summaryrefslogtreecommitdiff
path: root/gcc/hwint.h
diff options
context:
space:
mode:
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-20 21:49:12 +0000
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-20 21:49:12 +0000
commitc9c81ef3c667aaa14c498a5449ec6d134b4b66ff (patch)
tree0ac440db6513ee01deb5e5dc6142769d1e5b7b2d /gcc/hwint.h
parent12cdcb9d74f55c165366ca1b1eeec013a0ce72ef (diff)
parent891196d7325e4c55d92d5ac5cfe7161c4f36c0ce (diff)
downloadgcc-fortran-dev.tar.gz
Merge from trunk (r239915 to r240230)fortran-dev
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/fortran-dev@240290 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/hwint.h')
-rw-r--r--gcc/hwint.h35
1 files changed, 34 insertions, 1 deletions
diff --git a/gcc/hwint.h b/gcc/hwint.h
index 6b4d53737a2..ea87b2158b1 100644
--- a/gcc/hwint.h
+++ b/gcc/hwint.h
@@ -134,6 +134,31 @@ typedef HOST_WIDE_INT __gcc_host_wide_int__;
#endif
/* Inline functions operating on HOST_WIDE_INT. */
+
+/* Return X with all but the lowest bit masked off. */
+
+static inline unsigned HOST_WIDE_INT
+least_bit_hwi (unsigned HOST_WIDE_INT x)
+{
+ return (x & -x);
+}
+
+/* True if X is zero or a power of two. */
+
+static inline bool
+pow2_or_zerop (unsigned HOST_WIDE_INT x)
+{
+ return least_bit_hwi (x) == x;
+}
+
+/* True if X is a power of two. */
+
+static inline bool
+pow2p_hwi (unsigned HOST_WIDE_INT x)
+{
+ return x && pow2_or_zerop (x);
+}
+
#if GCC_VERSION < 3004
extern int clz_hwi (unsigned HOST_WIDE_INT x);
@@ -222,7 +247,7 @@ ceil_log2 (unsigned HOST_WIDE_INT x)
static inline int
exact_log2 (unsigned HOST_WIDE_INT x)
{
- return x == (x & -x) && x ? ctz_hwi (x) : -1;
+ return pow2p_hwi (x) ? ctz_hwi (x) : -1;
}
#endif /* GCC_VERSION >= 3004 */
@@ -238,6 +263,14 @@ extern HOST_WIDE_INT pos_mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
extern HOST_WIDE_INT mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
extern HOST_WIDE_INT least_common_multiple (HOST_WIDE_INT, HOST_WIDE_INT);
+/* Like ctz_hwi, except 0 when x == 0. */
+
+static inline int
+ctz_or_zero (unsigned HOST_WIDE_INT x)
+{
+ return ffs_hwi (x) - 1;
+}
+
/* Sign extend SRC starting from PREC. */
static inline HOST_WIDE_INT