Weiming Zhao | 9b7bbec | 2017-03-21 05:32:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
Dan Liew | 5be7eb3 | 2019-10-17 18:12:49 +0000 | [diff] [blame] | 2 | // REQUIRES: librt_has_clzti2 |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 3 | // REQUIRES: int128 |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 4 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 5 | #include "int_lib.h" |
| 6 | #include <stdio.h> |
| 7 | |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 8 | #ifdef CRT_HAS_128BIT |
| 9 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 10 | // Returns: the number of leading 0-bits |
| 11 | |
| 12 | // Precondition: a != 0 |
| 13 | |
Anatoly Trosinenko | 0ee439b | 2020-06-30 11:06:52 +0300 | [diff] [blame] | 14 | COMPILER_RT_ABI int __clzti2(ti_int a); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | |
Anatoly Trosinenko | 0ee439b | 2020-06-30 11:06:52 +0300 | [diff] [blame] | 16 | int test__clzti2(ti_int a, int expected) |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 17 | { |
Anatoly Trosinenko | 0ee439b | 2020-06-30 11:06:52 +0300 | [diff] [blame] | 18 | int x = __clzti2(a); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 19 | if (x != expected) |
| 20 | { |
| 21 | twords at; |
| 22 | at.all = a; |
| 23 | printf("error in __clzti2(0x%llX%.16llX) = %d, expected %d\n", |
Daniel Dunbar | 6485720 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 24 | at.s.high, at.s.low, x, expected); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 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 | { |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 35 | #ifdef CRT_HAS_128BIT |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 36 | 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; |
Joerg Sonnenberger | d9bcddd | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 77 | #else |
| 78 | printf("skipped\n"); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 79 | #endif |
| 80 | return 0; |
| 81 | } |