[cairo] [PATCH 5/8] Clean up _fbOnes()

Pavel Roskin proski at gnu.org
Sat Aug 12 22:57:56 PDT 2006


From: Pavel Roskin <proski at gnu.org>

The implementation of _FbOnes in iccolor.c would not work on 64-bit
longs correctly.  Fortunately, it's only used on integers, so make it
explicit in the declaration.

Use an inline function for the gcc builtin implementation to make sure
that it's never used with arguments of incorrect size.

There is no __INT_MIN__ in gcc 4.1.1, but it's not an issue now because
the argument is 32-bit.

Signed-off-by: Pavel Roskin <proski at gnu.org>
---

 pixman/src/iccolor.c |    4 ++--
 pixman/src/icint.h   |   12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/pixman/src/iccolor.c b/pixman/src/iccolor.c
index 716382f..51d6317 100644
--- a/pixman/src/iccolor.c
+++ b/pixman/src/iccolor.c
@@ -26,9 +26,9 @@ #include "icint.h"
 #ifdef ICINT_NEED_IC_ONES
 /* Fall back on HACKMEM 169.  */
 int
-_FbOnes (unsigned long mask)
+_FbOnes (unsigned int mask)
 {
-    register unsigned long y;
+    register int y;
 
     y = (mask >> 1) &033333333333;
     y = mask - y - ((y >>1) & 033333333333);
diff --git a/pixman/src/icint.h b/pixman/src/icint.h
index e1265eb..001d771 100644
--- a/pixman/src/icint.h
+++ b/pixman/src/icint.h
@@ -806,15 +806,15 @@ #include "icimage.h"
    in libgcc in case a target does not have one, which should be just as
    good as the static function below.  */
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
-# if __INT_MIN__ == 0x7fffffff
-#  define _FbOnes(mask)		__builtin_popcount(mask)
-# else
-#  define _FbOnes(mask)		__builtin_popcountl((mask) & 0xffffffff)
-# endif
+static INLINE int
+_FbOnes(unsigned int mask)
+{
+	return __builtin_popcount(mask);
+}
 #else
 # define ICINT_NEED_IC_ONES
 int
-_FbOnes(unsigned long mask);
+_FbOnes(unsigned int mask);
 #endif
 
 /* icformat.c */


More information about the cairo mailing list