Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / ctzti2_test.c
blob054776ef71cff8b99a6ed7b48ef3ccd720ede688
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ctzti2
3 // REQUIRES: int128
5 #include "int_lib.h"
6 #include <stdio.h>
8 #ifdef CRT_HAS_128BIT
10 // Returns: the number of trailing 0-bits
12 // Precondition: a != 0
14 COMPILER_RT_ABI int __ctzti2(ti_int a);
16 int test__ctzti2(ti_int a, int expected)
18 int x = __ctzti2(a);
19 if (x != expected)
21 twords at;
22 at.all = a;
23 printf("error in __ctzti2(0x%llX%.16llX) = %d, expected %d\n",
24 at.s.high, at.s.low, x, expected);
26 return x != expected;
29 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
31 #endif
33 int main()
35 #ifdef CRT_HAS_128BIT
36 if (test__ctzti2(0x00000001, 0))
37 return 1;
38 if (test__ctzti2(0x00000002, 1))
39 return 1;
40 if (test__ctzti2(0x00000003, 0))
41 return 1;
42 if (test__ctzti2(0x00000004, 2))
43 return 1;
44 if (test__ctzti2(0x00000005, 0))
45 return 1;
46 if (test__ctzti2(0x0000000A, 1))
47 return 1;
48 if (test__ctzti2(0x10000000, 28))
49 return 1;
50 if (test__ctzti2(0x20000000, 29))
51 return 1;
52 if (test__ctzti2(0x60000000, 29))
53 return 1;
54 if (test__ctzti2(0x80000000uLL, 31))
55 return 1;
56 if (test__ctzti2(0x0000050000000000uLL, 40))
57 return 1;
58 if (test__ctzti2(0x0200080000000000uLL, 43))
59 return 1;
60 if (test__ctzti2(0x7200000000000000uLL, 57))
61 return 1;
62 if (test__ctzti2(0x8000000000000000uLL, 63))
63 return 1;
64 if (test__ctzti2(make_ti(0x00000000A0000000LL, 0x0000000000000000LL), 93))
65 return 1;
66 if (test__ctzti2(make_ti(0xF000000000000000LL, 0x0000000000000000LL), 124))
67 return 1;
68 if (test__ctzti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 127))
69 return 1;
70 #else
71 printf("skipped\n");
72 #endif
74 return 0;