5#ifndef BITCOIN_UTIL_FASTRANGE_H
6#define BITCOIN_UTIL_FASTRANGE_H
21 return (uint64_t{x} * n) >> 32;
27#ifdef __SIZEOF_INT128__
28 return (
static_cast<unsigned __int128
>(x) *
static_cast<unsigned __int128
>(n)) >> 64;
35 const uint64_t x_hi = x >> 32;
36 const uint64_t x_lo = x & 0xFFFFFFFF;
37 const uint64_t n_hi = n >> 32;
38 const uint64_t n_lo = n & 0xFFFFFFFF;
40 const uint64_t ac = x_hi * n_hi;
41 const uint64_t ad = x_hi * n_lo;
42 const uint64_t bc = x_lo * n_hi;
43 const uint64_t bd = x_lo * n_lo;
45 const uint64_t mid34 = (bd >> 32) + (bc & 0xFFFFFFFF) + (ad & 0xFFFFFFFF);
46 const uint64_t upper64 = ac + (bc >> 32) + (ad >> 32) + (mid34 >> 32);
static uint64_t FastRange64(uint64_t x, uint64_t n)
Fast range reduction with 64-bit input and 64-bit range.
static uint32_t FastRange32(uint32_t x, uint32_t n)
Fast range reduction with 32-bit input and 32-bit range.