| 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 | |
| 11 | COMPILER_RT_ABI int __clzdi2(di_int a); |
| 12 | |
| 13 | int test__clzdi2(di_int a, int expected) |
| 14 | { |
| 15 | int x = __clzdi2(a); |
| 16 | if (x != expected) |
| 17 | printf(format: "error in __clzdi2(0x%llX) = %d, expected %d\n" , a, x, expected); |
| 18 | return x != expected; |
| 19 | } |
| 20 | |
| 21 | char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; |
| 22 | |
| 23 | int 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(a: 0x00000001, expected: N-1)) |
| 29 | return 1; |
| 30 | if (test__clzdi2(a: 0x00000002, expected: N-2)) |
| 31 | return 1; |
| 32 | if (test__clzdi2(a: 0x00000003, expected: N-2)) |
| 33 | return 1; |
| 34 | if (test__clzdi2(a: 0x00000004, expected: N-3)) |
| 35 | return 1; |
| 36 | if (test__clzdi2(a: 0x00000005, expected: N-3)) |
| 37 | return 1; |
| 38 | if (test__clzdi2(a: 0x0000000A, expected: N-4)) |
| 39 | return 1; |
| 40 | if (test__clzdi2(a: 0x1000000A, expected: N/2+3)) |
| 41 | return 1; |
| 42 | if (test__clzdi2(a: 0x2000000A, expected: N/2+2)) |
| 43 | return 1; |
| 44 | if (test__clzdi2(a: 0x6000000A, expected: N/2+1)) |
| 45 | return 1; |
| 46 | if (test__clzdi2(a: 0x8000000AuLL, expected: N/2)) |
| 47 | return 1; |
| 48 | if (test__clzdi2(a: 0x000005008000000AuLL, expected: 21)) |
| 49 | return 1; |
| 50 | if (test__clzdi2(a: 0x020005008000000AuLL, expected: 6)) |
| 51 | return 1; |
| 52 | if (test__clzdi2(a: 0x720005008000000AuLL, expected: 1)) |
| 53 | return 1; |
| 54 | if (test__clzdi2(a: 0x820005008000000AuLL, expected: 0)) |
| 55 | return 1; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |