1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ctzsi2
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
)
17 printf("error in __ctzsi2(0x%X) = %d, expected %d\n", a
, 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};
26 // if (test__ctzsi2(0x00000000, 32)) // undefined
28 if (test__ctzsi2(0x00000001, 0))
30 if (test__ctzsi2(0x00000002, 1))
32 if (test__ctzsi2(0x00000003, 0))
34 if (test__ctzsi2(0x00000004, 2))
36 if (test__ctzsi2(0x00000005, 0))
38 if (test__ctzsi2(0x00000006, 1))
40 if (test__ctzsi2(0x00000007, 0))
42 if (test__ctzsi2(0x00000008, 3))
44 if (test__ctzsi2(0x00000009, 0))
46 if (test__ctzsi2(0x0000000A, 1))
48 if (test__ctzsi2(0x0000000B, 0))
50 if (test__ctzsi2(0x0000000C, 2))
52 if (test__ctzsi2(0x0000000D, 0))
54 if (test__ctzsi2(0x0000000E, 1))
56 if (test__ctzsi2(0x0000000F, 0))
58 if (test__ctzsi2(0x00000010, 4))
60 if (test__ctzsi2(0x00000012, 1))
62 if (test__ctzsi2(0x00000013, 0))
64 if (test__ctzsi2(0x00000014, 2))
66 if (test__ctzsi2(0x00000015, 0))
68 if (test__ctzsi2(0x00000016, 1))
70 if (test__ctzsi2(0x00000017, 0))
72 if (test__ctzsi2(0x00000018, 3))
74 if (test__ctzsi2(0x00000019, 0))
76 if (test__ctzsi2(0x0000001A, 1))
78 if (test__ctzsi2(0x0000001B, 0))
80 if (test__ctzsi2(0x0000001C, 2))
82 if (test__ctzsi2(0x0000001D, 0))
84 if (test__ctzsi2(0x0000001E, 1))
86 if (test__ctzsi2(0x0000001F, 0))
88 if (test__ctzsi2(0x00000020, 5))
90 if (test__ctzsi2(0x00000022, 1))
92 if (test__ctzsi2(0x00000023, 0))
94 if (test__ctzsi2(0x00000024, 2))
96 if (test__ctzsi2(0x00000025, 0))
98 if (test__ctzsi2(0x00000026, 1))
100 if (test__ctzsi2(0x00000027, 0))
102 if (test__ctzsi2(0x00000028, 3))
104 if (test__ctzsi2(0x00000029, 0))
106 if (test__ctzsi2(0x0000002A, 1))
108 if (test__ctzsi2(0x0000002B, 0))
110 if (test__ctzsi2(0x0000002C, 2))
112 if (test__ctzsi2(0x0000002D, 0))
114 if (test__ctzsi2(0x0000002E, 1))
116 if (test__ctzsi2(0x0000002F, 0))
118 if (test__ctzsi2(0x00000030, 4))
120 if (test__ctzsi2(0x00000032, 1))
122 if (test__ctzsi2(0x00000033, 0))
124 if (test__ctzsi2(0x00000034, 2))
126 if (test__ctzsi2(0x00000035, 0))
128 if (test__ctzsi2(0x00000036, 1))
130 if (test__ctzsi2(0x00000037, 0))
132 if (test__ctzsi2(0x00000038, 3))
134 if (test__ctzsi2(0x00000039, 0))
136 if (test__ctzsi2(0x0000003A, 1))
138 if (test__ctzsi2(0x0000003B, 0))
140 if (test__ctzsi2(0x0000003C, 2))
142 if (test__ctzsi2(0x0000003D, 0))
144 if (test__ctzsi2(0x0000003E, 1))
146 if (test__ctzsi2(0x0000003F, 0))
148 if (test__ctzsi2(0x00000040, 6))
150 if (test__ctzsi2(0x00000042, 1))
152 if (test__ctzsi2(0x00000043, 0))
154 if (test__ctzsi2(0x00000044, 2))
156 if (test__ctzsi2(0x00000045, 0))
158 if (test__ctzsi2(0x00000046, 1))
160 if (test__ctzsi2(0x00000047, 0))
162 if (test__ctzsi2(0x00000048, 3))
164 if (test__ctzsi2(0x00000049, 0))
166 if (test__ctzsi2(0x0000004A, 1))
168 if (test__ctzsi2(0x0000004B, 0))
170 if (test__ctzsi2(0x0000004C, 2))
172 if (test__ctzsi2(0x0000004D, 0))
174 if (test__ctzsi2(0x0000004E, 1))
176 if (test__ctzsi2(0x0000004F, 0))
178 if (test__ctzsi2(0x00000050, 4))
180 if (test__ctzsi2(0x00000052, 1))
182 if (test__ctzsi2(0x00000053, 0))
184 if (test__ctzsi2(0x00000054, 2))
186 if (test__ctzsi2(0x00000055, 0))
188 if (test__ctzsi2(0x00000056, 1))
190 if (test__ctzsi2(0x00000057, 0))
192 if (test__ctzsi2(0x00000058, 3))
194 if (test__ctzsi2(0x00000059, 0))
196 if (test__ctzsi2(0x0000005A, 1))
198 if (test__ctzsi2(0x0000005B, 0))
200 if (test__ctzsi2(0x0000005C, 2))
202 if (test__ctzsi2(0x0000005D, 0))
204 if (test__ctzsi2(0x0000005E, 1))
206 if (test__ctzsi2(0x0000005F, 0))
208 if (test__ctzsi2(0x00000060, 5))
210 if (test__ctzsi2(0x00000062, 1))
212 if (test__ctzsi2(0x00000063, 0))
214 if (test__ctzsi2(0x00000064, 2))
216 if (test__ctzsi2(0x00000065, 0))
218 if (test__ctzsi2(0x00000066, 1))
220 if (test__ctzsi2(0x00000067, 0))
222 if (test__ctzsi2(0x00000068, 3))
224 if (test__ctzsi2(0x00000069, 0))
226 if (test__ctzsi2(0x0000006A, 1))
228 if (test__ctzsi2(0x0000006B, 0))
230 if (test__ctzsi2(0x0000006C, 2))
232 if (test__ctzsi2(0x0000006D, 0))
234 if (test__ctzsi2(0x0000006E, 1))
236 if (test__ctzsi2(0x0000006F, 0))
238 if (test__ctzsi2(0x00000070, 4))
240 if (test__ctzsi2(0x00000072, 1))
242 if (test__ctzsi2(0x00000073, 0))
244 if (test__ctzsi2(0x00000074, 2))
246 if (test__ctzsi2(0x00000075, 0))
248 if (test__ctzsi2(0x00000076, 1))
250 if (test__ctzsi2(0x00000077, 0))
252 if (test__ctzsi2(0x00000078, 3))
254 if (test__ctzsi2(0x00000079, 0))
256 if (test__ctzsi2(0x0000007A, 1))
258 if (test__ctzsi2(0x0000007B, 0))
260 if (test__ctzsi2(0x0000007C, 2))
262 if (test__ctzsi2(0x0000007D, 0))
264 if (test__ctzsi2(0x0000007E, 1))
266 if (test__ctzsi2(0x0000007F, 0))
268 if (test__ctzsi2(0x00000080, 7))
270 if (test__ctzsi2(0x00000082, 1))
272 if (test__ctzsi2(0x00000083, 0))
274 if (test__ctzsi2(0x00000084, 2))
276 if (test__ctzsi2(0x00000085, 0))
278 if (test__ctzsi2(0x00000086, 1))
280 if (test__ctzsi2(0x00000087, 0))
282 if (test__ctzsi2(0x00000088, 3))
284 if (test__ctzsi2(0x00000089, 0))
286 if (test__ctzsi2(0x0000008A, 1))
288 if (test__ctzsi2(0x0000008B, 0))
290 if (test__ctzsi2(0x0000008C, 2))
292 if (test__ctzsi2(0x0000008D, 0))
294 if (test__ctzsi2(0x0000008E, 1))
296 if (test__ctzsi2(0x0000008F, 0))
298 if (test__ctzsi2(0x00000090, 4))
300 if (test__ctzsi2(0x00000092, 1))
302 if (test__ctzsi2(0x00000093, 0))
304 if (test__ctzsi2(0x00000094, 2))
306 if (test__ctzsi2(0x00000095, 0))
308 if (test__ctzsi2(0x00000096, 1))
310 if (test__ctzsi2(0x00000097, 0))
312 if (test__ctzsi2(0x00000098, 3))
314 if (test__ctzsi2(0x00000099, 0))
316 if (test__ctzsi2(0x0000009A, 1))
318 if (test__ctzsi2(0x0000009B, 0))
320 if (test__ctzsi2(0x0000009C, 2))
322 if (test__ctzsi2(0x0000009D, 0))
324 if (test__ctzsi2(0x0000009E, 1))
326 if (test__ctzsi2(0x0000009F, 0))
328 if (test__ctzsi2(0x000000A0, 5))
330 if (test__ctzsi2(0x000000A2, 1))
332 if (test__ctzsi2(0x000000A3, 0))
334 if (test__ctzsi2(0x000000A4, 2))
336 if (test__ctzsi2(0x000000A5, 0))
338 if (test__ctzsi2(0x000000A6, 1))
340 if (test__ctzsi2(0x000000A7, 0))
342 if (test__ctzsi2(0x000000A8, 3))
344 if (test__ctzsi2(0x000000A9, 0))
346 if (test__ctzsi2(0x000000AA, 1))
348 if (test__ctzsi2(0x000000AB, 0))
350 if (test__ctzsi2(0x000000AC, 2))
352 if (test__ctzsi2(0x000000AD, 0))
354 if (test__ctzsi2(0x000000AE, 1))
356 if (test__ctzsi2(0x000000AF, 0))
358 if (test__ctzsi2(0x000000B0, 4))
360 if (test__ctzsi2(0x000000B2, 1))
362 if (test__ctzsi2(0x000000B3, 0))
364 if (test__ctzsi2(0x000000B4, 2))
366 if (test__ctzsi2(0x000000B5, 0))
368 if (test__ctzsi2(0x000000B6, 1))
370 if (test__ctzsi2(0x000000B7, 0))
372 if (test__ctzsi2(0x000000B8, 3))
374 if (test__ctzsi2(0x000000B9, 0))
376 if (test__ctzsi2(0x000000BA, 1))
378 if (test__ctzsi2(0x000000BB, 0))
380 if (test__ctzsi2(0x000000BC, 2))
382 if (test__ctzsi2(0x000000BD, 0))
384 if (test__ctzsi2(0x000000BE, 1))
386 if (test__ctzsi2(0x000000BF, 0))
388 if (test__ctzsi2(0x000000C0, 6))
390 if (test__ctzsi2(0x000000C2, 1))
392 if (test__ctzsi2(0x000000C3, 0))
394 if (test__ctzsi2(0x000000C4, 2))
396 if (test__ctzsi2(0x000000C5, 0))
398 if (test__ctzsi2(0x000000C6, 1))
400 if (test__ctzsi2(0x000000C7, 0))
402 if (test__ctzsi2(0x000000C8, 3))
404 if (test__ctzsi2(0x000000C9, 0))
406 if (test__ctzsi2(0x000000CA, 1))
408 if (test__ctzsi2(0x000000CB, 0))
410 if (test__ctzsi2(0x000000CC, 2))
412 if (test__ctzsi2(0x000000CD, 0))
414 if (test__ctzsi2(0x000000CE, 1))
416 if (test__ctzsi2(0x000000CF, 0))
418 if (test__ctzsi2(0x000000D0, 4))
420 if (test__ctzsi2(0x000000D2, 1))
422 if (test__ctzsi2(0x000000D3, 0))
424 if (test__ctzsi2(0x000000D4, 2))
426 if (test__ctzsi2(0x000000D5, 0))
428 if (test__ctzsi2(0x000000D6, 1))
430 if (test__ctzsi2(0x000000D7, 0))
432 if (test__ctzsi2(0x000000D8, 3))
434 if (test__ctzsi2(0x000000D9, 0))
436 if (test__ctzsi2(0x000000DA, 1))
438 if (test__ctzsi2(0x000000DB, 0))
440 if (test__ctzsi2(0x000000DC, 2))
442 if (test__ctzsi2(0x000000DD, 0))
444 if (test__ctzsi2(0x000000DE, 1))
446 if (test__ctzsi2(0x000000DF, 0))
448 if (test__ctzsi2(0x000000E0, 5))
450 if (test__ctzsi2(0x000000E2, 1))
452 if (test__ctzsi2(0x000000E3, 0))
454 if (test__ctzsi2(0x000000E4, 2))
456 if (test__ctzsi2(0x000000E5, 0))
458 if (test__ctzsi2(0x000000E6, 1))
460 if (test__ctzsi2(0x000000E7, 0))
462 if (test__ctzsi2(0x000000E8, 3))
464 if (test__ctzsi2(0x000000E9, 0))
466 if (test__ctzsi2(0x000000EA, 1))
468 if (test__ctzsi2(0x000000EB, 0))
470 if (test__ctzsi2(0x000000EC, 2))
472 if (test__ctzsi2(0x000000ED, 0))
474 if (test__ctzsi2(0x000000EE, 1))
476 if (test__ctzsi2(0x000000EF, 0))
478 if (test__ctzsi2(0x000000F0, 4))
480 if (test__ctzsi2(0x000000F2, 1))
482 if (test__ctzsi2(0x000000F3, 0))
484 if (test__ctzsi2(0x000000F4, 2))
486 if (test__ctzsi2(0x000000F5, 0))
488 if (test__ctzsi2(0x000000F6, 1))
490 if (test__ctzsi2(0x000000F7, 0))
492 if (test__ctzsi2(0x000000F8, 3))
494 if (test__ctzsi2(0x000000F9, 0))
496 if (test__ctzsi2(0x000000FA, 1))
498 if (test__ctzsi2(0x000000FB, 0))
500 if (test__ctzsi2(0x000000FC, 2))
502 if (test__ctzsi2(0x000000FD, 0))
504 if (test__ctzsi2(0x000000FE, 1))
506 if (test__ctzsi2(0x000000FF, 0))
509 if (test__ctzsi2(0x00000100, 8))
511 if (test__ctzsi2(0x00000200, 9))
513 if (test__ctzsi2(0x00000400, 10))
515 if (test__ctzsi2(0x00000800, 11))
517 if (test__ctzsi2(0x00001000, 12))
519 if (test__ctzsi2(0x00002000, 13))
521 if (test__ctzsi2(0x00004000, 14))
523 if (test__ctzsi2(0x00008000, 15))
525 if (test__ctzsi2(0x00010000, 16))
527 if (test__ctzsi2(0x00020000, 17))
529 if (test__ctzsi2(0x00040000, 18))
531 if (test__ctzsi2(0x00080000, 19))
533 if (test__ctzsi2(0x00100000, 20))
535 if (test__ctzsi2(0x00200000, 21))
537 if (test__ctzsi2(0x00400000, 22))
539 if (test__ctzsi2(0x00800000, 23))
541 if (test__ctzsi2(0x01000000, 24))
543 if (test__ctzsi2(0x02000000, 25))
545 if (test__ctzsi2(0x04000000, 26))
547 if (test__ctzsi2(0x08000000, 27))
549 if (test__ctzsi2(0x10000000, 28))
551 if (test__ctzsi2(0x20000000, 29))
553 if (test__ctzsi2(0x40000000, 30))
555 if (test__ctzsi2(0x80000000, 31))