1276789Sdim/* ===-- ffsdi2.c - Implement __ffsdi2 -------------------------------------=== 2276789Sdim * 3276789Sdim * The LLVM Compiler Infrastructure 4276789Sdim * 5276789Sdim * This file is dual licensed under the MIT and the University of Illinois Open 6276789Sdim * Source Licenses. See LICENSE.TXT for details. 7276789Sdim * 8276789Sdim * ===----------------------------------------------------------------------=== 9276789Sdim * 10276789Sdim * This file implements __ffsdi2 for the compiler_rt library. 11276789Sdim * 12276789Sdim * ===----------------------------------------------------------------------=== 13276789Sdim */ 14276789Sdim 15276789Sdim#include "int_lib.h" 16276789Sdim 17276789Sdim/* Returns: the index of the least significant 1-bit in a, or 18276789Sdim * the value zero if a is zero. The least significant bit is index one. 19276789Sdim */ 20276789Sdim 21276789SdimCOMPILER_RT_ABI si_int 22276789Sdim__ffsdi2(di_int a) 23276789Sdim{ 24276789Sdim dwords x; 25276789Sdim x.all = a; 26276789Sdim if (x.s.low == 0) 27276789Sdim { 28276789Sdim if (x.s.high == 0) 29276789Sdim return 0; 30276789Sdim return __builtin_ctz(x.s.high) + (1 + sizeof(si_int) * CHAR_BIT); 31276789Sdim } 32276789Sdim return __builtin_ctz(x.s.low) + 1; 33276789Sdim} 34