1//===-- ffsdi2_test.c - Test __ffsdi2 -------------------------------------===// 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 __ffsdi2 for the compiler_rt library. 11// 12//===----------------------------------------------------------------------===// 13 14#include "int_lib.h" 15#include <stdio.h> 16 17// Returns: the index of the least significant 1-bit in a, or 18// the value zero if a is zero. The least significant bit is index one. 19 20COMPILER_RT_ABI si_int __ffsdi2(di_int a); 21 22int test__ffsdi2(di_int a, si_int expected) 23{ 24 si_int x = __ffsdi2(a); 25 if (x != expected) 26 printf("error in __ffsdi2(0x%llX) = %d, expected %d\n", a, x, expected); 27 return x != expected; 28} 29 30char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; 31 32int main() 33{ 34 if (test__ffsdi2(0x00000000, 0)) 35 return 1; 36 if (test__ffsdi2(0x00000001, 1)) 37 return 1; 38 if (test__ffsdi2(0x00000002, 2)) 39 return 1; 40 if (test__ffsdi2(0x00000003, 1)) 41 return 1; 42 if (test__ffsdi2(0x00000004, 3)) 43 return 1; 44 if (test__ffsdi2(0x00000005, 1)) 45 return 1; 46 if (test__ffsdi2(0x0000000A, 2)) 47 return 1; 48 if (test__ffsdi2(0x10000000, 29)) 49 return 1; 50 if (test__ffsdi2(0x20000000, 30)) 51 return 1; 52 if (test__ffsdi2(0x60000000, 30)) 53 return 1; 54 if (test__ffsdi2(0x80000000uLL, 32)) 55 return 1; 56 if (test__ffsdi2(0x0000050000000000uLL, 41)) 57 return 1; 58 if (test__ffsdi2(0x0200080000000000uLL, 44)) 59 return 1; 60 if (test__ffsdi2(0x7200000000000000uLL, 58)) 61 return 1; 62 if (test__ffsdi2(0x8000000000000000uLL, 64)) 63 return 1; 64 65 return 0; 66} 67