blob: 194c2cbb4a707a7f418a4890723690d4c3348b1d [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- ffsti2.c - Implement __ffsti2 -------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements __ffsti2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if __x86_64
15
16#include "int_lib.h"
17
18// Returns: the index of the least significant 1-bit in a, or
19// the value zero if a is zero. The least significant bit is index one.
20
21si_int
22__ffsti2(ti_int a)
23{
24 twords x;
25 x.all = a;
26 if (x.low == 0)
27 {
28 if (x.high == 0)
29 return 0;
30 return __builtin_ctzll(x.high) + (1 + sizeof(di_int) * CHAR_BIT);
31 }
32 return __builtin_ctzll(x.low) + 1;
33}
34
35#endif