1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_ffsdi2 |
3 | |
4 | #include "int_lib.h" |
5 | #include <stdio.h> |
6 | |
7 | // Returns: the index of the least significant 1-bit in a, or |
8 | // the value zero if a is zero. The least significant bit is index one. |
9 | |
10 | COMPILER_RT_ABI int __ffsdi2(di_int a); |
11 | |
12 | int test__ffsdi2(di_int a, int expected) |
13 | { |
14 | int x = __ffsdi2(a); |
15 | if (x != expected) |
16 | printf(format: "error in __ffsdi2(0x%llX) = %d, expected %d\n" , a, x, expected); |
17 | return x != expected; |
18 | } |
19 | |
20 | char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; |
21 | |
22 | int main() |
23 | { |
24 | if (test__ffsdi2(a: 0x00000000, expected: 0)) |
25 | return 1; |
26 | if (test__ffsdi2(a: 0x00000001, expected: 1)) |
27 | return 1; |
28 | if (test__ffsdi2(a: 0x00000002, expected: 2)) |
29 | return 1; |
30 | if (test__ffsdi2(a: 0x00000003, expected: 1)) |
31 | return 1; |
32 | if (test__ffsdi2(a: 0x00000004, expected: 3)) |
33 | return 1; |
34 | if (test__ffsdi2(a: 0x00000005, expected: 1)) |
35 | return 1; |
36 | if (test__ffsdi2(a: 0x0000000A, expected: 2)) |
37 | return 1; |
38 | if (test__ffsdi2(a: 0x10000000, expected: 29)) |
39 | return 1; |
40 | if (test__ffsdi2(a: 0x20000000, expected: 30)) |
41 | return 1; |
42 | if (test__ffsdi2(a: 0x60000000, expected: 30)) |
43 | return 1; |
44 | if (test__ffsdi2(a: 0x80000000uLL, expected: 32)) |
45 | return 1; |
46 | if (test__ffsdi2(a: 0x0000050000000000uLL, expected: 41)) |
47 | return 1; |
48 | if (test__ffsdi2(a: 0x0200080000000000uLL, expected: 44)) |
49 | return 1; |
50 | if (test__ffsdi2(a: 0x7200000000000000uLL, expected: 58)) |
51 | return 1; |
52 | if (test__ffsdi2(a: 0x8000000000000000uLL, expected: 64)) |
53 | return 1; |
54 | |
55 | return 0; |
56 | } |
57 | |