Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / ffsti2_test.c
blob446b16fe3871ce1b8b4f0dd505236dd4cb8286f2
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ffsti2
3 // REQUIRES: int128
5 #include "int_lib.h"
6 #include <stdio.h>
8 #ifdef CRT_HAS_128BIT
10 // Returns: the index of the least significant 1-bit in a, or
11 // the value zero if a is zero. The least significant bit is index one.
13 COMPILER_RT_ABI int __ffsti2(ti_int a);
15 int test__ffsti2(ti_int a, int expected)
17 int x = __ffsti2(a);
18 if (x != expected)
20 twords at;
21 at.all = a;
22 printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
23 at.s.high, at.s.low, x, expected);
25 return x != expected;
28 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
30 #endif
32 int main()
34 #ifdef CRT_HAS_128BIT
35 if (test__ffsti2(0x00000000, 0))
36 return 1;
37 if (test__ffsti2(0x00000001, 1))
38 return 1;
39 if (test__ffsti2(0x00000002, 2))
40 return 1;
41 if (test__ffsti2(0x00000003, 1))
42 return 1;
43 if (test__ffsti2(0x00000004, 3))
44 return 1;
45 if (test__ffsti2(0x00000005, 1))
46 return 1;
47 if (test__ffsti2(0x0000000A, 2))
48 return 1;
49 if (test__ffsti2(0x10000000, 29))
50 return 1;
51 if (test__ffsti2(0x20000000, 30))
52 return 1;
53 if (test__ffsti2(0x60000000, 30))
54 return 1;
55 if (test__ffsti2(0x80000000uLL, 32))
56 return 1;
57 if (test__ffsti2(0x0000050000000000uLL, 41))
58 return 1;
59 if (test__ffsti2(0x0200080000000000uLL, 44))
60 return 1;
61 if (test__ffsti2(0x7200000000000000uLL, 58))
62 return 1;
63 if (test__ffsti2(0x8000000000000000uLL, 64))
64 return 1;
65 if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
66 return 1;
67 if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
68 return 1;
70 #else
71 printf("skipped\n");
72 #endif
73 return 0;