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