1 1.1 joerg //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===// 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 __ffsti2 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 index of the least significant 1-bit in a, or 20 1.1 joerg // the value zero if a is zero. The least significant bit is index one. 21 1.1 joerg 22 1.1 joerg si_int __ffsti2(ti_int a); 23 1.1 joerg 24 1.1 joerg int test__ffsti2(ti_int a, si_int expected) 25 1.1 joerg { 26 1.1 joerg si_int x = __ffsti2(a); 27 1.1 joerg if (x != expected) 28 1.1 joerg { 29 1.1 joerg twords at; 30 1.1 joerg at.all = a; 31 1.1 joerg printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n", 32 1.1 joerg at.s.high, at.s.low, x, expected); 33 1.1 joerg } 34 1.1 joerg return x != expected; 35 1.1 joerg } 36 1.1 joerg 37 1.1 joerg char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; 38 1.1 joerg 39 1.1 joerg #endif 40 1.1 joerg 41 1.1 joerg int main() 42 1.1 joerg { 43 1.1 joerg #if __x86_64 44 1.1 joerg if (test__ffsti2(0x00000000, 0)) 45 1.1 joerg return 1; 46 1.1 joerg if (test__ffsti2(0x00000001, 1)) 47 1.1 joerg return 1; 48 1.1 joerg if (test__ffsti2(0x00000002, 2)) 49 1.1 joerg return 1; 50 1.1 joerg if (test__ffsti2(0x00000003, 1)) 51 1.1 joerg return 1; 52 1.1 joerg if (test__ffsti2(0x00000004, 3)) 53 1.1 joerg return 1; 54 1.1 joerg if (test__ffsti2(0x00000005, 1)) 55 1.1 joerg return 1; 56 1.1 joerg if (test__ffsti2(0x0000000A, 2)) 57 1.1 joerg return 1; 58 1.1 joerg if (test__ffsti2(0x10000000, 29)) 59 1.1 joerg return 1; 60 1.1 joerg if (test__ffsti2(0x20000000, 30)) 61 1.1 joerg return 1; 62 1.1 joerg if (test__ffsti2(0x60000000, 30)) 63 1.1 joerg return 1; 64 1.1 joerg if (test__ffsti2(0x80000000uLL, 32)) 65 1.1 joerg return 1; 66 1.1 joerg if (test__ffsti2(0x0000050000000000uLL, 41)) 67 1.1 joerg return 1; 68 1.1 joerg if (test__ffsti2(0x0200080000000000uLL, 44)) 69 1.1 joerg return 1; 70 1.1 joerg if (test__ffsti2(0x7200000000000000uLL, 58)) 71 1.1 joerg return 1; 72 1.1 joerg if (test__ffsti2(0x8000000000000000uLL, 64)) 73 1.1 joerg return 1; 74 1.1 joerg if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100)) 75 1.1 joerg return 1; 76 1.1 joerg if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128)) 77 1.1 joerg return 1; 78 1.1 joerg 79 1.1 joerg #else 80 1.1 joerg printf("skipped\n"); 81 1.1 joerg #endif 82 1.1 joerg return 0; 83 1.1 joerg } 84