1214152Sed/* ===-- ffsti2.c - Implement __ffsti2 -------------------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open 6222656Sed * Source Licenses. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __ffsti2 for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 14214152Sed 15214152Sed#include "int_lib.h" 16214152Sed 17214152Sed#ifdef CRT_HAS_128BIT 18214152Sed 19222656Sed/* Returns: the index of the least significant 1-bit in a, or 20222656Sed * the value zero if a is zero. The least significant bit is index one. 21239138Sandrew */ 22222656Sed 23214152Sedsi_int 24214152Sed__ffsti2(ti_int a) 25214152Sed{ 26214152Sed twords x; 27214152Sed x.all = a; 28214152Sed if (x.s.low == 0) 29214152Sed { 30214152Sed if (x.s.high == 0) 31214152Sed return 0; 32214152Sed return __builtin_ctzll(x.s.high) + (1 + sizeof(di_int) * CHAR_BIT); 33214152Sed } 34214152Sed return __builtin_ctzll(x.s.low) + 1; 35214152Sed} 36214152Sed 37214152Sed#endif /* CRT_HAS_128BIT */ 38214152Sed