1 /* { dg-do run { target aarch64*-*-* } } */
2 /* { dg-options "-O2 --save-temps -fno-inline" } */
3 /* { dg-require-effective-target aarch64_little_endian } */
4
5 extern void abort (void);
6
7 typedef struct bitfield
8 {
9 unsigned short eight: 8;
10 unsigned short four: 4;
11 unsigned short five: 5;
12 unsigned short seven: 7;
13 unsigned int sixteen: 16;
14 } bitfield;
15
16 bitfield
bfi1(bitfield a)17 bfi1 (bitfield a)
18 {
19 /* { dg-final { scan-assembler "bfi\tx\[0-9\]+, x\[0-9\]+, 0, 8" } } */
20 a.eight = 3;
21 return a;
22 }
23
24 bitfield
bfi2(bitfield a)25 bfi2 (bitfield a)
26 {
27 /* { dg-final { scan-assembler "bfi\tx\[0-9\]+, x\[0-9\]+, 16, 5" } } */
28 a.five = 7;
29 return a;
30 }
31
32 bitfield
movk(bitfield a)33 movk (bitfield a)
34 {
35 /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0x1d6b, lsl 32" } } */
36 a.sixteen = 7531;
37 return a;
38 }
39
40 bitfield
set1(bitfield a)41 set1 (bitfield a)
42 {
43 /* { dg-final { scan-assembler "orr\tx\[0-9\]+, x\[0-9\]+, 2031616" } } */
44 a.five = 0x1f;
45 return a;
46 }
47
48 bitfield
set0(bitfield a)49 set0 (bitfield a)
50 {
51 /* { dg-final { scan-assembler "and\tx\[0-9\]+, x\[0-9\]+, -2031617" } } */
52 a.five = 0;
53 return a;
54 }
55
56
57 int
main(int argc,char ** argv)58 main (int argc, char** argv)
59 {
60 static bitfield a;
61 bitfield b = bfi1 (a);
62 bitfield c = bfi2 (b);
63 bitfield d = movk (c);
64
65 if (d.eight != 3)
66 abort ();
67
68 if (d.five != 7)
69 abort ();
70
71 if (d.sixteen != 7531)
72 abort ();
73
74 d = set1 (d);
75 if (d.five != 0x1f)
76 abort ();
77
78 d = set0 (d);
79 if (d.five != 0)
80 abort ();
81
82 return 0;
83 }
84
85