Commit 765d98c7 by Richard Henderson Committed by Richard Henderson

toplev.c (floor_log2): Rename from floor_log2_wide, use CLZ_HWI.

        * toplev.c (floor_log2): Rename from floor_log2_wide, use CLZ_HWI.
        (exact_log2): Rename from exact_log2_wide, use CTZ_HWI.
        * toplev.h (FL2T__): Remove.
        (CLZ_HWI): Rename from FL2T_CLZ__.
        (CTZ_HWI): New.
        (floor_log2): Simplify.
        (exact_log2): New.

From-SVN: r90519
parent c9dd2023
2004-11-12 Richard Henderson <rth@redhat.com>
* toplev.c (floor_log2): Rename from floor_log2_wide, use CLZ_HWI.
(exact_log2): Rename from exact_log2_wide, use CTZ_HWI.
* toplev.h (FL2T__): Remove.
(CLZ_HWI): Rename from FL2T_CLZ__.
(CTZ_HWI): New.
(floor_log2): Simplify.
(exact_log2): New.
2004-11-12 Sebastian Pop <pop@cri.ensmp.fr> 2004-11-12 Sebastian Pop <pop@cri.ensmp.fr>
* tree-data-ref.c (analyze_subscript_affine_affine): Correctly * tree-data-ref.c (analyze_subscript_affine_affine): Correctly
......
...@@ -537,20 +537,23 @@ read_integral_parameter (const char *p, const char *pname, const int defval) ...@@ -537,20 +537,23 @@ read_integral_parameter (const char *p, const char *pname, const int defval)
} }
/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X. /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
If X is 0, return -1. If X is 0, return -1. */
This should be used via the floor_log2 macro. */
int int
floor_log2_wide (unsigned HOST_WIDE_INT x) floor_log2 (unsigned HOST_WIDE_INT x)
{ {
int t=0; int t = 0;
if (x == 0) if (x == 0)
return -1; return -1;
if (sizeof (HOST_WIDE_INT) * 8 > 64)
#ifdef CLZ_HWI
t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
#else
if (HOST_BITS_PER_WIDE_INT > 64)
if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64)) if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
t += 64; t += 64;
if (sizeof (HOST_WIDE_INT) * 8 > 32) if (HOST_BITS_PER_WIDE_INT > 32)
if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32)) if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
t += 32; t += 32;
if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16)) if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
...@@ -563,21 +566,24 @@ floor_log2_wide (unsigned HOST_WIDE_INT x) ...@@ -563,21 +566,24 @@ floor_log2_wide (unsigned HOST_WIDE_INT x)
t += 2; t += 2;
if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1)) if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
t += 1; t += 1;
#endif
return t; return t;
} }
/* Return the logarithm of X, base 2, considering X unsigned, /* Return the logarithm of X, base 2, considering X unsigned,
if X is a power of 2. Otherwise, returns -1. if X is a power of 2. Otherwise, returns -1. */
This should be used via the `exact_log2' macro. */
int int
exact_log2_wide (unsigned HOST_WIDE_INT x) exact_log2 (unsigned HOST_WIDE_INT x)
{ {
/* Test for 0 or a power of 2. */ if (x != (x & -x))
if (x == 0 || x != (x & -x))
return -1; return -1;
return floor_log2_wide (x); #ifdef CTZ_HWI
return x ? CTZ_HWI (x) : -1;
#else
return floor_log2 (x);
#endif
} }
/* Handler for fatal signals, such as SIGSEGV. These are transformed /* Handler for fatal signals, such as SIGSEGV. These are transformed
......
...@@ -158,38 +158,37 @@ extern void decode_d_option (const char *); ...@@ -158,38 +158,37 @@ extern void decode_d_option (const char *);
/* Return true iff flags are set as if -ffast-math. */ /* Return true iff flags are set as if -ffast-math. */
extern bool fast_math_flags_set_p (void); extern bool fast_math_flags_set_p (void);
/* The following functions accept a wide integer argument. Rather /* Return log2, or -1 if not exact. */
than having to cast on every function call, we use a macro instead. */ extern int exact_log2 (unsigned HOST_WIDE_INT);
#ifndef exact_log2 /* Return floor of log2, with -1 for zero. */
#define exact_log2(N) exact_log2_wide ((unsigned HOST_WIDE_INT) (N)) extern int floor_log2 (unsigned HOST_WIDE_INT);
#if (__GNUC__ * 1000 + __GNUC_MINOR__) >= 3004 /* Inline versions of the above for speed. */
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG #if GCC_VERSION >= 3004
#define FL2T__ HOST_WIDE_INT # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
#define FL2T_CLZ__ __builtin_clzll # define CLZ_HWI __builtin_clzl
#else # define CTZ_HWI __builtin_ctzl
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG # elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
#define FL2T__ HOST_WIDE_INT # define CLZ_HWI __builtin_clzll
#define FL2T_CLZ__ __builtin_clzl # define CTZ_HWI __builtin_ctzll
#else # else
#define FL2T__ int # define CLZ_HWI __builtin_clz
#define FL2T_CLZ__ __builtin_clz # define CTZ_HWI __builtin_ctz
#endif # endif
#endif
static inline int floor_log2(FL2T__ n) extern inline int
floor_log2 (unsigned HOST_WIDE_INT x)
{ {
if (n) return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
return (sizeof(FL2T__)*8-1) - (int)FL2T_CLZ__(n);
return -1;
} }
#else
#define floor_log2(N) floor_log2_wide ((unsigned HOST_WIDE_INT) (N))
#endif
#endif extern inline int
extern int exact_log2_wide (unsigned HOST_WIDE_INT); exact_log2 (unsigned HOST_WIDE_INT x)
extern int floor_log2_wide (unsigned HOST_WIDE_INT); {
return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
}
#endif /* GCC_VERSION >= 3004 */
/* Functions used to get and set GCC's notion of in what directory /* Functions used to get and set GCC's notion of in what directory
compilation was started. */ compilation was started. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment