From 6b6fd9bac83aeb089ae4f95d962e04595699cb81 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 9 Jan 2007 19:05:36 +0000 Subject: [PATCH] Use a more optimized g_bit_storage() when gcc is available. (#371670, 2007-01-09 Behdad Esfahbod * glib/gutils.h: Use a more optimized g_bit_storage() when gcc is available. (#371670, Daniel Elstner) svn path=/trunk/; revision=5234 --- ChangeLog | 5 +++++ glib/gutils.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 070ab47..a76305b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-01-09 Behdad Esfahbod + + * glib/gutils.h: Use a more optimized g_bit_storage() when gcc is + available. (#371670, Daniel Elstner) + 2007-01-08 Matthias Clasen * gthread/gthread-posix.c (g_thread_impl_init): Don't diff --git a/glib/gutils.h b/glib/gutils.h index 06845b0..03df076 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -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; -- 2.7.4