diff options
Diffstat (limited to 'gcc/double-int.c')
-rw-r--r-- | gcc/double-int.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/double-int.c b/gcc/double-int.c index 924e91b6c90..29e720b2919 100644 --- a/gcc/double-int.c +++ b/gcc/double-int.c @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "tm.h" #include "tree.h" +#include "toplev.h" /* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring overflow. Suppose A, B and SUM have the same respective signs as A1, B1, @@ -850,6 +851,26 @@ double_int_setbit (double_int a, unsigned bitpos) return a; } +/* Count trailing zeros in A. */ +int +double_int_ctz (double_int a) +{ + unsigned HOST_WIDE_INT w = a.low ? a.low : (unsigned HOST_WIDE_INT) a.high; + unsigned bits = a.low ? 0 : HOST_BITS_PER_WIDE_INT; + if (!w) + return HOST_BITS_PER_DOUBLE_INT; +#if (GCC_VERSION >= 3004) + bits += CTZ_HWI (w); +#else + while (!(w & 1)) + { + w >>= 1; + bits += 1; + } +#endif + return bits; +} + /* Shift A left by COUNT places keeping only PREC bits of result. Shift right if COUNT is negative. ARITH true specifies arithmetic shifting; otherwise use logical shift. */ |