summaryrefslogtreecommitdiff
path: root/gcc/hwint.h
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-30 16:36:19 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-30 16:36:19 +0000
commitb96c136c396a3a8cf37758ecd2ba705005542044 (patch)
treec381c35f0952d6ecccac229a039bf3585647cf4c /gcc/hwint.h
parent050190438f97763fc6ab94dd4ffb0635002a8b4c (diff)
downloadgcc-b96c136c396a3a8cf37758ecd2ba705005542044.tar.gz
* hwint.c: New. Extracted from toplev.c.
* hwint.h (clz_hwi, ctz_hwi, ffs_hwi, exact_log2, floor_log2): Move from toplev.h. * toplev.c (clz_hwi, ctz_hwi, ffs_hwi, exact_log2, floor_log2): Move to hwint.c. * toplev.h (clz_hwi, ctz_hwi, ffs_hwi, exact_log2, floor_log2): Move to hwint.h. * builtins.c, combine.c, config/i386/winnt.c, double-int.c, explow.c, expmed.c, fold-const.c, ggc-page.c, ggc-zone.c, ifcvt.c, ipa-struct-reorg.c, ira-color.c, matrix-reorg.c, omp-low.c, real.c, recog.c, reload.c, rtlanal.c, simplify-rtx.c, stor-layout.c, tree-dfa.c, tree-ssa-alias.c, tree-ssa-loop-niter.c, tree-vect-data-refs.c, tree-vect-loop-manip.c, tree-vect-loop.c, tree-vect-stmts.c, tree-vrp.c: Don't include toplev.h. * genattrtab.c, genconditions.c, genemit.c, genextract.c, genoutput.c, genpeep.c, genpreds.c, genrecog.c: Don't include toplev.h in generated output. * Makefile.in (OBJS-common): Add hwint.o. Dependencies for above files changed to remove toplev.h. (hwint.o): New. (insn-attrtab.o, insn-emit.o, insn-extract.o, insn-output.o, insn-peep.o, insn-preds.o, insn-recog.o): Don't depend on toplev.h. * config/i386/t-cygming (winnt.o): Don't depend on toplev.h. * config/i386/t-interix (winnt.o): Don't depend on toplev.h. fortran: * trans-common.c: Don't include toplev.h. java: * boehm.c: Don't include toplev.h. * Make-lang.in (java/boehm.o): Don't depend on toplev.h. lto: * lto-object.c: Don't include toplev.h. * Make-lang.in (lto/lto-object.o): Don't depend on toplev.h. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167301 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/hwint.h')
-rw-r--r--gcc/hwint.h73
1 files changed, 72 insertions, 1 deletions
diff --git a/gcc/hwint.h b/gcc/hwint.h
index c7fcd345bec..8bd7c5e7bdc 100644
--- a/gcc/hwint.h
+++ b/gcc/hwint.h
@@ -1,5 +1,6 @@
/* HOST_WIDE_INT definitions for the GNU compiler.
- Copyright (C) 1998, 2002, 2004, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2002, 2004, 2008, 2009, 2010
+ Free Software Foundation, Inc.
This file is part of GCC.
@@ -157,4 +158,74 @@ extern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1];
# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONG
#endif
+/* Inline functions operating on HOST_WIDE_INT. */
+#if GCC_VERSION < 3004
+
+extern int clz_hwi (unsigned HOST_WIDE_INT x);
+extern int ctz_hwi (unsigned HOST_WIDE_INT x);
+extern int ffs_hwi (unsigned HOST_WIDE_INT x);
+
+/* Return log2, or -1 if not exact. */
+extern int exact_log2 (unsigned HOST_WIDE_INT);
+
+/* Return floor of log2, with -1 for zero. */
+extern int floor_log2 (unsigned HOST_WIDE_INT);
+
+#else /* GCC_VERSION >= 3004 */
+
+/* For convenience, define 0 -> word_size. */
+static inline int
+clz_hwi (unsigned HOST_WIDE_INT x)
+{
+ if (x == 0)
+ return HOST_BITS_PER_WIDE_INT;
+# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
+ return __builtin_clzl (x);
+# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
+ return __builtin_clzll (x);
+# else
+ return __builtin_clz (x);
+# endif
+}
+
+static inline int
+ctz_hwi (unsigned HOST_WIDE_INT x)
+{
+ if (x == 0)
+ return HOST_BITS_PER_WIDE_INT;
+# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
+ return __builtin_ctzl (x);
+# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
+ return __builtin_ctzll (x);
+# else
+ return __builtin_ctz (x);
+# endif
+}
+
+static inline int
+ffs_hwi (unsigned HOST_WIDE_INT x)
+{
+# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
+ return __builtin_ffsl (x);
+# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
+ return __builtin_ffsll (x);
+# else
+ return __builtin_ffs (x);
+# endif
+}
+
+static inline int
+floor_log2 (unsigned HOST_WIDE_INT x)
+{
+ return HOST_BITS_PER_WIDE_INT - 1 - clz_hwi (x);
+}
+
+static inline int
+exact_log2 (unsigned HOST_WIDE_INT x)
+{
+ return x == (x & -x) && x ? ctz_hwi (x) : -1;
+}
+
+#endif /* GCC_VERSION >= 3004 */
+
#endif /* ! GCC_HWINT_H */