82 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_clzti23// REQUIRES: int1284 5#include "int_lib.h"6#include <stdio.h>7 8#ifdef CRT_HAS_128BIT9 10// Returns: the number of leading 0-bits11 12// Precondition: a != 013 14COMPILER_RT_ABI int __clzti2(ti_int a);15 16int test__clzti2(ti_int a, int expected)17{18 int x = __clzti2(a);19 if (x != expected)20 {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);25 }26 return x != expected;27}28 29char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};30 31#endif32 33int main()34{35#ifdef CRT_HAS_128BIT36 const int N = (int)(sizeof(ti_int) * CHAR_BIT);37 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;66 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#else78 printf("skipped\n");79#endif80 return 0;81}82