[Commit] libic/src iccolor.c,1.2,1.3
Richard Henderson
commit at keithp.com
Thu Jul 31 21:46:24 PDT 2003
Committed by: rth
Update of /local/src/CVS/libic/src
In directory home.keithp.com:/tmp/cvs-serv4135/src
Modified Files:
iccolor.c
Log Message:
* src/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
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- iccolor.c 31 Jul 2003 17:00:09 -0000 1.2
+++ iccolor.c 1 Aug 2003 03:46:21 -0000 1.3
@@ -25,11 +25,20 @@
#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);
-
-static int
-Ones(unsigned long mask) /* HACKMEM 169 */
+Ones(unsigned long mask)
{
register unsigned long y;
@@ -37,6 +46,7 @@
y = mask - y - ((y >>1) & 033333333333);
return (((y + (y >> 3)) & 030707070707) % 077);
}
+#endif
void
IcColorToPixel (const IcFormat *format,
More information about the Commit
mailing list