[GlobalISel] Avoid repeated hash lookups (NFC) (#124393)
[llvm-project.git] / compiler-rt / test / builtins / Unit / ctzsi2_test.c
blobdb6d4ce6a1621e010f5a86bd2163d007fc4bd774
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ctzsi2
4 #include "int_lib.h"
5 #include <stdio.h>
7 // Returns: the number of trailing 0-bits
9 // Precondition: a != 0
11 COMPILER_RT_ABI int __ctzsi2(si_int a);
13 int test__ctzsi2(si_int a, int expected)
15 int x = __ctzsi2(a);
16 if (x != expected)
17 printf("error in __ctzsi2(0x%X) = %d, expected %d\n", a, x, expected);
18 return x != expected;
21 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
22 char assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0};
24 int main()
26 // if (test__ctzsi2(0x00000000, 32)) // undefined
27 // return 1;
28 if (test__ctzsi2(0x00000001, 0))
29 return 1;
30 if (test__ctzsi2(0x00000002, 1))
31 return 1;
32 if (test__ctzsi2(0x00000003, 0))
33 return 1;
34 if (test__ctzsi2(0x00000004, 2))
35 return 1;
36 if (test__ctzsi2(0x00000005, 0))
37 return 1;
38 if (test__ctzsi2(0x00000006, 1))
39 return 1;
40 if (test__ctzsi2(0x00000007, 0))
41 return 1;
42 if (test__ctzsi2(0x00000008, 3))
43 return 1;
44 if (test__ctzsi2(0x00000009, 0))
45 return 1;
46 if (test__ctzsi2(0x0000000A, 1))
47 return 1;
48 if (test__ctzsi2(0x0000000B, 0))
49 return 1;
50 if (test__ctzsi2(0x0000000C, 2))
51 return 1;
52 if (test__ctzsi2(0x0000000D, 0))
53 return 1;
54 if (test__ctzsi2(0x0000000E, 1))
55 return 1;
56 if (test__ctzsi2(0x0000000F, 0))
57 return 1;
58 if (test__ctzsi2(0x00000010, 4))
59 return 1;
60 if (test__ctzsi2(0x00000012, 1))
61 return 1;
62 if (test__ctzsi2(0x00000013, 0))
63 return 1;
64 if (test__ctzsi2(0x00000014, 2))
65 return 1;
66 if (test__ctzsi2(0x00000015, 0))
67 return 1;
68 if (test__ctzsi2(0x00000016, 1))
69 return 1;
70 if (test__ctzsi2(0x00000017, 0))
71 return 1;
72 if (test__ctzsi2(0x00000018, 3))
73 return 1;
74 if (test__ctzsi2(0x00000019, 0))
75 return 1;
76 if (test__ctzsi2(0x0000001A, 1))
77 return 1;
78 if (test__ctzsi2(0x0000001B, 0))
79 return 1;
80 if (test__ctzsi2(0x0000001C, 2))
81 return 1;
82 if (test__ctzsi2(0x0000001D, 0))
83 return 1;
84 if (test__ctzsi2(0x0000001E, 1))
85 return 1;
86 if (test__ctzsi2(0x0000001F, 0))
87 return 1;
88 if (test__ctzsi2(0x00000020, 5))
89 return 1;
90 if (test__ctzsi2(0x00000022, 1))
91 return 1;
92 if (test__ctzsi2(0x00000023, 0))
93 return 1;
94 if (test__ctzsi2(0x00000024, 2))
95 return 1;
96 if (test__ctzsi2(0x00000025, 0))
97 return 1;
98 if (test__ctzsi2(0x00000026, 1))
99 return 1;
100 if (test__ctzsi2(0x00000027, 0))
101 return 1;
102 if (test__ctzsi2(0x00000028, 3))
103 return 1;
104 if (test__ctzsi2(0x00000029, 0))
105 return 1;
106 if (test__ctzsi2(0x0000002A, 1))
107 return 1;
108 if (test__ctzsi2(0x0000002B, 0))
109 return 1;
110 if (test__ctzsi2(0x0000002C, 2))
111 return 1;
112 if (test__ctzsi2(0x0000002D, 0))
113 return 1;
114 if (test__ctzsi2(0x0000002E, 1))
115 return 1;
116 if (test__ctzsi2(0x0000002F, 0))
117 return 1;
118 if (test__ctzsi2(0x00000030, 4))
119 return 1;
120 if (test__ctzsi2(0x00000032, 1))
121 return 1;
122 if (test__ctzsi2(0x00000033, 0))
123 return 1;
124 if (test__ctzsi2(0x00000034, 2))
125 return 1;
126 if (test__ctzsi2(0x00000035, 0))
127 return 1;
128 if (test__ctzsi2(0x00000036, 1))
129 return 1;
130 if (test__ctzsi2(0x00000037, 0))
131 return 1;
132 if (test__ctzsi2(0x00000038, 3))
133 return 1;
134 if (test__ctzsi2(0x00000039, 0))
135 return 1;
136 if (test__ctzsi2(0x0000003A, 1))
137 return 1;
138 if (test__ctzsi2(0x0000003B, 0))
139 return 1;
140 if (test__ctzsi2(0x0000003C, 2))
141 return 1;
142 if (test__ctzsi2(0x0000003D, 0))
143 return 1;
144 if (test__ctzsi2(0x0000003E, 1))
145 return 1;
146 if (test__ctzsi2(0x0000003F, 0))
147 return 1;
148 if (test__ctzsi2(0x00000040, 6))
149 return 1;
150 if (test__ctzsi2(0x00000042, 1))
151 return 1;
152 if (test__ctzsi2(0x00000043, 0))
153 return 1;
154 if (test__ctzsi2(0x00000044, 2))
155 return 1;
156 if (test__ctzsi2(0x00000045, 0))
157 return 1;
158 if (test__ctzsi2(0x00000046, 1))
159 return 1;
160 if (test__ctzsi2(0x00000047, 0))
161 return 1;
162 if (test__ctzsi2(0x00000048, 3))
163 return 1;
164 if (test__ctzsi2(0x00000049, 0))
165 return 1;
166 if (test__ctzsi2(0x0000004A, 1))
167 return 1;
168 if (test__ctzsi2(0x0000004B, 0))
169 return 1;
170 if (test__ctzsi2(0x0000004C, 2))
171 return 1;
172 if (test__ctzsi2(0x0000004D, 0))
173 return 1;
174 if (test__ctzsi2(0x0000004E, 1))
175 return 1;
176 if (test__ctzsi2(0x0000004F, 0))
177 return 1;
178 if (test__ctzsi2(0x00000050, 4))
179 return 1;
180 if (test__ctzsi2(0x00000052, 1))
181 return 1;
182 if (test__ctzsi2(0x00000053, 0))
183 return 1;
184 if (test__ctzsi2(0x00000054, 2))
185 return 1;
186 if (test__ctzsi2(0x00000055, 0))
187 return 1;
188 if (test__ctzsi2(0x00000056, 1))
189 return 1;
190 if (test__ctzsi2(0x00000057, 0))
191 return 1;
192 if (test__ctzsi2(0x00000058, 3))
193 return 1;
194 if (test__ctzsi2(0x00000059, 0))
195 return 1;
196 if (test__ctzsi2(0x0000005A, 1))
197 return 1;
198 if (test__ctzsi2(0x0000005B, 0))
199 return 1;
200 if (test__ctzsi2(0x0000005C, 2))
201 return 1;
202 if (test__ctzsi2(0x0000005D, 0))
203 return 1;
204 if (test__ctzsi2(0x0000005E, 1))
205 return 1;
206 if (test__ctzsi2(0x0000005F, 0))
207 return 1;
208 if (test__ctzsi2(0x00000060, 5))
209 return 1;
210 if (test__ctzsi2(0x00000062, 1))
211 return 1;
212 if (test__ctzsi2(0x00000063, 0))
213 return 1;
214 if (test__ctzsi2(0x00000064, 2))
215 return 1;
216 if (test__ctzsi2(0x00000065, 0))
217 return 1;
218 if (test__ctzsi2(0x00000066, 1))
219 return 1;
220 if (test__ctzsi2(0x00000067, 0))
221 return 1;
222 if (test__ctzsi2(0x00000068, 3))
223 return 1;
224 if (test__ctzsi2(0x00000069, 0))
225 return 1;
226 if (test__ctzsi2(0x0000006A, 1))
227 return 1;
228 if (test__ctzsi2(0x0000006B, 0))
229 return 1;
230 if (test__ctzsi2(0x0000006C, 2))
231 return 1;
232 if (test__ctzsi2(0x0000006D, 0))
233 return 1;
234 if (test__ctzsi2(0x0000006E, 1))
235 return 1;
236 if (test__ctzsi2(0x0000006F, 0))
237 return 1;
238 if (test__ctzsi2(0x00000070, 4))
239 return 1;
240 if (test__ctzsi2(0x00000072, 1))
241 return 1;
242 if (test__ctzsi2(0x00000073, 0))
243 return 1;
244 if (test__ctzsi2(0x00000074, 2))
245 return 1;
246 if (test__ctzsi2(0x00000075, 0))
247 return 1;
248 if (test__ctzsi2(0x00000076, 1))
249 return 1;
250 if (test__ctzsi2(0x00000077, 0))
251 return 1;
252 if (test__ctzsi2(0x00000078, 3))
253 return 1;
254 if (test__ctzsi2(0x00000079, 0))
255 return 1;
256 if (test__ctzsi2(0x0000007A, 1))
257 return 1;
258 if (test__ctzsi2(0x0000007B, 0))
259 return 1;
260 if (test__ctzsi2(0x0000007C, 2))
261 return 1;
262 if (test__ctzsi2(0x0000007D, 0))
263 return 1;
264 if (test__ctzsi2(0x0000007E, 1))
265 return 1;
266 if (test__ctzsi2(0x0000007F, 0))
267 return 1;
268 if (test__ctzsi2(0x00000080, 7))
269 return 1;
270 if (test__ctzsi2(0x00000082, 1))
271 return 1;
272 if (test__ctzsi2(0x00000083, 0))
273 return 1;
274 if (test__ctzsi2(0x00000084, 2))
275 return 1;
276 if (test__ctzsi2(0x00000085, 0))
277 return 1;
278 if (test__ctzsi2(0x00000086, 1))
279 return 1;
280 if (test__ctzsi2(0x00000087, 0))
281 return 1;
282 if (test__ctzsi2(0x00000088, 3))
283 return 1;
284 if (test__ctzsi2(0x00000089, 0))
285 return 1;
286 if (test__ctzsi2(0x0000008A, 1))
287 return 1;
288 if (test__ctzsi2(0x0000008B, 0))
289 return 1;
290 if (test__ctzsi2(0x0000008C, 2))
291 return 1;
292 if (test__ctzsi2(0x0000008D, 0))
293 return 1;
294 if (test__ctzsi2(0x0000008E, 1))
295 return 1;
296 if (test__ctzsi2(0x0000008F, 0))
297 return 1;
298 if (test__ctzsi2(0x00000090, 4))
299 return 1;
300 if (test__ctzsi2(0x00000092, 1))
301 return 1;
302 if (test__ctzsi2(0x00000093, 0))
303 return 1;
304 if (test__ctzsi2(0x00000094, 2))
305 return 1;
306 if (test__ctzsi2(0x00000095, 0))
307 return 1;
308 if (test__ctzsi2(0x00000096, 1))
309 return 1;
310 if (test__ctzsi2(0x00000097, 0))
311 return 1;
312 if (test__ctzsi2(0x00000098, 3))
313 return 1;
314 if (test__ctzsi2(0x00000099, 0))
315 return 1;
316 if (test__ctzsi2(0x0000009A, 1))
317 return 1;
318 if (test__ctzsi2(0x0000009B, 0))
319 return 1;
320 if (test__ctzsi2(0x0000009C, 2))
321 return 1;
322 if (test__ctzsi2(0x0000009D, 0))
323 return 1;
324 if (test__ctzsi2(0x0000009E, 1))
325 return 1;
326 if (test__ctzsi2(0x0000009F, 0))
327 return 1;
328 if (test__ctzsi2(0x000000A0, 5))
329 return 1;
330 if (test__ctzsi2(0x000000A2, 1))
331 return 1;
332 if (test__ctzsi2(0x000000A3, 0))
333 return 1;
334 if (test__ctzsi2(0x000000A4, 2))
335 return 1;
336 if (test__ctzsi2(0x000000A5, 0))
337 return 1;
338 if (test__ctzsi2(0x000000A6, 1))
339 return 1;
340 if (test__ctzsi2(0x000000A7, 0))
341 return 1;
342 if (test__ctzsi2(0x000000A8, 3))
343 return 1;
344 if (test__ctzsi2(0x000000A9, 0))
345 return 1;
346 if (test__ctzsi2(0x000000AA, 1))
347 return 1;
348 if (test__ctzsi2(0x000000AB, 0))
349 return 1;
350 if (test__ctzsi2(0x000000AC, 2))
351 return 1;
352 if (test__ctzsi2(0x000000AD, 0))
353 return 1;
354 if (test__ctzsi2(0x000000AE, 1))
355 return 1;
356 if (test__ctzsi2(0x000000AF, 0))
357 return 1;
358 if (test__ctzsi2(0x000000B0, 4))
359 return 1;
360 if (test__ctzsi2(0x000000B2, 1))
361 return 1;
362 if (test__ctzsi2(0x000000B3, 0))
363 return 1;
364 if (test__ctzsi2(0x000000B4, 2))
365 return 1;
366 if (test__ctzsi2(0x000000B5, 0))
367 return 1;
368 if (test__ctzsi2(0x000000B6, 1))
369 return 1;
370 if (test__ctzsi2(0x000000B7, 0))
371 return 1;
372 if (test__ctzsi2(0x000000B8, 3))
373 return 1;
374 if (test__ctzsi2(0x000000B9, 0))
375 return 1;
376 if (test__ctzsi2(0x000000BA, 1))
377 return 1;
378 if (test__ctzsi2(0x000000BB, 0))
379 return 1;
380 if (test__ctzsi2(0x000000BC, 2))
381 return 1;
382 if (test__ctzsi2(0x000000BD, 0))
383 return 1;
384 if (test__ctzsi2(0x000000BE, 1))
385 return 1;
386 if (test__ctzsi2(0x000000BF, 0))
387 return 1;
388 if (test__ctzsi2(0x000000C0, 6))
389 return 1;
390 if (test__ctzsi2(0x000000C2, 1))
391 return 1;
392 if (test__ctzsi2(0x000000C3, 0))
393 return 1;
394 if (test__ctzsi2(0x000000C4, 2))
395 return 1;
396 if (test__ctzsi2(0x000000C5, 0))
397 return 1;
398 if (test__ctzsi2(0x000000C6, 1))
399 return 1;
400 if (test__ctzsi2(0x000000C7, 0))
401 return 1;
402 if (test__ctzsi2(0x000000C8, 3))
403 return 1;
404 if (test__ctzsi2(0x000000C9, 0))
405 return 1;
406 if (test__ctzsi2(0x000000CA, 1))
407 return 1;
408 if (test__ctzsi2(0x000000CB, 0))
409 return 1;
410 if (test__ctzsi2(0x000000CC, 2))
411 return 1;
412 if (test__ctzsi2(0x000000CD, 0))
413 return 1;
414 if (test__ctzsi2(0x000000CE, 1))
415 return 1;
416 if (test__ctzsi2(0x000000CF, 0))
417 return 1;
418 if (test__ctzsi2(0x000000D0, 4))
419 return 1;
420 if (test__ctzsi2(0x000000D2, 1))
421 return 1;
422 if (test__ctzsi2(0x000000D3, 0))
423 return 1;
424 if (test__ctzsi2(0x000000D4, 2))
425 return 1;
426 if (test__ctzsi2(0x000000D5, 0))
427 return 1;
428 if (test__ctzsi2(0x000000D6, 1))
429 return 1;
430 if (test__ctzsi2(0x000000D7, 0))
431 return 1;
432 if (test__ctzsi2(0x000000D8, 3))
433 return 1;
434 if (test__ctzsi2(0x000000D9, 0))
435 return 1;
436 if (test__ctzsi2(0x000000DA, 1))
437 return 1;
438 if (test__ctzsi2(0x000000DB, 0))
439 return 1;
440 if (test__ctzsi2(0x000000DC, 2))
441 return 1;
442 if (test__ctzsi2(0x000000DD, 0))
443 return 1;
444 if (test__ctzsi2(0x000000DE, 1))
445 return 1;
446 if (test__ctzsi2(0x000000DF, 0))
447 return 1;
448 if (test__ctzsi2(0x000000E0, 5))
449 return 1;
450 if (test__ctzsi2(0x000000E2, 1))
451 return 1;
452 if (test__ctzsi2(0x000000E3, 0))
453 return 1;
454 if (test__ctzsi2(0x000000E4, 2))
455 return 1;
456 if (test__ctzsi2(0x000000E5, 0))
457 return 1;
458 if (test__ctzsi2(0x000000E6, 1))
459 return 1;
460 if (test__ctzsi2(0x000000E7, 0))
461 return 1;
462 if (test__ctzsi2(0x000000E8, 3))
463 return 1;
464 if (test__ctzsi2(0x000000E9, 0))
465 return 1;
466 if (test__ctzsi2(0x000000EA, 1))
467 return 1;
468 if (test__ctzsi2(0x000000EB, 0))
469 return 1;
470 if (test__ctzsi2(0x000000EC, 2))
471 return 1;
472 if (test__ctzsi2(0x000000ED, 0))
473 return 1;
474 if (test__ctzsi2(0x000000EE, 1))
475 return 1;
476 if (test__ctzsi2(0x000000EF, 0))
477 return 1;
478 if (test__ctzsi2(0x000000F0, 4))
479 return 1;
480 if (test__ctzsi2(0x000000F2, 1))
481 return 1;
482 if (test__ctzsi2(0x000000F3, 0))
483 return 1;
484 if (test__ctzsi2(0x000000F4, 2))
485 return 1;
486 if (test__ctzsi2(0x000000F5, 0))
487 return 1;
488 if (test__ctzsi2(0x000000F6, 1))
489 return 1;
490 if (test__ctzsi2(0x000000F7, 0))
491 return 1;
492 if (test__ctzsi2(0x000000F8, 3))
493 return 1;
494 if (test__ctzsi2(0x000000F9, 0))
495 return 1;
496 if (test__ctzsi2(0x000000FA, 1))
497 return 1;
498 if (test__ctzsi2(0x000000FB, 0))
499 return 1;
500 if (test__ctzsi2(0x000000FC, 2))
501 return 1;
502 if (test__ctzsi2(0x000000FD, 0))
503 return 1;
504 if (test__ctzsi2(0x000000FE, 1))
505 return 1;
506 if (test__ctzsi2(0x000000FF, 0))
507 return 1;
509 if (test__ctzsi2(0x00000100, 8))
510 return 1;
511 if (test__ctzsi2(0x00000200, 9))
512 return 1;
513 if (test__ctzsi2(0x00000400, 10))
514 return 1;
515 if (test__ctzsi2(0x00000800, 11))
516 return 1;
517 if (test__ctzsi2(0x00001000, 12))
518 return 1;
519 if (test__ctzsi2(0x00002000, 13))
520 return 1;
521 if (test__ctzsi2(0x00004000, 14))
522 return 1;
523 if (test__ctzsi2(0x00008000, 15))
524 return 1;
525 if (test__ctzsi2(0x00010000, 16))
526 return 1;
527 if (test__ctzsi2(0x00020000, 17))
528 return 1;
529 if (test__ctzsi2(0x00040000, 18))
530 return 1;
531 if (test__ctzsi2(0x00080000, 19))
532 return 1;
533 if (test__ctzsi2(0x00100000, 20))
534 return 1;
535 if (test__ctzsi2(0x00200000, 21))
536 return 1;
537 if (test__ctzsi2(0x00400000, 22))
538 return 1;
539 if (test__ctzsi2(0x00800000, 23))
540 return 1;
541 if (test__ctzsi2(0x01000000, 24))
542 return 1;
543 if (test__ctzsi2(0x02000000, 25))
544 return 1;
545 if (test__ctzsi2(0x04000000, 26))
546 return 1;
547 if (test__ctzsi2(0x08000000, 27))
548 return 1;
549 if (test__ctzsi2(0x10000000, 28))
550 return 1;
551 if (test__ctzsi2(0x20000000, 29))
552 return 1;
553 if (test__ctzsi2(0x40000000, 30))
554 return 1;
555 if (test__ctzsi2(0x80000000, 31))
556 return 1;
558 return 0;