10b57cec5SDimitry Andric //===-- ffsdi2.c - Implement __ffsdi2 -------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file implements __ffsdi2 for the compiler_rt library. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #include "int_lib.h" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric // Returns: the index of the least significant 1-bit in a, or 160b57cec5SDimitry Andric // the value zero if a is zero. The least significant bit is index one. 170b57cec5SDimitry Andric __ffsdi2(di_int a)18*5ffd83dbSDimitry AndricCOMPILER_RT_ABI int __ffsdi2(di_int a) { 190b57cec5SDimitry Andric dwords x; 200b57cec5SDimitry Andric x.all = a; 210b57cec5SDimitry Andric if (x.s.low == 0) { 220b57cec5SDimitry Andric if (x.s.high == 0) 230b57cec5SDimitry Andric return 0; 24*5ffd83dbSDimitry Andric return ctzsi(x.s.high) + (1 + sizeof(si_int) * CHAR_BIT); 250b57cec5SDimitry Andric } 26*5ffd83dbSDimitry Andric return ctzsi(x.s.low) + 1; 270b57cec5SDimitry Andric } 28