[GlobalISel] Avoid repeated hash lookups (NFC) (#124393)
[llvm-project.git] / compiler-rt / test / builtins / Unit / clzti2_test.c
blob13e0e698422f2b9b39957dd47e1f2404a074de20
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_clzti2
3 // REQUIRES: int128
5 #include "int_lib.h"
6 #include <stdio.h>
8 #ifdef CRT_HAS_128BIT
10 // Returns: the number of leading 0-bits
12 // Precondition: a != 0
14 COMPILER_RT_ABI int __clzti2(ti_int a);
16 int test__clzti2(ti_int a, int expected)
18 int x = __clzti2(a);
19 if (x != expected)
21 twords at;
22 at.all = a;
23 printf("error in __clzti2(0x%llX%.16llX) = %d, expected %d\n",
24 at.s.high, at.s.low, x, expected);
26 return x != expected;
29 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
31 #endif
33 int main()
35 #ifdef CRT_HAS_128BIT
36 const int N = (int)(sizeof(ti_int) * CHAR_BIT);
38 if (test__clzti2(0x00000001, N-1))
39 return 1;
40 if (test__clzti2(0x00000002, N-2))
41 return 1;
42 if (test__clzti2(0x00000003, N-2))
43 return 1;
44 if (test__clzti2(0x00000004, N-3))
45 return 1;
46 if (test__clzti2(0x00000005, N-3))
47 return 1;
48 if (test__clzti2(0x0000000A, N-4))
49 return 1;
50 if (test__clzti2(0x1000000A, N*3/4+3))
51 return 1;
52 if (test__clzti2(0x2000000A, N*3/4+2))
53 return 1;
54 if (test__clzti2(0x6000000A, N*3/4+1))
55 return 1;
56 if (test__clzti2(0x8000000AuLL, N*3/4))
57 return 1;
58 if (test__clzti2(0x000005008000000AuLL, 85))
59 return 1;
60 if (test__clzti2(0x020005008000000AuLL, 70))
61 return 1;
62 if (test__clzti2(0x720005008000000AuLL, 65))
63 return 1;
64 if (test__clzti2(0x820005008000000AuLL, 64))
65 return 1;
67 if (test__clzti2(make_ti(0x0000000080000000LL, 0x8000000800000000LL), 32))
68 return 1;
69 if (test__clzti2(make_ti(0x0000000100000000LL, 0x8000000800000000LL), 31))
70 return 1;
71 if (test__clzti2(make_ti(0x1000000100000000LL, 0x8000000800000000LL), 3))
72 return 1;
73 if (test__clzti2(make_ti(0x7000000100000000LL, 0x8000000800000000LL), 1))
74 return 1;
75 if (test__clzti2(make_ti(0x8000000100000000LL, 0x8000000800000000LL), 0))
76 return 1;
77 #else
78 printf("skipped\n");
79 #endif
80 return 0;