1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_ffssi2 |
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 __ffssi2(si_int a); |
11 | |
12 | int test__ffssi2(si_int a, int expected) |
13 | { |
14 | int x = __ffssi2(a); |
15 | if (x != expected) |
16 | printf(format: "error in __ffssi2(0x%X) = %d, expected %d\n" , a, x, expected); |
17 | return x != expected; |
18 | } |
19 | |
20 | int main() |
21 | { |
22 | if (test__ffssi2(a: 0x00000000, expected: 0)) |
23 | return 1; |
24 | if (test__ffssi2(a: 0x00000001, expected: 1)) |
25 | return 1; |
26 | if (test__ffssi2(a: 0x00000002, expected: 2)) |
27 | return 1; |
28 | if (test__ffssi2(a: 0x00000003, expected: 1)) |
29 | return 1; |
30 | if (test__ffssi2(a: 0x00000004, expected: 3)) |
31 | return 1; |
32 | if (test__ffssi2(a: 0x00000005, expected: 1)) |
33 | return 1; |
34 | if (test__ffssi2(a: 0x0000000A, expected: 2)) |
35 | return 1; |
36 | if (test__ffssi2(a: 0x10000000, expected: 29)) |
37 | return 1; |
38 | if (test__ffssi2(a: 0x20000000, expected: 30)) |
39 | return 1; |
40 | if (test__ffssi2(a: 0x60000000, expected: 30)) |
41 | return 1; |
42 | if (test__ffssi2(a: 0x80000000u, expected: 32)) |
43 | return 1; |
44 | |
45 | return 0; |
46 | } |
47 | |