summaryrefslogtreecommitdiff
path: root/gcc/hwint.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/hwint.c')
-rw-r--r--gcc/hwint.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/gcc/hwint.c b/gcc/hwint.c
index 533133c7b4d..bfc5e3dedcd 100644
--- a/gcc/hwint.c
+++ b/gcc/hwint.c
@@ -25,10 +25,11 @@ along with GCC; see the file COPYING3. If not see
#if GCC_VERSION < 3004
-/* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
- are defined as inline functions in hwint.h if GCC_VERSION >= 3004.
- The definitions here are used for older versions of GCC and non-GCC
- bootstrap compilers. */
+/* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2, ceil_log2,
+ and exact_log2 are defined as inline functions in hwint.h
+ if GCC_VERSION >= 3004.
+ The definitions here are used for older versions of GCC and
+ non-GCC bootstrap compilers. */
/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
If X is 0, return -1. */
@@ -61,6 +62,14 @@ floor_log2 (unsigned HOST_WIDE_INT x)
return t;
}
+/* Given X, an unsigned number, return the largest Y such that 2**Y >= X. */
+
+int
+ceil_log2 (unsigned HOST_WIDE_INT x)
+{
+ return floor_log2 (x - 1) + 1;
+}
+
/* Return the logarithm of X, base 2, considering X unsigned,
if X is a power of 2. Otherwise, returns -1. */