[Cairo] Use __builtin_popcount when available
Richard Henderson
rth at twiddle.net
Thu Jul 31 16:40:24 PDT 2003
Ok?
r~
* iccolor.c (Ones): Define as __builtin_popcount when available.
Index: iccolor.c
===================================================================
RCS file: /local/src/CVS/libic/src/iccolor.c,v
retrieving revision 1.2
diff -c -p -d -r1.2 iccolor.c
*** iccolor.c 31 Jul 2003 17:00:09 -0000 1.2
--- iccolor.c 31 Jul 2003 17:31:16 -0000
***************
*** 25,35 ****
#include "icint.h"
static int
! Ones(unsigned long mask);
!
! static int
! Ones(unsigned long mask) /* HACKMEM 169 */
{
register unsigned long y;
--- 25,44 ----
#include "icint.h"
+ /* GCC 3.4 supports a "population count" builtin, which on many targets is
+ implemented with a single instruction. There is a fallback definition
+ 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 Ones(mask) __builtin_popcount(mask)
+ # else
+ # define Ones(mask) __builtin_popcountl((mask) & 0xffffffff)
+ # endif
+ #else
+ /* Otherwise fall back on HACKMEM 169. */
static int
! Ones(unsigned long mask)
{
register unsigned long y;
*************** Ones(unsigned long mask)
*** 37,42 ****
--- 46,52 ----
y = mask - y - ((y >>1) & 033333333333);
return (((y + (y >> 3)) & 030707070707) % 077);
}
+ #endif
void
IcColorToPixel (const IcFormat *format,
More information about the cairo
mailing list