Skip to content

Commit f33b717

Browse files
committed
blockfilter: Optimization on compilers with int128 support.
1 parent 97b64d6 commit f33b717

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/blockfilter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ static uint64_t GolombRiceDecode(BitStreamReader<IStream>& bitreader, uint8_t P)
5252
// See: https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
5353
static uint64_t MapIntoRange(uint64_t x, uint64_t n)
5454
{
55+
#ifdef __SIZEOF_INT128__
56+
return (static_cast<unsigned __int128>(x) * static_cast<unsigned __int128>(n)) >> 64;
57+
#else
5558
// To perform the calculation on 64-bit numbers without losing the
5659
// result to overflow, split the numbers into the most significant and
5760
// least significant 32 bits and perform multiplication piece-wise.
@@ -70,6 +73,7 @@ static uint64_t MapIntoRange(uint64_t x, uint64_t n)
7073
uint64_t mid34 = (bd >> 32) + (bc & 0xFFFFFFFF) + (ad & 0xFFFFFFFF);
7174
uint64_t upper64 = ac + (bc >> 32) + (ad >> 32) + (mid34 >> 32);
7275
return upper64;
76+
#endif
7377
}
7478

7579
uint64_t GCSFilter::HashToRange(const Element& element) const

0 commit comments

Comments
 (0)