Home | History | Annotate | Download | only in Unit
      1 //===-- clzdi2_test.c - Test __clzdi2 -------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __clzdi2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 // Returns: the number of leading 0-bits
     18 
     19 // Precondition: a != 0
     20 
     21 si_int __clzdi2(di_int a);
     22 
     23 int test__clzdi2(di_int a, si_int expected)
     24 {
     25     si_int x = __clzdi2(a);
     26     if (x != expected)
     27         printf("error in __clzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
     28     return x != expected;
     29 }
     30 
     31 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
     32 
     33 int main()
     34 {
     35     const int N = (int)(sizeof(di_int) * CHAR_BIT);
     36 //    if (test__clzdi2(0x00000000, N))  // undefined
     37 //        return 1;
     38     if (test__clzdi2(0x00000001, N-1))
     39         return 1;
     40     if (test__clzdi2(0x00000002, N-2))
     41         return 1;
     42     if (test__clzdi2(0x00000003, N-2))
     43         return 1;
     44     if (test__clzdi2(0x00000004, N-3))
     45         return 1;
     46     if (test__clzdi2(0x00000005, N-3))
     47         return 1;
     48     if (test__clzdi2(0x0000000A, N-4))
     49         return 1;
     50     if (test__clzdi2(0x1000000A, N/2+3))
     51         return 1;
     52     if (test__clzdi2(0x2000000A, N/2+2))
     53         return 1;
     54     if (test__clzdi2(0x6000000A, N/2+1))
     55         return 1;
     56     if (test__clzdi2(0x8000000AuLL, N/2))
     57         return 1;
     58     if (test__clzdi2(0x000005008000000AuLL, 21))
     59         return 1;
     60     if (test__clzdi2(0x020005008000000AuLL, 6))
     61         return 1;
     62     if (test__clzdi2(0x720005008000000AuLL, 1))
     63         return 1;
     64     if (test__clzdi2(0x820005008000000AuLL, 0))
     65         return 1;
     66 
     67    return 0;
     68 }
     69