aboutsummaryrefslogtreecommitdiff
path: root/src/blockfilter.cpp
diff options
context:
space:
mode:
authorJim Posen <jim.posen@gmail.com>2018-05-13 12:00:02 -0700
committerJim Posen <jim.posen@gmail.com>2018-08-25 10:02:37 -0700
commitf33b717a85363e067316c133a542559d2f4aaeca (patch)
tree4434179067bab1ae68b8555678700b25fee4658f /src/blockfilter.cpp
parent97b64d67daf0336dfb64b132f3e4d6a4c1967da4 (diff)
downloadbitcoin-f33b717a85363e067316c133a542559d2f4aaeca.tar.xz
blockfilter: Optimization on compilers with int128 support.
Diffstat (limited to 'src/blockfilter.cpp')
-rw-r--r--src/blockfilter.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp
index 124cbcfd92..38fcfacf7f 100644
--- a/src/blockfilter.cpp
+++ b/src/blockfilter.cpp
@@ -52,6 +52,9 @@ static uint64_t GolombRiceDecode(BitStreamReader<IStream>& bitreader, uint8_t P)
// See: https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
static uint64_t MapIntoRange(uint64_t x, uint64_t n)
{
+#ifdef __SIZEOF_INT128__
+ return (static_cast<unsigned __int128>(x) * static_cast<unsigned __int128>(n)) >> 64;
+#else
// To perform the calculation on 64-bit numbers without losing the
// result to overflow, split the numbers into the most significant and
// least significant 32 bits and perform multiplication piece-wise.
@@ -70,6 +73,7 @@ static uint64_t MapIntoRange(uint64_t x, uint64_t n)
uint64_t mid34 = (bd >> 32) + (bc & 0xFFFFFFFF) + (ad & 0xFFFFFFFF);
uint64_t upper64 = ac + (bc >> 32) + (ad >> 32) + (mid34 >> 32);
return upper64;
+#endif
}
uint64_t GCSFilter::HashToRange(const Element& element) const