blob: 93afc6ce3b78bc79c0a508e29a470e68f80e8177 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- ffsdi2.c - Implement __ffsdi2 -------------------------------------===//
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 __ffsdi2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15
16// Returns: the index of the least significant 1-bit in a, or
17// the value zero if a is zero. The least significant bit is index one.
18
19si_int
20__ffsdi2(di_int a)
21{
22 dwords x;
23 x.all = a;
24 if (x.low == 0)
25 {
26 if (x.high == 0)
27 return 0;
28 return __builtin_ctz(x.high) + (1 + sizeof(si_int) * CHAR_BIT);
29 }
30 return __builtin_ctz(x.low) + 1;
31}