This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add double_int_ctz
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 3 Aug 2010 14:59:48 +0200 (CEST)
- Subject: [PATCH] Add double_int_ctz
This adds double_int_ctz as required by bit-CCP.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Richard.
2010-08-03 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.
Index: gcc/Makefile.in
===================================================================
*** gcc/Makefile.in (revision 162816)
--- gcc/Makefile.in (working copy)
*************** stringpool.o: stringpool.c $(CONFIG_H) $
*** 2279,2285 ****
convert.o: convert.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(FLAGS_H) convert.h $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) langhooks.h
! double-int.o: double-int.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H)
# lto-compress.o needs $(ZLIBINC) added to the include flags.
lto-compress.o: lto-compress.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
--- 2279,2286 ----
convert.o: convert.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(FLAGS_H) convert.h $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) langhooks.h
! double-int.o: double-int.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
! $(TOPLEV_H) $(TREE_H)
# lto-compress.o needs $(ZLIBINC) added to the include flags.
lto-compress.o: lto-compress.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
Index: gcc/double-int.h
===================================================================
*** gcc/double-int.h (revision 162816)
--- gcc/double-int.h (working copy)
*************** double_int double_int_umod (double_int,
*** 148,154 ****
--- 148,156 ----
double_int double_int_divmod (double_int, double_int, bool, unsigned, double_int *);
double_int double_int_sdivmod (double_int, double_int, unsigned, double_int *);
double_int double_int_udivmod (double_int, double_int, unsigned, double_int *);
+
double_int double_int_setbit (double_int, unsigned);
+ int double_int_ctz (double_int);
/* Logical operations. */
Index: gcc/double-int.c
===================================================================
*** gcc/double-int.c (revision 162816)
--- gcc/double-int.c (working copy)
*************** along with GCC; see the file COPYING3.
*** 22,27 ****
--- 22,28 ----
#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,
*************** double_int_setbit (double_int a, unsigne
*** 850,855 ****
--- 851,876 ----
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. */