swar-swarctrl.c
1.46 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
/* -----------------------------------------------------------------------------
* 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-swarctrl.c
* Authors : Roman Bartosinski
* Description : simple test of clang/LLVM compiler with SWAR extension
* Release :
* Version :
* Date :
* -----------------------------------------------------------------------------
*/
//A: --has-swar
//C: -daiteq-swar-enable
typedef unsigned int su4x8b __attribute__((subword(8)));
#define LEN 3
su4x8b a, b, z;
void test_swarctrl(unsigned short arg)
{
const unsigned short cw = 0x2800;
unsigned short vw;
z = a + b;
#pragma swar manual
asm("nop");
__builtin_swarctrl(cw | 0x20);
asm("nop");
__builtin_swarctrl(0x2400);
asm("nop");
__builtin_swarctrl(cw);
asm("nop");
__builtin_swarctrl(cw | 0x20);
asm("nop");
for (int i=0;i<3;++i) {
z = a + b;
}
__builtin_swarctrl(cw | 0x10);
// z = swar(a,b);
vw = arg;
__builtin_swarctrl(vw);
// z = swar(a,b); /* in LLVM correct bitcode for this version */
*((unsigned *)&z) = swar(*((unsigned *)&a), *((unsigned *)&b));
}
int main(void)
{
volatile unsigned short c = 0x2200;
test_swarctrl(c);
return 0;
}