[cairo] [PATCH 5/8] Clean up _fbOnes()
Behdad Esfahbod
behdad at behdad.org
Sun Aug 13 01:48:59 PDT 2006
This one looks good to me, but I prefer to leave it for some more review
and let someone else commit. (Carl, hint, hint)
behdad
On Sun, 2006-08-13 at 01:57 -0400, Pavel Roskin wrote:
> 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 */
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
--
behdad
http://behdad.org/
"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
-- Dan Bern, "New American Language"
More information about the cairo
mailing list