@@ -16,46 +16,14 @@ using namespace hashing;
1616namespace counting_bloomfilter {
1717
1818#define bitCount64 (x ) __builtin_popcountll(x)
19- // inline int bitCount64(uint64_t x) {
20- // return __builtin_popcountll(x);
21- // }
22- /*
23- inline int bitCount64(uint64_t x) {
24- return __builtin_popcountll(x);
25- }
26- */
2719
28- /*
29- inline int select64(uint64_t k, uint64_t x) {
30- uint64_t result = uint64_t(1) << k;
31- asm("pdep %1, %0, %0\n\t"
32- "tzcnt %0, %0"
33- : "+r"(result)
34- : "r"(x));
35- return result;
36- }
37- */
38- // #if defined(__BMI2__)
20+ #if defined(__BMI2__)
21+
3922// use a macro, to ensure it is inlined
4023#define select64 (A, B ) _tzcnt_u64(_pdep_u64(1ULL << (B), (A)))
41- /*
24+
4225#else
43- inline int select64(uint64_t x, int n) {
44- // with this, "add" is around 310 ns/key at 10000000 keys
45- // from http://bitmagic.io/rank-select.html
46- // https://github.com/Forceflow/libmorton/issues/6
47- // This is a rather unusual usage of the pdep (bit deposit) operation,
48- // as we use the x as the mask, and we use n as the value.
49- // We deposit (move) the bits of 1 << n to the locations
50- // defined by x.
51- uint64_t d = _pdep_u64(1ULL << n, x);
52- // and now we count the trailing zeroes, to find out
53- // where the '1' was deposited
54- return __builtin_ctzl(d);
55- // return _tzcnt_u64(d);
56- }
57- */
58- // #else
26+
5927/*
6028inline int select64(uint64_t x, int n) {
6129 // alternative implementation
@@ -71,9 +39,15 @@ inline int select64(uint64_t x, int n) {
7139 return -1;
7240}
7341*/
74- // #endif
7542
7643/*
44+
45+ From https://github.com/splatlab/Sux
46+ https://github.com/splatlab/Sux/blob/master/testselect64.cpp
47+
48+ */
49+
50+
7751#define ONES_STEP_4 0x1111111111111111ULL
7852#define ONES_STEP_8 0x0101010101010101ULL
7953#define MSBS_STEP_8 (0x80L * ONES_STEP_8)
@@ -204,7 +178,8 @@ inline int select64(uint64_t x, int n) {
204178 return byteOffset +
205179 SELECT_IN_BYTE[(int ) ((x >> byteOffset) & 0xFF ) | byteRank << 8 ];
206180}
207- */
181+
182+ #endif
208183
209184inline int numberOfLeadingZeros64 (uint64_t x) {
210185 // If x is 0, the result is undefined.
0 commit comments