summaryrefslogtreecommitdiff
path: root/gcc/hwint.h
diff options
context:
space:
mode:
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