summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2002-03-10 20:21:50 +0000
committerPeter Johnson <peter@tortall.net>2002-03-10 20:21:50 +0000
commitba2c819e71175114e6d9055bdb6e4363ebeb560a (patch)
tree305b68c428abf3072cdb0cc852dd09bf8b307e43 /util.h
parent96db2a27b2932a442443f740b9c05566083f9fcc (diff)
downloadyasm-ba2c819e71175114e6d9055bdb6e4363ebeb560a.tar.gz
Move BitCount() macro from hamt.c to util.h.
svn path=/trunk/yasm/; revision=488
Diffstat (limited to 'util.h')
-rw-r--r--util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/util.h b/util.h
index abd7f539..2dbd480f 100644
--- a/util.h
+++ b/util.h
@@ -135,6 +135,19 @@ int strncasecmp(const char *s1, const char *s2, size_t n);
void xfree(/*@only@*/ /*@out@*/ /*@null@*/ void *p);
#endif
+/* Bit-counting: used primarily by HAMT but also in a few other places. */
+#define SK5 0x55555555
+#define SK3 0x33333333
+#define SKF0 0x0F0F0F0F
+#define BitCount(d, s) do { \
+ d = s; \
+ d -= (d>>1) & SK5; \
+ d = (d & SK3) + ((d>>2) & SK3); \
+ d = (d & SKF0) + ((d>>4) & SKF0); \
+ d += d>>16; \
+ d += d>>8; \
+ } while (0)
+
#include "coretype.h"
#include "valparam.h"