Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-bswap-14.c
blob62711d8ef64d4964d901e5d8b780f93c7329008f
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 extern void abort (void);
7 __attribute__ ((noinline, noclone))
8 static int rt32 (int x, int y, int z) {
9 return (__builtin_bswap32(x) >> y) & z;
11 #define TEST32(X,Y,Z) if(((__builtin_bswap32(X)>>Y)&Z)!=rt32(X,Y,Z)) abort()
12 void test32(int x)
14 TEST32(x,0,1);
15 TEST32(x,0,255);
16 TEST32(x,1,1);
17 TEST32(x,2,1);
18 TEST32(x,3,1);
19 TEST32(x,4,1);
20 TEST32(x,5,1);
21 TEST32(x,6,1);
22 TEST32(x,7,1);
23 TEST32(x,8,1);
24 TEST32(x,8,255);
25 TEST32(x,9,1);
26 TEST32(x,10,1);
27 TEST32(x,11,1);
28 TEST32(x,12,1);
29 TEST32(x,13,1);
30 TEST32(x,14,1);
31 TEST32(x,15,1);
32 TEST32(x,16,1);
33 TEST32(x,16,255);
34 TEST32(x,17,1);
35 TEST32(x,18,1);
36 TEST32(x,19,1);
37 TEST32(x,20,1);
38 TEST32(x,21,1);
39 TEST32(x,22,1);
40 TEST32(x,23,1);
41 TEST32(x,24,1);
42 TEST32(x,24,255);
43 TEST32(x,25,1);
44 TEST32(x,26,1);
45 TEST32(x,27,1);
46 TEST32(x,28,1);
47 TEST32(x,29,1);
48 TEST32(x,30,1);
49 TEST32(x,31,1);
52 #if __SIZEOF_LONG_LONG__ == 8
53 __attribute__ ((noinline, noclone))
54 static long long rt64 (long long x, int y, long long z) {
55 return (__builtin_bswap64(x) >> y) & z;
57 #define TEST64(X,Y,Z) if(((__builtin_bswap64(X)>>Y)&Z)!=rt64(X,Y,Z)) abort()
58 void test64(long long x)
60 TEST64(x,0,1);
61 TEST64(x,0,255);
62 TEST64(x,1,1);
63 TEST64(x,2,1);
64 TEST64(x,3,1);
65 TEST64(x,4,1);
66 TEST64(x,5,1);
67 TEST64(x,6,1);
68 TEST64(x,7,1);
69 TEST64(x,8,1);
70 TEST64(x,8,255);
71 TEST64(x,9,1);
72 TEST64(x,10,1);
73 TEST64(x,11,1);
74 TEST64(x,12,1);
75 TEST64(x,13,1);
76 TEST64(x,14,1);
77 TEST64(x,15,1);
78 TEST64(x,16,1);
79 TEST64(x,16,255);
80 TEST64(x,17,1);
81 TEST64(x,18,1);
82 TEST64(x,19,1);
83 TEST64(x,20,1);
84 TEST64(x,21,1);
85 TEST64(x,22,1);
86 TEST64(x,23,1);
87 TEST64(x,24,1);
88 TEST64(x,24,255);
89 TEST64(x,25,1);
90 TEST64(x,26,1);
91 TEST64(x,27,1);
92 TEST64(x,28,1);
93 TEST64(x,29,1);
94 TEST64(x,30,1);
95 TEST64(x,31,1);
96 TEST64(x,32,1);
97 TEST64(x,32,255);
98 TEST64(x,33,1);
99 TEST64(x,34,1);
100 TEST64(x,35,1);
101 TEST64(x,36,1);
102 TEST64(x,37,1);
103 TEST64(x,38,1);
104 TEST64(x,39,1);
105 TEST64(x,40,1);
106 TEST64(x,40,255);
107 TEST64(x,41,1);
108 TEST64(x,42,1);
109 TEST64(x,43,1);
110 TEST64(x,44,1);
111 TEST64(x,45,1);
112 TEST64(x,46,1);
113 TEST64(x,47,1);
114 TEST64(x,48,1);
115 TEST64(x,48,255);
116 TEST64(x,49,1);
117 TEST64(x,50,1);
118 TEST64(x,51,1);
119 TEST64(x,52,1);
120 TEST64(x,53,1);
121 TEST64(x,54,1);
122 TEST64(x,55,1);
123 TEST64(x,56,1);
124 TEST64(x,56,255);
125 TEST64(x,57,1);
126 TEST64(x,58,1);
127 TEST64(x,59,1);
128 TEST64(x,60,1);
129 TEST64(x,61,1);
130 TEST64(x,62,1);
131 TEST64(x,63,1);
133 #endif
135 __attribute__ ((noinline, noclone))
136 static int rt16 (int x, int y, int z) {
137 return (__builtin_bswap16(x) >> y) & z;
139 #define TEST16(X,Y,Z) if(((__builtin_bswap16(X)>>Y)&Z)!=rt16(X,Y,Z)) abort()
140 void test16(int x)
142 TEST16(x,0,1);
143 TEST16(x,0,255);
144 TEST16(x,1,1);
145 TEST16(x,2,1);
146 TEST16(x,3,1);
147 TEST16(x,4,1);
148 TEST16(x,5,1);
149 TEST16(x,6,1);
150 TEST16(x,7,1);
151 TEST16(x,8,1);
152 TEST16(x,8,255);
153 TEST16(x,9,1);
154 TEST16(x,10,1);
155 TEST16(x,11,1);
156 TEST16(x,12,1);
157 TEST16(x,13,1);
158 TEST16(x,14,1);
159 TEST16(x,15,1);
162 int main()
164 test32(0x00000000);
165 test32(0xffffffff);
166 test32(0x00000001);
167 test32(0x00000002);
168 test32(0x00000004);
169 test32(0x00000008);
170 test32(0x00000010);
171 test32(0x00000020);
172 test32(0x00000040);
173 test32(0x00000080);
174 test32(0x00000100);
175 test32(0x00000200);
176 test32(0x00000400);
177 test32(0x00000800);
178 test32(0x00001000);
179 test32(0x00002000);
180 test32(0x00004000);
181 test32(0x00008000);
182 test32(0x00010000);
183 test32(0x00020000);
184 test32(0x00040000);
185 test32(0x00080000);
186 test32(0x00100000);
187 test32(0x00200000);
188 test32(0x00400000);
189 test32(0x00800000);
190 test32(0x01000000);
191 test32(0x02000000);
192 test32(0x04000000);
193 test32(0x08000000);
194 test32(0x10000000);
195 test32(0x20000000);
196 test32(0x40000000);
197 test32(0x80000000);
198 test32(0x12345678);
199 test32(0x87654321);
200 test32(0xdeadbeef);
201 test32(0xcafebabe);
203 #if __SIZEOF_LONG_LONG__ == 8
204 test64(0x0000000000000000ll);
205 test64(0xffffffffffffffffll);
206 test64(0x0000000000000001ll);
207 test64(0x0000000000000002ll);
208 test64(0x0000000000000004ll);
209 test64(0x0000000000000008ll);
210 test64(0x0000000000000010ll);
211 test64(0x0000000000000020ll);
212 test64(0x0000000000000040ll);
213 test64(0x0000000000000080ll);
214 test64(0x0000000000000100ll);
215 test64(0x0000000000000200ll);
216 test64(0x0000000000000400ll);
217 test64(0x0000000000000800ll);
218 test64(0x0000000000001000ll);
219 test64(0x0000000000002000ll);
220 test64(0x0000000000004000ll);
221 test64(0x0000000000008000ll);
222 test64(0x0000000000010000ll);
223 test64(0x0000000000020000ll);
224 test64(0x0000000000040000ll);
225 test64(0x0000000000080000ll);
226 test64(0x0000000000100000ll);
227 test64(0x0000000000200000ll);
228 test64(0x0000000000400000ll);
229 test64(0x0000000000800000ll);
230 test64(0x0000000001000000ll);
231 test64(0x0000000002000000ll);
232 test64(0x0000000004000000ll);
233 test64(0x0000000008000000ll);
234 test64(0x0000000010000000ll);
235 test64(0x0000000020000000ll);
236 test64(0x0000000040000000ll);
237 test64(0x0000000080000000ll);
238 test64(0x0000000100000000ll);
239 test64(0x0000000200000000ll);
240 test64(0x0000000400000000ll);
241 test64(0x0000000800000000ll);
242 test64(0x0000001000000000ll);
243 test64(0x0000002000000000ll);
244 test64(0x0000004000000000ll);
245 test64(0x0000008000000000ll);
246 test64(0x0000010000000000ll);
247 test64(0x0000020000000000ll);
248 test64(0x0000040000000000ll);
249 test64(0x0000080000000000ll);
250 test64(0x0000100000000000ll);
251 test64(0x0000200000000000ll);
252 test64(0x0000400000000000ll);
253 test64(0x0000800000000000ll);
254 test64(0x0001000000000000ll);
255 test64(0x0002000000000000ll);
256 test64(0x0004000000000000ll);
257 test64(0x0008000000000000ll);
258 test64(0x0010000000000000ll);
259 test64(0x0020000000000000ll);
260 test64(0x0040000000000000ll);
261 test64(0x0080000000000000ll);
262 test64(0x0100000000000000ll);
263 test64(0x0200000000000000ll);
264 test64(0x0400000000000000ll);
265 test64(0x0800000000000000ll);
266 test64(0x1000000000000000ll);
267 test64(0x2000000000000000ll);
268 test64(0x4000000000000000ll);
269 test64(0x8000000000000000ll);
270 test64(0x0123456789abcdefll);
271 test64(0xfedcba9876543210ll);
272 test64(0xdeadbeefdeadbeefll);
273 test64(0xcafebabecafebabell);
274 #endif
276 test16(0x0000);
277 test16(0xffff);
278 test16(0x0001);
279 test16(0x0002);
280 test16(0x0004);
281 test16(0x0008);
282 test16(0x0010);
283 test16(0x0020);
284 test16(0x0040);
285 test16(0x0080);
286 test16(0x0100);
287 test16(0x0200);
288 test16(0x0400);
289 test16(0x0800);
290 test16(0x1000);
291 test16(0x2000);
292 test16(0x4000);
293 test16(0x8000);
294 test16(0x1234);
295 test16(0x4321);
296 test16(0xdead);
297 test16(0xbeef);
298 test16(0xcafe);
299 test16(0xbabe);
301 return 0;