1
2 /* { dg-options "-w -O3 -funroll-loops" } */
3 /* { dg-final { scan-assembler-not "%d0:%d0" } } */
4 /* { dg-final { scan-assembler-not "%d1:%d1" } } */
5 /* { dg-final { scan-assembler-not "%d2:%d2" } } */
6 /* { dg-final { scan-assembler-not "%d3:%d3" } } */
7 /* { dg-final { scan-assembler-not "%d4:%d4" } } */
8 /* { dg-final { scan-assembler-not "%d5:%d5" } } */
9 /* { dg-final { scan-assembler-not "%d6:%d6" } } */
10 /* { dg-final { scan-assembler-not "%d7:%d7" } } */
11 /* Test arithmetics on bitfields. */
12
13 extern void abort (void);
14 extern void exit (int);
15
16 unsigned int
myrnd(void)17 myrnd (void)
18 {
19 static unsigned int s = 1388815473;
20 s *= 1103515245;
21 s += 12345;
22 return (s / 65536) % 2048;
23 }
24
25 #define T(S) \
26 struct S s##S; \
27 struct S retme##S (struct S x) \
28 { \
29 return x; \
30 } \
31 \
32 unsigned int fn1##S (unsigned int x) \
33 { \
34 struct S y = s##S; \
35 y.k += x; \
36 y = retme##S (y); \
37 return y.k; \
38 } \
39 \
40 unsigned int fn2##S (unsigned int x) \
41 { \
42 struct S y = s##S; \
43 y.k += x; \
44 y.k %= 15; \
45 return y.k; \
46 } \
47 \
48 unsigned int retit##S (void) \
49 { \
50 return s##S.k; \
51 } \
52 \
53 unsigned int fn3##S (unsigned int x) \
54 { \
55 s##S.k += x; \
56 return retit##S (); \
57 } \
58 \
59 void test##S (void) \
60 { \
61 int i; \
62 unsigned int mask, v, a, r; \
63 struct S x; \
64 char *p = (char *) &s##S; \
65 for (i = 0; i < sizeof (s##S); ++i) \
66 *p++ = myrnd (); \
67 if (__builtin_classify_type (s##S.l) == 8) \
68 s##S.l = 5.25; \
69 s##S.k = -1; \
70 mask = s##S.k; \
71 v = myrnd (); \
72 a = myrnd (); \
73 s##S.k = v; \
74 x = s##S; \
75 r = fn1##S (a); \
76 if (x.i != s##S.i || x.j != s##S.j \
77 || x.k != s##S.k || x.l != s##S.l \
78 || ((v + a) & mask) != r) \
79 abort (); \
80 v = myrnd (); \
81 a = myrnd (); \
82 s##S.k = v; \
83 x = s##S; \
84 r = fn2##S (a); \
85 if (x.i != s##S.i || x.j != s##S.j \
86 || x.k != s##S.k || x.l != s##S.l \
87 || ((((v + a) & mask) % 15) & mask) != r) \
88 abort (); \
89 v = myrnd (); \
90 a = myrnd (); \
91 s##S.k = v; \
92 x = s##S; \
93 r = fn3##S (a); \
94 if (x.i != s##S.i || x.j != s##S.j \
95 || s##S.k != r || x.l != s##S.l \
96 || ((v + a) & mask) != r) \
97 abort (); \
98 }
99
100 struct A { unsigned int i : 6, l : 1, j : 10, k : 15; }; T(A)
101 struct B { unsigned int i : 6, j : 11, k : 15; unsigned int l; }; T(B)
102 struct C { unsigned int l; unsigned int i : 6, j : 11, k : 15; }; T(C)
103 struct D { unsigned long long l : 6, i : 6, j : 23, k : 29; }; T(D)
104 struct E { unsigned long long l, i : 12, j : 23, k : 29; }; T(E)
105 struct F { unsigned long long i : 12, j : 23, k : 29, l; }; T(F)
106 struct G { unsigned int i : 12, j : 13, k : 7; unsigned long long l; }; T(G)
107 struct H { unsigned int i : 12, j : 11, k : 9; unsigned long long l; }; T(H)
108 struct I { unsigned short i : 1, j : 6, k : 9; unsigned long long l; }; T(I)
109 struct J { unsigned short i : 1, j : 8, k : 7; unsigned short l; }; T(J)
110 struct K { unsigned int k : 6, l : 1, j : 10, i : 15; }; T(K)
111 struct L { unsigned int k : 6, j : 11, i : 15; unsigned int l; }; T(L)
112 struct M { unsigned int l; unsigned int k : 6, j : 11, i : 15; }; T(M)
113 struct N { unsigned long long l : 6, k : 6, j : 23, i : 29; }; T(N)
114 struct O { unsigned long long l, k : 12, j : 23, i : 29; }; T(O)
115 struct P { unsigned long long k : 12, j : 23, i : 29, l; }; T(P)
116 struct Q { unsigned int k : 12, j : 13, i : 7; unsigned long long l; }; T(Q)
117 struct R { unsigned int k : 12, j : 11, i : 9; unsigned long long l; }; T(R)
118 struct S { unsigned short k : 1, j : 6, i : 9; unsigned long long l; }; T(S)
119 struct T { unsigned short k : 1, j : 8, i : 7; unsigned short l; }; T(T)
120 struct U { unsigned short j : 6, k : 1, i : 9; unsigned long long l; }; T(U)
121 struct V { unsigned short j : 8, k : 1, i : 7; unsigned short l; }; T(V)
122 struct W { long double l; unsigned int k : 12, j : 13, i : 7; }; T(W)
123 struct X { unsigned int k : 12, j : 13, i : 7; long double l; }; T(X)
124 struct Y { unsigned int k : 12, j : 11, i : 9; long double l; }; T(Y)
T(Z)125 struct Z { long double l; unsigned int j : 13, i : 7, k : 12; }; T(Z)
126
127 int
128 main (void)
129 {
130 testA ();
131 testB ();
132 testC ();
133 testD ();
134 testE ();
135 testF ();
136 testG ();
137 testH ();
138 testI ();
139 testJ ();
140 testK ();
141 testL ();
142 testM ();
143 testN ();
144 testO ();
145 testP ();
146 testQ ();
147 testR ();
148 testS ();
149 testT ();
150 testU ();
151 testV ();
152 testW ();
153 testX ();
154 testY ();
155 testZ ();
156 exit (0);
157 }
158