diff options
author | Peter Johnson <peter@tortall.net> | 2004-09-25 06:38:57 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2004-09-25 06:38:57 +0000 |
commit | eafa10819179860fbce2283ba2dd9bde3f25cd1e (patch) | |
tree | b0dad8487c853f5f10dee705cffbde3bde9f6499 /util.h | |
parent | ad2c7b3e3fc570be20a8c29dd2f464e587324e36 (diff) | |
download | yasm-eafa10819179860fbce2283ba2dd9bde3f25cd1e.tar.gz |
* util.h (BitCount): Change bit-counting algorithm; the old one miscounted
4096 (0x1000) as having 257 bits; almost certainly other values were broken
as well.
svn path=/trunk/yasm/; revision=1148
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -137,16 +137,15 @@ #endif /* Bit-counting: used primarily by HAMT but also in a few other places. */ -#define SK5 0x55555555 -#define SK3 0x33333333 -#define SKF0 0x0F0F0F0F +#define BC_TWO(c) (0x1ul << (c)) +#define BC_MSK(c) (((unsigned long)(-1)) / (BC_TWO(BC_TWO(c)) + 1ul)) +#define BC_COUNT(x,c) ((x) & BC_MSK(c)) + (((x) >> (BC_TWO(c))) & BC_MSK(c)) #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; \ + d = BC_COUNT(s, 0); \ + d = BC_COUNT(d, 1); \ + d = BC_COUNT(d, 2); \ + d = BC_COUNT(d, 3); \ + d = BC_COUNT(d, 4); \ } while (0) #ifndef NELEMS |