Use a more optimized g_bit_storage() when gcc is available. (#371670,
authorBehdad Esfahbod <behdad@gnome.org>
Tue, 9 Jan 2007 19:05:36 +0000 (19:05 +0000)
committerBehdad Esfahbod <behdad@src.gnome.org>
Tue, 9 Jan 2007 19:05:36 +0000 (19:05 +0000)
2007-01-09  Behdad Esfahbod  <behdad@gnome.org>

        * glib/gutils.h: Use a more optimized g_bit_storage() when gcc is
        available.  (#371670, Daniel Elstner)

svn path=/trunk/; revision=5234

ChangeLog
glib/gutils.h

index 070ab47..a76305b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-01-09  Behdad Esfahbod  <behdad@gnome.org>
+
+       * glib/gutils.h: Use a more optimized g_bit_storage() when gcc is
+       available.  (#371670, Daniel Elstner)
+
 2007-01-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gthread/gthread-posix.c (g_thread_impl_init): Don't
index 06845b0..03df076 100644 (file)
@@ -305,7 +305,8 @@ G_INLINE_FUNC guint
 g_bit_storage (gulong number)
 {
 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
-  return number ? GLIB_SIZEOF_LONG * 8 - __builtin_clzl(number) : 1;
+  return G_LIKELY (number) ?
+          ((GLIB_SIZEOF_LONG * 8 - 1) ^ __builtin_clzl(number)) + 1 : 1;
 #else
   register guint n_bits = 0;