diff options
Diffstat (limited to 'lib/ctzdi2.c')
-rw-r--r-- | lib/ctzdi2.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/ctzdi2.c b/lib/ctzdi2.c new file mode 100644 index 000000000..8ea3ab319 --- /dev/null +++ b/lib/ctzdi2.c @@ -0,0 +1,28 @@ +//===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements __ctzdi2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" + +// Returns: the number of trailing 0-bits + +// Precondition: a != 0 + +si_int +__ctzdi2(di_int a) +{ + dwords x; + x.all = a; + const si_int f = -(x.low == 0); + return __builtin_ctz((x.high & f) | (x.low & ~f)) + + (f & ((si_int)(sizeof(si_int) * CHAR_BIT))); +} |