1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_clzdi2
3
4#include "int_lib.h"
5#include <stdio.h>
6
7// Returns: the number of leading 0-bits
8
9// Precondition: a != 0
10
11COMPILER_RT_ABI int __clzdi2(di_int a);
12
13int test__clzdi2(di_int a, int expected)
14{
15 int x = __clzdi2(a);
16 if (x != expected)
17 printf("error in __clzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
18 return x != expected;
19}
20
21char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
22
23int main()
24{
25 const int N = (int)(sizeof(di_int) * CHAR_BIT);
26// if (test__clzdi2(0x00000000, N)) // undefined
27// return 1;
28 if (test__clzdi2(0x00000001, N-1))
29 return 1;
30 if (test__clzdi2(0x00000002, N-2))
31 return 1;
32 if (test__clzdi2(0x00000003, N-2))
33 return 1;
34 if (test__clzdi2(0x00000004, N-3))
35 return 1;
36 if (test__clzdi2(0x00000005, N-3))
37 return 1;
38 if (test__clzdi2(0x0000000A, N-4))
39 return 1;
40 if (test__clzdi2(0x1000000A, N/2+3))
41 return 1;
42 if (test__clzdi2(0x2000000A, N/2+2))
43 return 1;
44 if (test__clzdi2(0x6000000A, N/2+1))
45 return 1;
46 if (test__clzdi2(0x8000000AuLL, N/2))
47 return 1;
48 if (test__clzdi2(0x000005008000000AuLL, 21))
49 return 1;
50 if (test__clzdi2(0x020005008000000AuLL, 6))
51 return 1;
52 if (test__clzdi2(0x720005008000000AuLL, 1))
53 return 1;
54 if (test__clzdi2(0x820005008000000AuLL, 0))
55 return 1;
56
57 return 0;
58}
59