xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/ffsdi2_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- ffsdi2_test.c - Test __ffsdi2 -------------------------------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __ffsdi2 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot // Returns: the index of the least significant 1-bit in a, or
18*7c3d14c8STreehugger Robot // the value zero if a is zero. The least significant bit is index one.
19*7c3d14c8STreehugger Robot 
20*7c3d14c8STreehugger Robot COMPILER_RT_ABI si_int __ffsdi2(di_int a);
21*7c3d14c8STreehugger Robot 
test__ffsdi2(di_int a,si_int expected)22*7c3d14c8STreehugger Robot int test__ffsdi2(di_int a, si_int expected)
23*7c3d14c8STreehugger Robot {
24*7c3d14c8STreehugger Robot     si_int x = __ffsdi2(a);
25*7c3d14c8STreehugger Robot     if (x != expected)
26*7c3d14c8STreehugger Robot         printf("error in __ffsdi2(0x%llX) = %d, expected %d\n", a, x, expected);
27*7c3d14c8STreehugger Robot     return x != expected;
28*7c3d14c8STreehugger Robot }
29*7c3d14c8STreehugger Robot 
30*7c3d14c8STreehugger Robot char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
31*7c3d14c8STreehugger Robot 
main()32*7c3d14c8STreehugger Robot int main()
33*7c3d14c8STreehugger Robot {
34*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x00000000, 0))
35*7c3d14c8STreehugger Robot         return 1;
36*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x00000001, 1))
37*7c3d14c8STreehugger Robot         return 1;
38*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x00000002, 2))
39*7c3d14c8STreehugger Robot         return 1;
40*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x00000003, 1))
41*7c3d14c8STreehugger Robot         return 1;
42*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x00000004, 3))
43*7c3d14c8STreehugger Robot         return 1;
44*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x00000005, 1))
45*7c3d14c8STreehugger Robot         return 1;
46*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x0000000A, 2))
47*7c3d14c8STreehugger Robot         return 1;
48*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x10000000, 29))
49*7c3d14c8STreehugger Robot         return 1;
50*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x20000000, 30))
51*7c3d14c8STreehugger Robot         return 1;
52*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x60000000, 30))
53*7c3d14c8STreehugger Robot         return 1;
54*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x80000000uLL, 32))
55*7c3d14c8STreehugger Robot         return 1;
56*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x0000050000000000uLL, 41))
57*7c3d14c8STreehugger Robot         return 1;
58*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x0200080000000000uLL, 44))
59*7c3d14c8STreehugger Robot         return 1;
60*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x7200000000000000uLL, 58))
61*7c3d14c8STreehugger Robot         return 1;
62*7c3d14c8STreehugger Robot     if (test__ffsdi2(0x8000000000000000uLL, 64))
63*7c3d14c8STreehugger Robot         return 1;
64*7c3d14c8STreehugger Robot 
65*7c3d14c8STreehugger Robot    return 0;
66*7c3d14c8STreehugger Robot }
67