aboutsummaryrefslogtreecommitdiff
path: root/gcc/toplev.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r--gcc/toplev.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 2741be5..e180394 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1248,36 +1248,48 @@ read_integral_parameter (const char *p, const char *pname, const int defval)
return atoi (p);
}
-/* Return the logarithm of X, base 2, considering X unsigned,
- if X is a power of 2. Otherwise, returns -1.
+/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
+ If X is 0, return -1.
- This should be used via the `exact_log2' macro. */
+ This should be used via the floor_log2 macro. */
int
-exact_log2_wide (unsigned HOST_WIDE_INT x)
+floor_log2_wide (unsigned HOST_WIDE_INT x)
{
- int log = 0;
- /* Test for 0 or a power of 2. */
- if (x == 0 || x != (x & -x))
+ int t=0;
+ if (x == 0)
return -1;
- while ((x >>= 1) != 0)
- log++;
- return log;
+ if (sizeof (HOST_WIDE_INT)*8 > 64)
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+64)))
+ t += 64;
+ if (sizeof (HOST_WIDE_INT)*8 > 32)
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+32)))
+ t += 32;
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+16)))
+ t += 16;
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+8)))
+ t += 8;
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+4)))
+ t += 4;
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+2)))
+ t += 2;
+ if (x >= (unsigned HOST_WIDE_INT)(1 << (t+1)))
+ t += 1;
+ return t;
}
-/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
- If X is 0, return -1.
+/* Return the logarithm of X, base 2, considering X unsigned,
+ if X is a power of 2. Otherwise, returns -1.
- This should be used via the floor_log2 macro. */
+ This should be used via the `exact_log2' macro. */
int
-floor_log2_wide (unsigned HOST_WIDE_INT x)
+exact_log2_wide (unsigned HOST_WIDE_INT x)
{
- int log = -1;
- while (x != 0)
- log++,
- x >>= 1;
- return log;
+ /* Test for 0 or a power of 2. */
+ if (x == 0 || x != (x & -x))
+ return -1;
+ return floor_log2_wide (x);
}
/* Handler for fatal signals, such as SIGSEGV. These are transformed