summaryrefslogtreecommitdiff
path: root/gcc/toplev.h
diff options
context:
space:
mode:
authordj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-08 19:24:07 +0000
committerdj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-08 19:24:07 +0000
commit2f8c398164724cd8cdc439c871cec8d3664d663e (patch)
tree887165390ca703d20364aad9a0a6ada538084ea9 /gcc/toplev.h
parent442ab8352a0a09b6da05f5079f9ee2bb2a246807 (diff)
downloadgcc-2f8c398164724cd8cdc439c871cec8d3664d663e.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82778 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/toplev.h')
-rw-r--r--gcc/toplev.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/toplev.h b/gcc/toplev.h
index aca355771fb..f12102e9f7b 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);