1353358Sdim//===-- ctzti2.c - Implement __ctzti2 -------------------------------------===// 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 __ctzti2 for the compiler_rt library. 10353358Sdim// 11353358Sdim//===----------------------------------------------------------------------===// 12276789Sdim 13276789Sdim#include "int_lib.h" 14276789Sdim 15276789Sdim#ifdef CRT_HAS_128BIT 16276789Sdim 17353358Sdim// Returns: the number of trailing 0-bits 18276789Sdim 19353358Sdim// Precondition: a != 0 20276789Sdim 21353358SdimCOMPILER_RT_ABI si_int __ctzti2(ti_int a) { 22353358Sdim twords x; 23353358Sdim x.all = a; 24353358Sdim const di_int f = -(x.s.low == 0); 25353358Sdim return __builtin_ctzll((x.s.high & f) | (x.s.low & ~f)) + 26353358Sdim ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT))); 27276789Sdim} 28276789Sdim 29353358Sdim#endif // CRT_HAS_128BIT 30