summaryrefslogtreecommitdiff
path: root/gcc/double-int.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2010-08-04 09:15:51 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2010-08-04 09:15:51 +0000
commitd41e3320812c9a849b32c60aa7c7b4f4de62995f (patch)
tree048c888ac173b7ff5e353331c625f86b580387ee /gcc/double-int.c
parent0be9eeeeffec9dcc76041dd8d019e9782e28569c (diff)
downloadgcc-d41e3320812c9a849b32c60aa7c7b4f4de62995f.tar.gz
2010-08-04 Richard Guenther <rguenther@suse.de>
* Makefile.in (double-int.o): Add $(TOPLEV_H) dependency. * double-int.h (double_int_ctz): Declare. * double-int.c (double_int_ctz): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162859 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/double-int.c')
-rw-r--r--gcc/double-int.c21
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. */