diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-10-05 17:30:03 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-10-05 17:30:47 -0400 |
commit | bc9233d278f917060a4df2a5a564090c1ab4d5c7 (patch) | |
tree | db0e45e67449851a7f2b13611cfcbcbe05c2ed70 /lisc | |
parent | e30fab31e1935dc5a4154a0dab9cc61c8708953c (diff) | |
download | roux-bc9233d278f917060a4df2a5a564090c1ab4d5c7.tar.gz |
implement popcnt with a simple loop
Diffstat (limited to 'lisc')
-rw-r--r-- | lisc/util.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/lisc/util.c b/lisc/util.c index 81857b0..8a5cfc4 100644 --- a/lisc/util.c +++ b/lisc/util.c @@ -53,27 +53,16 @@ emiti(Ins i) int bcnt(Bits *b) { - const uint64_t m1 = 0x5555555555555555; - const uint64_t m2 = 0x3333333333333333; - const uint64_t m3 = 0x0f0f0f0f0f0f0f0f; - const uint64_t m4 = 0x00ff00ff00ff00ff; - const uint64_t m5 = 0x0000ffff0000ffff; - const uint64_t m6 = 0x00000000ffffffff; - uint64_t tmp; - int z, i; + int z, i, j; + ulong tmp; i = 0; for (z=0; z<BITS; z++) { tmp = b->t[z]; - if (!tmp) - continue; - tmp = (tmp&m1) + (tmp>> 1&m1); - tmp = (tmp&m2) + (tmp>> 2&m2); - tmp = (tmp&m3) + (tmp>> 4&m3); - tmp = (tmp&m4) + (tmp>> 8&m4); - tmp = (tmp&m5) + (tmp>>16&m5); - tmp = (tmp&m6) + (tmp>>32&m6); - i += tmp; + for (j=0; j<64; j++) { + i += 1 & tmp; + tmp >>= 1; + } } return i; } |