swar-4x8b-pragma3.c
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -----------------------------------------------------------------------------
* Copyright (C) 2018-2020 daiteq s.r.o. http://www.daiteq.com
*
* This program is distributed WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* -----------------------------------------------------------------------------
* Filename : swar-4x8b-pragma3.c
* Authors : Roman Bartosinski
* Description : simple test of clang/LLVM compiler with SWAR extension
* Release :
* Version :
* Date :
* -----------------------------------------------------------------------------
*/
////A: --has-swar
//C: -daiteq-swar-enable
//#include <stdio.h>
typedef unsigned int su4x8b __attribute__((subword(8)));
#define LEN 3
const su4x8b a[LEN] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
su4x8b b[LEN] = {{10,20,30,40},{50,60,70,80},{90,100,110,120}};
su4x8b z[LEN] = {{0},{1},{10}};
void do_4x8b_add(void)
{
#pragma swar normalize
z[0] = a[0] + b[0];
z[1] = a[1] + b[1];
z[2] = a[2] + b[2];
{
#pragma swar saturate
z[0] = a[2] + b[1];
//#pragma swar manual
z[1] = a[0] + b[2];
z[2] = a[1] + b[0];
}
{
z[0] = a[1] + b[2];
z[1] = a[2] + b[0];
#pragma swar reduce
z[2] = a[0] + b[1];
}
#pragma swar saturate
{
z[0] = a[1] + b[2];
z[1] = a[2] + b[0];
z[2] = a[0] + b[1];
}
}
int main(void)
{
volatile unsigned long acc;
//__builtin_swarctrl(0);
z[0] = a[0] * b[0];
acc = __builtin_swaraccum(0);
acc = __builtin_swaraccum(1);
acc = __builtin_swaraccum(2);
acc = __builtin_swaraccum(3);
do_4x8b_add();
acc = __builtin_swaraccum(0);
acc = __builtin_swaraccum(1);
acc = __builtin_swaraccum(2);
acc = __builtin_swaraccum(3);
return 0;
}