1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_ctzti2 |
3 | // REQUIRES: int128 |
4 | |
5 | #include "int_lib.h" |
6 | #include <stdio.h> |
7 | |
8 | #ifdef CRT_HAS_128BIT |
9 | |
10 | // Returns: the number of trailing 0-bits |
11 | |
12 | // Precondition: a != 0 |
13 | |
14 | COMPILER_RT_ABI int __ctzti2(ti_int a); |
15 | |
16 | int test__ctzti2(ti_int a, int expected) |
17 | { |
18 | int x = __ctzti2(a); |
19 | if (x != expected) |
20 | { |
21 | twords at; |
22 | at.all = a; |
23 | printf(format: "error in __ctzti2(0x%llX%.16llX) = %d, expected %d\n" , |
24 | at.s.high, at.s.low, x, expected); |
25 | } |
26 | return x != expected; |
27 | } |
28 | |
29 | char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; |
30 | |
31 | #endif |
32 | |
33 | int main() |
34 | { |
35 | #ifdef CRT_HAS_128BIT |
36 | if (test__ctzti2(a: 0x00000001, expected: 0)) |
37 | return 1; |
38 | if (test__ctzti2(a: 0x00000002, expected: 1)) |
39 | return 1; |
40 | if (test__ctzti2(a: 0x00000003, expected: 0)) |
41 | return 1; |
42 | if (test__ctzti2(a: 0x00000004, expected: 2)) |
43 | return 1; |
44 | if (test__ctzti2(a: 0x00000005, expected: 0)) |
45 | return 1; |
46 | if (test__ctzti2(a: 0x0000000A, expected: 1)) |
47 | return 1; |
48 | if (test__ctzti2(a: 0x10000000, expected: 28)) |
49 | return 1; |
50 | if (test__ctzti2(a: 0x20000000, expected: 29)) |
51 | return 1; |
52 | if (test__ctzti2(a: 0x60000000, expected: 29)) |
53 | return 1; |
54 | if (test__ctzti2(a: 0x80000000uLL, expected: 31)) |
55 | return 1; |
56 | if (test__ctzti2(a: 0x0000050000000000uLL, expected: 40)) |
57 | return 1; |
58 | if (test__ctzti2(a: 0x0200080000000000uLL, expected: 43)) |
59 | return 1; |
60 | if (test__ctzti2(a: 0x7200000000000000uLL, expected: 57)) |
61 | return 1; |
62 | if (test__ctzti2(a: 0x8000000000000000uLL, expected: 63)) |
63 | return 1; |
64 | if (test__ctzti2(a: make_ti(h: 0x00000000A0000000LL, l: 0x0000000000000000LL), expected: 93)) |
65 | return 1; |
66 | if (test__ctzti2(a: make_ti(h: 0xF000000000000000LL, l: 0x0000000000000000LL), expected: 124)) |
67 | return 1; |
68 | if (test__ctzti2(a: make_ti(h: 0x8000000000000000LL, l: 0x0000000000000000LL), expected: 127)) |
69 | return 1; |
70 | #else |
71 | printf("skipped\n" ); |
72 | #endif |
73 | |
74 | return 0; |
75 | } |
76 | |