Skip to content

Commit 2794c29

Browse files
committed
Enabled and slightly improved Branchless Bloom
1 parent 2042042 commit 2794c29

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

benchmarks/bulk-insert-and-query.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ Statistics FilterBenchmark(
593593

594594
#ifdef __linux__
595595
unified.end(results);
596-
printf("adds ");
597-
printf("cycles: %4.1f/key, instructions: (%4.1f/key, %4.1f/cycle) cache misses: %4.2f/key branch misses: %4.2f/key\n",
598-
results[0]*1.0/add_count,
599-
results[1]*1.0/add_count ,
600-
results[1]*1.0/results[0],
596+
printf("adds ");
597+
printf("cycles: %5.1f/key, instructions: (%5.1f/key, %4.2f/cycle) cache misses: %5.2f/key branch misses: %4.2f/key\n",
598+
results[0]*1.0/add_count,
599+
results[1]*1.0/add_count ,
600+
results[1]*1.0/results[0],
601601
results[2]*1.0/add_count,
602602
results[3] * 1.0/add_count);
603603
#else
@@ -628,10 +628,10 @@ Statistics FilterBenchmark(
628628
#ifdef __linux__
629629
unified.end(results);
630630
printf("%3.2f%% ",found_probability);
631-
printf("cycles: %4.1f/key, instructions: (%4.1f/key, %4.1f/cycle) cache misses: %4.2f/key branch misses: %4.1f/key\n",
632-
results[0]*1.0/to_lookup_mixed.size(),
633-
results[1]*1.0/to_lookup_mixed.size(),
634-
results[1]*1.0/results[0],
631+
printf("cycles: %5.1f/key, instructions: (%5.1f/key, %4.2f/cycle) cache misses: %5.2f/key branch misses: %4.2f/key\n",
632+
results[0]*1.0/to_lookup_mixed.size(),
633+
results[1]*1.0/to_lookup_mixed.size(),
634+
results[1]*1.0/results[0],
635635
results[2]*1.0/to_lookup_mixed.size(),
636636
results[3] * 1.0/to_lookup_mixed.size());
637637
#else
@@ -721,7 +721,7 @@ int main(int argc, char * argv[]) {
721721
{5,"Cuckoo16"}, {6,"CuckooSemiSort13" }, {7,"Bloom8"},
722722
{8,"Bloom12" }, {9,"Bloom16"}, {10,"BlockedBloom"},
723723
{11,"sort"}, {12,"Xor+8"}, {13,"Xor+16"},
724-
{14,"GCS"}, {15,"CQF"}, {22, "Xor10 (NBitArray)"}, {23, "Xor14 (NBitArray)"},
724+
{14,"GCS"}, {15,"CQF"}, {22, "Xor10 (NBitArray)"}, {23, "Xor14 (NBitArray)"},
725725
{25, "Xor10"},{26, "Xor10.666"}, {37,"Bloom8 (addall)"},
726726
{38,"Bloom12 (addall)"},{39,"Bloom16 (addall)"}, {43,"Branchless Bloom8 (addall)"},
727727
{41,"Branchless Bloom12 (addall)"},{42,"Branchless Bloom16 (addall)"},
@@ -732,7 +732,7 @@ int main(int argc, char * argv[]) {
732732
std::map<int,std::string> names = {{0,"Xor8"},{1,"Xor12"},
733733
{2,"Xor16"}, {3,"Cuckoo8"}, {4,"Cuckoo12"},
734734
{5,"Cuckoo16"}, {6,"CuckooSemiSort13" }, {7,"Bloom8"},
735-
{8,"Bloom12" }, {9,"Bloom16"},
735+
{8,"Bloom12" }, {9,"Bloom16"},
736736
{11,"sort"}, {12,"Xor+8"}, {13,"Xor+16"},
737737
{14,"GCS"}, {22, "Xor10 (NBitArray)"}, {23, "Xor14 (NBitArray)"},
738738
{25, "Xor10"},{26, "Xor10.666"}, {37,"Bloom8 (addall)"},
@@ -961,7 +961,7 @@ int main(int argc, char * argv[]) {
961961
add_count, to_add, distinct_add, to_lookup, distinct_lookup, intersectionsize, hasduplicates, mixed_sets, seed);
962962
cout << setw(NAME_WIDTH) << names[10] << cf << endl;
963963
}
964-
#endif
964+
#endif
965965

966966
#ifdef __AVX2__
967967
if (algorithmId == 10 || algorithmId < 0 || (algos.find(10) != algos.end())) {
@@ -1144,21 +1144,21 @@ int main(int argc, char * argv[]) {
11441144

11451145
if (algorithmId == 43 || algorithmId < 0 || (algos.find(43) != algos.end())) {
11461146
auto cf = FilterBenchmark<
1147-
BloomFilter<uint64_t, 8, false, SimpleMixSplit>>(
1147+
BloomFilter<uint64_t, 8, true, SimpleMixSplit>>(
11481148
add_count, to_add, distinct_add, to_lookup, distinct_lookup, intersectionsize, hasduplicates, mixed_sets, seed, true);
11491149
cout << setw(NAME_WIDTH) << names[43] << cf << endl;
11501150
}
11511151

11521152
if (algorithmId == 41 || algorithmId < 0 || (algos.find(41) != algos.end())) {
11531153
auto cf = FilterBenchmark<
1154-
BloomFilter<uint64_t, 12, false, SimpleMixSplit>>(
1154+
BloomFilter<uint64_t, 12, true, SimpleMixSplit>>(
11551155
add_count, to_add, distinct_add, to_lookup, distinct_lookup, intersectionsize, hasduplicates, mixed_sets, seed, true);
11561156
cout << setw(NAME_WIDTH) << names[41] << cf << endl;
11571157
}
11581158

11591159
if (algorithmId == 42 || algorithmId < 0 || (algos.find(42) != algos.end())) {
11601160
auto cf = FilterBenchmark<
1161-
BloomFilter<uint64_t, 16, false, SimpleMixSplit>>(
1161+
BloomFilter<uint64_t, 16, true, SimpleMixSplit>>(
11621162
add_count, to_add, distinct_add, to_lookup, distinct_lookup, intersectionsize, hasduplicates, mixed_sets, seed, true);
11631163
cout << setw(NAME_WIDTH) << names[42] << cf << endl;
11641164
}

src/bloom.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,21 @@ Status BloomFilter<ItemType, bits_per_item, branchless, HashFamily, k>::Contain(
148148
uint32_t a = (uint32_t)(hash >> 32);
149149
uint32_t b = (uint32_t)hash;
150150
if (branchless) {
151-
char ok = 1;
152-
for (int i = 0; i < k; i++) {
153-
ok &= bittest64(data + reduce(a, this->arrayLength), a);
151+
int b0 = data[reduce(a, this->arrayLength)] >> (a & 63);
152+
a += b;
153+
int b1 = data[reduce(a, this->arrayLength)] >> (a & 63);
154+
a += b;
155+
int b2 = data[reduce(a, this->arrayLength)] >> (a & 63);
156+
if ((b0 & b1 & b2 & 1) == 0) {
157+
return NotFound;
158+
}
159+
for (int i = 3; i < k; i++) {
160+
a += b;
161+
if (((data[reduce(a, this->arrayLength)] >> (a & 63)) & 1) == 0) {
162+
return NotFound;
163+
}
154164
}
155-
return ok == 0 ? Ok : NotFound;
165+
return Ok;
156166
}
157167
for (int i = 0; i < k; i++) {
158168
if ((data[reduce(a, this->arrayLength)] & getBit(a)) == 0) {

0 commit comments

Comments
 (0)