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