diff options
author | DJ Delorie <dj@redhat.com> | 2004-06-08 15:24:07 -0400 |
---|---|---|
committer | DJ Delorie <dj@gcc.gnu.org> | 2004-06-08 15:24:07 -0400 |
commit | 73d10efa86de15b218ab2030a9d02d4e396afe2c (patch) | |
tree | 887165390ca703d20364aad9a0a6ada538084ea9 /gcc/toplev.h | |
parent | 3b48085e661950a1e6fdaf1997cda53ed8388064 (diff) | |
download | gcc-73d10efa86de15b218ab2030a9d02d4e396afe2c.zip gcc-73d10efa86de15b218ab2030a9d02d4e396afe2c.tar.gz gcc-73d10efa86de15b218ab2030a9d02d4e396afe2c.tar.bz2 |
toplev.c (floor_log2_wide): Replace loop with faster bit operations.
* toplev.c (floor_log2_wide): Replace loop with faster bit
operations.
(exact_log2_wide): Define in terms of the above.
* toplev.h (floor_log2): Use _builtin_clz family of builtins if
available.
From-SVN: r82778
Diffstat (limited to 'gcc/toplev.h')
-rw-r--r-- | gcc/toplev.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/toplev.h b/gcc/toplev.h index aca3557..f12102e 100644 --- a/gcc/toplev.h +++ b/gcc/toplev.h @@ -152,8 +152,31 @@ extern bool fast_math_flags_set_p (void); #ifndef exact_log2 #define exact_log2(N) exact_log2_wide ((unsigned HOST_WIDE_INT) (N)) + +#if (__GNUC__ * 1000 + __GNUC_MINOR__) >= 3004 +#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG +#define FL2T__ HOST_WIDE_INT +#define FL2T_CLZ__ __builtin_clzll +#else +#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG +#define FL2T__ HOST_WIDE_INT +#define FL2T_CLZ__ __builtin_clzl +#else +#define FL2T__ int +#define FL2T_CLZ__ __builtin_clz +#endif +#endif +static inline int floor_log2(FL2T__ n) +{ + if (n) + 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 int exact_log2_wide (unsigned HOST_WIDE_INT); extern int floor_log2_wide (unsigned HOST_WIDE_INT); |