52[[nodiscard]]
static inline uint64_t
multiply_uint64(uint64_t x, uint64_t y,
62[[nodiscard]]
static inline uint64_t
divide_128(uint64_t high, uint64_t low,
83 uint32_t x_hi =
static_cast<uint32_t
>(x >> 32);
84 uint32_t x_lo =
static_cast<uint32_t
>(x);
85 uint32_t y_hi =
static_cast<uint32_t
>(y >> 32);
86 uint32_t y_lo =
static_cast<uint32_t
>(y);
88 uint64_t hi_lo =
static_cast<uint64_t
>(x_hi) * y_lo;
90 uint64_t low =
static_cast<uint64_t
>(x_lo) * y_lo;
93 uint64_t mid = (low >> 32) +
static_cast<uint64_t
>(x_lo) * y_hi +
94 static_cast<uint32_t
>(hi_lo);
95 hi = (mid >> 32) +
static_cast<uint64_t
>(x_hi) * y_hi + (hi_lo >> 32);
96 return static_cast<uint32_t
>(low) + (mid << 32);
100#if defined(_MSC_VER) && defined(_M_X64) && !defined(_M_ARM64EC)
103#pragma intrinsic(_umul128)
104[[nodiscard]]
static inline uint64_t
multiply_uint64(uint64_t x, uint64_t y,
106 return _umul128(x, y, &hi);
108#elif defined(__SIZEOF_INT128__)
111[[nodiscard]]
static inline uint64_t
multiply_uint64(uint64_t x, uint64_t y,
113 unsigned __int128 res = (
unsigned __int128)x * y;
114 hi =
static_cast<uint64_t
>(res >> 64);
115 return static_cast<uint64_t
>(res);
124[[nodiscard]]
static inline uint64_t
divide_128(uint64_t high, uint64_t low,
127 for (
auto current_bit = 63; current_bit >= 0; current_bit--) {
128 const auto div_hi = current_bit ? (div >> (64 - current_bit)) : 0;
129 const auto div_lo = div << current_bit;
130 if (div_hi < high || (div_hi == high && div_lo <= low)) {
136 res += 1ULL << current_bit;
202 const uint64_t guess = hi *
m_mod;
203 const uint64_t rest = x - guess;
248 stored_data.
m_inv.load(std::memory_order_relaxed)};
256 data.
m_mod.store(new_mod, std::memory_order_relaxed);
257 data.
m_inv.store(inv, std::memory_order_relaxed);
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:41
A class that allows to read value of variable of some type T atomically and allows the value to be ch...
Definition: ut0seq_lock.h:49
Allows to execute x % mod for a specified mod in a fast way, without using a slow operation of divisi...
Definition: ut0math.h:145
uint64_t get_inverse() const
Gets the precomputed value of inverse.
Definition: ut0math.h:209
uint64_t m_inv
Definition: ut0math.h:232
uint64_t compute(uint64_t x) const
Computes the value of x % mod.
Definition: ut0math.h:198
fast_modulo_t(uint64_t mod)
Definition: ut0math.h:193
static uint64_t precompute_inv(uint64_t mod)
Precomputes the inverse needed for fast modulo operations.
Definition: ut0math.h:215
uint64_t m_mod
Definition: ut0math.h:231
fast_modulo_t(uint64_t mod, uint64_t inv)
Definition: ut0math.h:195
uint64_t get_mod() const
Gets the modulo value.
Definition: ut0math.h:212
A class that allows to atomically set new modulo value for fast modulo computations.
Definition: ut0math.h:237
mt_fast_modulo_t()
Definition: ut0math.h:239
mt_fast_modulo_t(uint64_t mod)
Definition: ut0math.h:240
fast_modulo_t load()
Definition: ut0math.h:245
void store(uint64_t new_mod)
Definition: ut0math.h:252
Seq_lock< data_t > m_data
Definition: ut0math.h:267
Definition: ut0tuple.h:57
constexpr uint64_t multiply_uint64_portable(uint64_t x, uint64_t y, uint64_t &hi)
Calculates the 128bit result of multiplication of the two specified 64bit integers.
Definition: ut0math.h:80
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
uint64_t find_prime(uint64_t n)
Looks for a prime number slightly greater than the given argument.
Definition: ut0math.cc:36
static uint64_t multiply_uint64(uint64_t x, uint64_t y, uint64_t &hi)
Calculates the 128bit result of multiplication of the two specified 64bit integers.
Definition: ut0math.h:118
static uint64_t divide_128(uint64_t high, uint64_t low, uint64_t div)
Definition: ut0math.h:124
Definition: ut0math.h:262
std::atomic< uint64_t > m_mod
Definition: ut0math.h:263
std::atomic< uint64_t > m_inv
Definition: ut0math.h:264
Utilities related to class lifecycle.
Debug utilities for Innobase.
static uint64_t operator%(uint64_t x, const ut::fast_modulo_t &fm)
Definition: ut0math.h:272
Implements a sequential lock structure for non-locking atomic read/write operations on a complex stru...
int n
Definition: xcom_base.cc:509