1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_ffsti2
4 //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //===----------------------------------------------------------------------===//
12 // This file tests __ffsti2 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
21 // Returns: the index of the least significant 1-bit in a, or
22 // the value zero if a is zero. The least significant bit is index one.
24 COMPILER_RT_ABI si_int
__ffsti2(ti_int a
);
26 int test__ffsti2(ti_int a
, si_int expected
)
28 si_int x
= __ffsti2(a
);
33 printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
34 at
.s
.high
, at
.s
.low
, x
, expected
);
39 char assumption_1
[sizeof(ti_int
) == 2*sizeof(di_int
)] = {0};
46 if (test__ffsti2(0x00000000, 0))
48 if (test__ffsti2(0x00000001, 1))
50 if (test__ffsti2(0x00000002, 2))
52 if (test__ffsti2(0x00000003, 1))
54 if (test__ffsti2(0x00000004, 3))
56 if (test__ffsti2(0x00000005, 1))
58 if (test__ffsti2(0x0000000A, 2))
60 if (test__ffsti2(0x10000000, 29))
62 if (test__ffsti2(0x20000000, 30))
64 if (test__ffsti2(0x60000000, 30))
66 if (test__ffsti2(0x80000000uLL
, 32))
68 if (test__ffsti2(0x0000050000000000uLL
, 41))
70 if (test__ffsti2(0x0200080000000000uLL
, 44))
72 if (test__ffsti2(0x7200000000000000uLL
, 58))
74 if (test__ffsti2(0x8000000000000000uLL
, 64))
76 if (test__ffsti2(make_ti(0x8000000800000000uLL
, 0), 100))
78 if (test__ffsti2(make_ti(0x8000000000000000uLL
, 0), 128))