1353358Sdim//===-- ffsdi2.c - Implement __ffsdi2 -------------------------------------===// 2353358Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6353358Sdim// 7353358Sdim//===----------------------------------------------------------------------===// 8353358Sdim// 9353358Sdim// This file implements __ffsdi2 for the compiler_rt library. 10353358Sdim// 11353358Sdim//===----------------------------------------------------------------------===// 12276789Sdim 13276789Sdim#include "int_lib.h" 14276789Sdim 15353358Sdim// Returns: the index of the least significant 1-bit in a, or 16353358Sdim// the value zero if a is zero. The least significant bit is index one. 17276789Sdim 18353358SdimCOMPILER_RT_ABI si_int __ffsdi2(di_int a) { 19353358Sdim dwords x; 20353358Sdim x.all = a; 21353358Sdim if (x.s.low == 0) { 22353358Sdim if (x.s.high == 0) 23353358Sdim return 0; 24353358Sdim return __builtin_ctz(x.s.high) + (1 + sizeof(si_int) * CHAR_BIT); 25353358Sdim } 26353358Sdim return __builtin_ctz(x.s.low) + 1; 27276789Sdim} 28