Home | History | Annotate | Download | only in Unit
      1 //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __ffsti2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 #ifdef CRT_HAS_128BIT
     18 
     19 // Returns: the index of the least significant 1-bit in a, or
     20 // the value zero if a is zero. The least significant bit is index one.
     21 
     22 si_int __ffsti2(ti_int a);
     23 
     24 int test__ffsti2(ti_int a, si_int expected)
     25 {
     26     si_int x = __ffsti2(a);
     27     if (x != expected)
     28     {
     29         twords at;
     30         at.all = a;
     31         printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
     32                at.s.high, at.s.low, x, expected);
     33     }
     34     return x != expected;
     35 }
     36 
     37 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
     38 
     39 #endif
     40 
     41 int main()
     42 {
     43 #ifdef CRT_HAS_128BIT
     44     if (test__ffsti2(0x00000000, 0))
     45         return 1;
     46     if (test__ffsti2(0x00000001, 1))
     47         return 1;
     48     if (test__ffsti2(0x00000002, 2))
     49         return 1;
     50     if (test__ffsti2(0x00000003, 1))
     51         return 1;
     52     if (test__ffsti2(0x00000004, 3))
     53         return 1;
     54     if (test__ffsti2(0x00000005, 1))
     55         return 1;
     56     if (test__ffsti2(0x0000000A, 2))
     57         return 1;
     58     if (test__ffsti2(0x10000000, 29))
     59         return 1;
     60     if (test__ffsti2(0x20000000, 30))
     61         return 1;
     62     if (test__ffsti2(0x60000000, 30))
     63         return 1;
     64     if (test__ffsti2(0x80000000uLL, 32))
     65         return 1;
     66     if (test__ffsti2(0x0000050000000000uLL, 41))
     67         return 1;
     68     if (test__ffsti2(0x0200080000000000uLL, 44))
     69         return 1;
     70     if (test__ffsti2(0x7200000000000000uLL, 58))
     71         return 1;
     72     if (test__ffsti2(0x8000000000000000uLL, 64))
     73         return 1;
     74     if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
     75         return 1;
     76     if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
     77         return 1;
     78 
     79 #else
     80     printf("skipped\n");
     81 #endif
     82    return 0;
     83 }
     84