* toplev.c (floor_log2): Rename from floor_log2_wide, use CLZ_HWI.
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 Nov 2004 02:24:51 +0000 (02:24 +0000)
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 Nov 2004 02:24:51 +0000 (02:24 +0000)
        (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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@90519 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/toplev.c
gcc/toplev.h

index 3ed9d24..5a5d6d1 100644 (file)
@@ -1,3 +1,13 @@
+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>
 
        * tree-data-ref.c (analyze_subscript_affine_affine): Correctly
index afc43f8..4ce593a 100644 (file)
@@ -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.
-   If X is 0, return -1.
-
-   This should be used via the floor_log2 macro.  */
+   If X is 0, return -1.  */
 
 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)
     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))
       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))
       t += 32;
   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
@@ -563,21 +566,24 @@ floor_log2_wide (unsigned HOST_WIDE_INT x)
     t += 2;
   if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
     t += 1;
+#endif
+
   return t;
 }
 
 /* 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 `exact_log2' macro.  */
+   if X is a power of 2.  Otherwise, returns -1.  */
 
 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 == 0 || x != (x & -x))
+  if (x != (x & -x))
     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
index a212972..719cb4c 100644 (file)
@@ -158,38 +158,37 @@ extern void decode_d_option               (const char *);
 /* Return true iff flags are set as if -ffast-math.  */
 extern bool fast_math_flags_set_p      (void);
 
-/* The following functions accept a wide integer argument.  Rather
-   than having to cast on every function call, we use a macro instead.  */
-
-#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)
+/* Return log2, or -1 if not exact.  */
+extern int exact_log2                  (unsigned HOST_WIDE_INT);
+
+/* Return floor of log2, with -1 for zero.  */
+extern int floor_log2                  (unsigned HOST_WIDE_INT);
+
+/* Inline versions of the above for speed.  */
+#if GCC_VERSION >= 3004
+# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
+#  define CLZ_HWI __builtin_clzl
+#  define CTZ_HWI __builtin_ctzl
+# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
+#  define CLZ_HWI __builtin_clzll
+#  define CTZ_HWI __builtin_ctzll
+# else
+#  define CLZ_HWI __builtin_clz
+#  define CTZ_HWI __builtin_ctz
+# endif
+
+extern inline int
+floor_log2 (unsigned HOST_WIDE_INT x)
 {
-  if (n)
-    return (sizeof(FL2T__)*8-1) - (int)FL2T_CLZ__(n);
-  return -1;
+  return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -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);
+extern inline int
+exact_log2 (unsigned HOST_WIDE_INT x)
+{
+  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
    compilation was started.  */