Weiming Zhao | 9b7bbec | 2017-03-21 05:32:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 2 | //===-- clzti2_test.c - Test __clzti2 -------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
Howard Hinnant | 5b791f6 | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
| 11 | // This file tests __clzti2 for the compiler_rt library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | #include "int_lib.h" |
| 16 | #include <stdio.h> |
| 17 | |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 18 | #ifdef CRT_HAS_128BIT |
| 19 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 20 | // Returns: the number of leading 0-bits |
| 21 | |
| 22 | // Precondition: a != 0 |
| 23 | |
Derek Schuff | eb0ebc3 | 2015-04-24 15:45:57 +0000 | [diff] [blame] | 24 | COMPILER_RT_ABI si_int __clzti2(ti_int a); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 25 | |
| 26 | int test__clzti2(ti_int a, si_int expected) |
| 27 | { |
| 28 | si_int x = __clzti2(a); |
| 29 | if (x != expected) |
| 30 | { |
| 31 | twords at; |
| 32 | at.all = a; |
| 33 | printf("error in __clzti2(0x%llX%.16llX) = %d, expected %d\n", |
Daniel Dunbar | 6485720 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 34 | at.s.high, at.s.low, x, expected); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 35 | } |
| 36 | return x != expected; |
| 37 | } |
| 38 | |
| 39 | char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; |
| 40 | |
| 41 | #endif |
| 42 | |
| 43 | int main() |
| 44 | { |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 45 | #ifdef CRT_HAS_128BIT |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 46 | const int N = (int)(sizeof(ti_int) * CHAR_BIT); |
| 47 | |
| 48 | if (test__clzti2(0x00000001, N-1)) |
| 49 | return 1; |
| 50 | if (test__clzti2(0x00000002, N-2)) |
| 51 | return 1; |
| 52 | if (test__clzti2(0x00000003, N-2)) |
| 53 | return 1; |
| 54 | if (test__clzti2(0x00000004, N-3)) |
| 55 | return 1; |
| 56 | if (test__clzti2(0x00000005, N-3)) |
| 57 | return 1; |
| 58 | if (test__clzti2(0x0000000A, N-4)) |
| 59 | return 1; |
| 60 | if (test__clzti2(0x1000000A, N*3/4+3)) |
| 61 | return 1; |
| 62 | if (test__clzti2(0x2000000A, N*3/4+2)) |
| 63 | return 1; |
| 64 | if (test__clzti2(0x6000000A, N*3/4+1)) |
| 65 | return 1; |
| 66 | if (test__clzti2(0x8000000AuLL, N*3/4)) |
| 67 | return 1; |
| 68 | if (test__clzti2(0x000005008000000AuLL, 85)) |
| 69 | return 1; |
| 70 | if (test__clzti2(0x020005008000000AuLL, 70)) |
| 71 | return 1; |
| 72 | if (test__clzti2(0x720005008000000AuLL, 65)) |
| 73 | return 1; |
| 74 | if (test__clzti2(0x820005008000000AuLL, 64)) |
| 75 | return 1; |
| 76 | |
| 77 | if (test__clzti2(make_ti(0x0000000080000000LL, 0x8000000800000000LL), 32)) |
| 78 | return 1; |
| 79 | if (test__clzti2(make_ti(0x0000000100000000LL, 0x8000000800000000LL), 31)) |
| 80 | return 1; |
| 81 | if (test__clzti2(make_ti(0x1000000100000000LL, 0x8000000800000000LL), 3)) |
| 82 | return 1; |
| 83 | if (test__clzti2(make_ti(0x7000000100000000LL, 0x8000000800000000LL), 1)) |
| 84 | return 1; |
| 85 | if (test__clzti2(make_ti(0x8000000100000000LL, 0x8000000800000000LL), 0)) |
| 86 | return 1; |
Joerg Sonnenberger | d9bcddd | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 87 | #else |
| 88 | printf("skipped\n"); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 89 | #endif |
| 90 | return 0; |
| 91 | } |