1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ctzsi2
3 //===-- ctzsi2_test.c - Test __ctzsi2 -------------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __ctzsi2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
18 // Returns: the number of trailing 0-bits
20 // Precondition: a != 0
22 COMPILER_RT_ABI si_int
__ctzsi2(si_int a
);
24 int test__ctzsi2(si_int a
, si_int expected
)
26 si_int x
= __ctzsi2(a
);
28 printf("error in __ctzsi2(0x%X) = %d, expected %d\n", a
, x
, expected
);
32 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
33 char assumption_2
[sizeof(si_int
)*CHAR_BIT
== 32] = {0};
37 // if (test__ctzsi2(0x00000000, 32)) // undefined
39 if (test__ctzsi2(0x00000001, 0))
41 if (test__ctzsi2(0x00000002, 1))
43 if (test__ctzsi2(0x00000003, 0))
45 if (test__ctzsi2(0x00000004, 2))
47 if (test__ctzsi2(0x00000005, 0))
49 if (test__ctzsi2(0x00000006, 1))
51 if (test__ctzsi2(0x00000007, 0))
53 if (test__ctzsi2(0x00000008, 3))
55 if (test__ctzsi2(0x00000009, 0))
57 if (test__ctzsi2(0x0000000A, 1))
59 if (test__ctzsi2(0x0000000B, 0))
61 if (test__ctzsi2(0x0000000C, 2))
63 if (test__ctzsi2(0x0000000D, 0))
65 if (test__ctzsi2(0x0000000E, 1))
67 if (test__ctzsi2(0x0000000F, 0))
69 if (test__ctzsi2(0x00000010, 4))
71 if (test__ctzsi2(0x00000012, 1))
73 if (test__ctzsi2(0x00000013, 0))
75 if (test__ctzsi2(0x00000014, 2))
77 if (test__ctzsi2(0x00000015, 0))
79 if (test__ctzsi2(0x00000016, 1))
81 if (test__ctzsi2(0x00000017, 0))
83 if (test__ctzsi2(0x00000018, 3))
85 if (test__ctzsi2(0x00000019, 0))
87 if (test__ctzsi2(0x0000001A, 1))
89 if (test__ctzsi2(0x0000001B, 0))
91 if (test__ctzsi2(0x0000001C, 2))
93 if (test__ctzsi2(0x0000001D, 0))
95 if (test__ctzsi2(0x0000001E, 1))
97 if (test__ctzsi2(0x0000001F, 0))
99 if (test__ctzsi2(0x00000020, 5))
101 if (test__ctzsi2(0x00000022, 1))
103 if (test__ctzsi2(0x00000023, 0))
105 if (test__ctzsi2(0x00000024, 2))
107 if (test__ctzsi2(0x00000025, 0))
109 if (test__ctzsi2(0x00000026, 1))
111 if (test__ctzsi2(0x00000027, 0))
113 if (test__ctzsi2(0x00000028, 3))
115 if (test__ctzsi2(0x00000029, 0))
117 if (test__ctzsi2(0x0000002A, 1))
119 if (test__ctzsi2(0x0000002B, 0))
121 if (test__ctzsi2(0x0000002C, 2))
123 if (test__ctzsi2(0x0000002D, 0))
125 if (test__ctzsi2(0x0000002E, 1))
127 if (test__ctzsi2(0x0000002F, 0))
129 if (test__ctzsi2(0x00000030, 4))
131 if (test__ctzsi2(0x00000032, 1))
133 if (test__ctzsi2(0x00000033, 0))
135 if (test__ctzsi2(0x00000034, 2))
137 if (test__ctzsi2(0x00000035, 0))
139 if (test__ctzsi2(0x00000036, 1))
141 if (test__ctzsi2(0x00000037, 0))
143 if (test__ctzsi2(0x00000038, 3))
145 if (test__ctzsi2(0x00000039, 0))
147 if (test__ctzsi2(0x0000003A, 1))
149 if (test__ctzsi2(0x0000003B, 0))
151 if (test__ctzsi2(0x0000003C, 2))
153 if (test__ctzsi2(0x0000003D, 0))
155 if (test__ctzsi2(0x0000003E, 1))
157 if (test__ctzsi2(0x0000003F, 0))
159 if (test__ctzsi2(0x00000040, 6))
161 if (test__ctzsi2(0x00000042, 1))
163 if (test__ctzsi2(0x00000043, 0))
165 if (test__ctzsi2(0x00000044, 2))
167 if (test__ctzsi2(0x00000045, 0))
169 if (test__ctzsi2(0x00000046, 1))
171 if (test__ctzsi2(0x00000047, 0))
173 if (test__ctzsi2(0x00000048, 3))
175 if (test__ctzsi2(0x00000049, 0))
177 if (test__ctzsi2(0x0000004A, 1))
179 if (test__ctzsi2(0x0000004B, 0))
181 if (test__ctzsi2(0x0000004C, 2))
183 if (test__ctzsi2(0x0000004D, 0))
185 if (test__ctzsi2(0x0000004E, 1))
187 if (test__ctzsi2(0x0000004F, 0))
189 if (test__ctzsi2(0x00000050, 4))
191 if (test__ctzsi2(0x00000052, 1))
193 if (test__ctzsi2(0x00000053, 0))
195 if (test__ctzsi2(0x00000054, 2))
197 if (test__ctzsi2(0x00000055, 0))
199 if (test__ctzsi2(0x00000056, 1))
201 if (test__ctzsi2(0x00000057, 0))
203 if (test__ctzsi2(0x00000058, 3))
205 if (test__ctzsi2(0x00000059, 0))
207 if (test__ctzsi2(0x0000005A, 1))
209 if (test__ctzsi2(0x0000005B, 0))
211 if (test__ctzsi2(0x0000005C, 2))
213 if (test__ctzsi2(0x0000005D, 0))
215 if (test__ctzsi2(0x0000005E, 1))
217 if (test__ctzsi2(0x0000005F, 0))
219 if (test__ctzsi2(0x00000060, 5))
221 if (test__ctzsi2(0x00000062, 1))
223 if (test__ctzsi2(0x00000063, 0))
225 if (test__ctzsi2(0x00000064, 2))
227 if (test__ctzsi2(0x00000065, 0))
229 if (test__ctzsi2(0x00000066, 1))
231 if (test__ctzsi2(0x00000067, 0))
233 if (test__ctzsi2(0x00000068, 3))
235 if (test__ctzsi2(0x00000069, 0))
237 if (test__ctzsi2(0x0000006A, 1))
239 if (test__ctzsi2(0x0000006B, 0))
241 if (test__ctzsi2(0x0000006C, 2))
243 if (test__ctzsi2(0x0000006D, 0))
245 if (test__ctzsi2(0x0000006E, 1))
247 if (test__ctzsi2(0x0000006F, 0))
249 if (test__ctzsi2(0x00000070, 4))
251 if (test__ctzsi2(0x00000072, 1))
253 if (test__ctzsi2(0x00000073, 0))
255 if (test__ctzsi2(0x00000074, 2))
257 if (test__ctzsi2(0x00000075, 0))
259 if (test__ctzsi2(0x00000076, 1))
261 if (test__ctzsi2(0x00000077, 0))
263 if (test__ctzsi2(0x00000078, 3))
265 if (test__ctzsi2(0x00000079, 0))
267 if (test__ctzsi2(0x0000007A, 1))
269 if (test__ctzsi2(0x0000007B, 0))
271 if (test__ctzsi2(0x0000007C, 2))
273 if (test__ctzsi2(0x0000007D, 0))
275 if (test__ctzsi2(0x0000007E, 1))
277 if (test__ctzsi2(0x0000007F, 0))
279 if (test__ctzsi2(0x00000080, 7))
281 if (test__ctzsi2(0x00000082, 1))
283 if (test__ctzsi2(0x00000083, 0))
285 if (test__ctzsi2(0x00000084, 2))
287 if (test__ctzsi2(0x00000085, 0))
289 if (test__ctzsi2(0x00000086, 1))
291 if (test__ctzsi2(0x00000087, 0))
293 if (test__ctzsi2(0x00000088, 3))
295 if (test__ctzsi2(0x00000089, 0))
297 if (test__ctzsi2(0x0000008A, 1))
299 if (test__ctzsi2(0x0000008B, 0))
301 if (test__ctzsi2(0x0000008C, 2))
303 if (test__ctzsi2(0x0000008D, 0))
305 if (test__ctzsi2(0x0000008E, 1))
307 if (test__ctzsi2(0x0000008F, 0))
309 if (test__ctzsi2(0x00000090, 4))
311 if (test__ctzsi2(0x00000092, 1))
313 if (test__ctzsi2(0x00000093, 0))
315 if (test__ctzsi2(0x00000094, 2))
317 if (test__ctzsi2(0x00000095, 0))
319 if (test__ctzsi2(0x00000096, 1))
321 if (test__ctzsi2(0x00000097, 0))
323 if (test__ctzsi2(0x00000098, 3))
325 if (test__ctzsi2(0x00000099, 0))
327 if (test__ctzsi2(0x0000009A, 1))
329 if (test__ctzsi2(0x0000009B, 0))
331 if (test__ctzsi2(0x0000009C, 2))
333 if (test__ctzsi2(0x0000009D, 0))
335 if (test__ctzsi2(0x0000009E, 1))
337 if (test__ctzsi2(0x0000009F, 0))
339 if (test__ctzsi2(0x000000A0, 5))
341 if (test__ctzsi2(0x000000A2, 1))
343 if (test__ctzsi2(0x000000A3, 0))
345 if (test__ctzsi2(0x000000A4, 2))
347 if (test__ctzsi2(0x000000A5, 0))
349 if (test__ctzsi2(0x000000A6, 1))
351 if (test__ctzsi2(0x000000A7, 0))
353 if (test__ctzsi2(0x000000A8, 3))
355 if (test__ctzsi2(0x000000A9, 0))
357 if (test__ctzsi2(0x000000AA, 1))
359 if (test__ctzsi2(0x000000AB, 0))
361 if (test__ctzsi2(0x000000AC, 2))
363 if (test__ctzsi2(0x000000AD, 0))
365 if (test__ctzsi2(0x000000AE, 1))
367 if (test__ctzsi2(0x000000AF, 0))
369 if (test__ctzsi2(0x000000B0, 4))
371 if (test__ctzsi2(0x000000B2, 1))
373 if (test__ctzsi2(0x000000B3, 0))
375 if (test__ctzsi2(0x000000B4, 2))
377 if (test__ctzsi2(0x000000B5, 0))
379 if (test__ctzsi2(0x000000B6, 1))
381 if (test__ctzsi2(0x000000B7, 0))
383 if (test__ctzsi2(0x000000B8, 3))
385 if (test__ctzsi2(0x000000B9, 0))
387 if (test__ctzsi2(0x000000BA, 1))
389 if (test__ctzsi2(0x000000BB, 0))
391 if (test__ctzsi2(0x000000BC, 2))
393 if (test__ctzsi2(0x000000BD, 0))
395 if (test__ctzsi2(0x000000BE, 1))
397 if (test__ctzsi2(0x000000BF, 0))
399 if (test__ctzsi2(0x000000C0, 6))
401 if (test__ctzsi2(0x000000C2, 1))
403 if (test__ctzsi2(0x000000C3, 0))
405 if (test__ctzsi2(0x000000C4, 2))
407 if (test__ctzsi2(0x000000C5, 0))
409 if (test__ctzsi2(0x000000C6, 1))
411 if (test__ctzsi2(0x000000C7, 0))
413 if (test__ctzsi2(0x000000C8, 3))
415 if (test__ctzsi2(0x000000C9, 0))
417 if (test__ctzsi2(0x000000CA, 1))
419 if (test__ctzsi2(0x000000CB, 0))
421 if (test__ctzsi2(0x000000CC, 2))
423 if (test__ctzsi2(0x000000CD, 0))
425 if (test__ctzsi2(0x000000CE, 1))
427 if (test__ctzsi2(0x000000CF, 0))
429 if (test__ctzsi2(0x000000D0, 4))
431 if (test__ctzsi2(0x000000D2, 1))
433 if (test__ctzsi2(0x000000D3, 0))
435 if (test__ctzsi2(0x000000D4, 2))
437 if (test__ctzsi2(0x000000D5, 0))
439 if (test__ctzsi2(0x000000D6, 1))
441 if (test__ctzsi2(0x000000D7, 0))
443 if (test__ctzsi2(0x000000D8, 3))
445 if (test__ctzsi2(0x000000D9, 0))
447 if (test__ctzsi2(0x000000DA, 1))
449 if (test__ctzsi2(0x000000DB, 0))
451 if (test__ctzsi2(0x000000DC, 2))
453 if (test__ctzsi2(0x000000DD, 0))
455 if (test__ctzsi2(0x000000DE, 1))
457 if (test__ctzsi2(0x000000DF, 0))
459 if (test__ctzsi2(0x000000E0, 5))
461 if (test__ctzsi2(0x000000E2, 1))
463 if (test__ctzsi2(0x000000E3, 0))
465 if (test__ctzsi2(0x000000E4, 2))
467 if (test__ctzsi2(0x000000E5, 0))
469 if (test__ctzsi2(0x000000E6, 1))
471 if (test__ctzsi2(0x000000E7, 0))
473 if (test__ctzsi2(0x000000E8, 3))
475 if (test__ctzsi2(0x000000E9, 0))
477 if (test__ctzsi2(0x000000EA, 1))
479 if (test__ctzsi2(0x000000EB, 0))
481 if (test__ctzsi2(0x000000EC, 2))
483 if (test__ctzsi2(0x000000ED, 0))
485 if (test__ctzsi2(0x000000EE, 1))
487 if (test__ctzsi2(0x000000EF, 0))
489 if (test__ctzsi2(0x000000F0, 4))
491 if (test__ctzsi2(0x000000F2, 1))
493 if (test__ctzsi2(0x000000F3, 0))
495 if (test__ctzsi2(0x000000F4, 2))
497 if (test__ctzsi2(0x000000F5, 0))
499 if (test__ctzsi2(0x000000F6, 1))
501 if (test__ctzsi2(0x000000F7, 0))
503 if (test__ctzsi2(0x000000F8, 3))
505 if (test__ctzsi2(0x000000F9, 0))
507 if (test__ctzsi2(0x000000FA, 1))
509 if (test__ctzsi2(0x000000FB, 0))
511 if (test__ctzsi2(0x000000FC, 2))
513 if (test__ctzsi2(0x000000FD, 0))
515 if (test__ctzsi2(0x000000FE, 1))
517 if (test__ctzsi2(0x000000FF, 0))
520 if (test__ctzsi2(0x00000100, 8))
522 if (test__ctzsi2(0x00000200, 9))
524 if (test__ctzsi2(0x00000400, 10))
526 if (test__ctzsi2(0x00000800, 11))
528 if (test__ctzsi2(0x00001000, 12))
530 if (test__ctzsi2(0x00002000, 13))
532 if (test__ctzsi2(0x00004000, 14))
534 if (test__ctzsi2(0x00008000, 15))
536 if (test__ctzsi2(0x00010000, 16))
538 if (test__ctzsi2(0x00020000, 17))
540 if (test__ctzsi2(0x00040000, 18))
542 if (test__ctzsi2(0x00080000, 19))
544 if (test__ctzsi2(0x00100000, 20))
546 if (test__ctzsi2(0x00200000, 21))
548 if (test__ctzsi2(0x00400000, 22))
550 if (test__ctzsi2(0x00800000, 23))
552 if (test__ctzsi2(0x01000000, 24))
554 if (test__ctzsi2(0x02000000, 25))
556 if (test__ctzsi2(0x04000000, 26))
558 if (test__ctzsi2(0x08000000, 27))
560 if (test__ctzsi2(0x10000000, 28))
562 if (test__ctzsi2(0x20000000, 29))
564 if (test__ctzsi2(0x40000000, 30))
566 if (test__ctzsi2(0x80000000, 31))