12#ifndef RANLUXPP_HELPERS_H
13#define RANLUXPP_HELPERS_H
18static inline uint64_t
add_overflow(uint64_t
a, uint64_t
b,
unsigned &overflow)
26static inline uint64_t
add_carry(uint64_t
a, uint64_t
b,
unsigned &carry)
37static inline uint64_t
sub_overflow(uint64_t
a, uint64_t
b,
unsigned &overflow)
45static inline uint64_t
sub_carry(uint64_t
a, uint64_t
b,
unsigned &carry)
62static inline int64_t
compute_r(
const uint64_t *upper, uint64_t *
r)
66 for (
int i = 0; i < 9; i++) {
70 uint64_t t1_i = upper[i];
74 int64_t
c = -((int64_t)carry);
78 for (
int i = 0; i < 9; i++) {
84 t2_bits += upper[i + 5] >> 16;
86 t2_bits += upper[i + 6] << 48;
99 uint64_t t2_bits = (upper[5] >> 16) << 48;
100 uint64_t t3_bits = (upper[0] << 48);
107 for (
int i = 0; i < 3; i++) {
108 uint64_t r_i =
r[i + 4];
111 uint64_t t2_bits = (upper[5 + i] >> 32) + (upper[6 + i] << 32);
112 uint64_t t3_bits = (upper[i] >> 16) + (upper[1 + i] << 48);
123 uint64_t t2_bits = (upper[8] >> 32);
124 uint64_t t3_bits = (upper[3] >> 16) + (upper[4] << 48);
135 uint64_t t3_bits = (upper[4] >> 16) + (upper[5] << 48);
148 bool greater_m =
r[0] |
r[1] |
r[2] | (
r[3] & 0x0000ffffffffffff);
149 greater_m &= (
r[3] >> 48) == 0xffff;
150 for (
int i = 4; i < 9; i++) {
151 greater_m &= (
r[i] == UINT64_MAX);
153 return c + (
c == 0 && greater_m);
static uint64_t sub_overflow(uint64_t a, uint64_t b, unsigned &overflow)
Compute a - b and set overflow accordingly.
static uint64_t sub_carry(uint64_t a, uint64_t b, unsigned &carry)
Compute a - b and increment carry if there was an overflow.
static uint64_t add_carry(uint64_t a, uint64_t b, unsigned &carry)
Compute a + b and increment carry if there was an overflow.
static int64_t compute_r(const uint64_t *upper, uint64_t *r)
Update r = r - (t1 + t2) + (t3 + t2) * b ** 10.
static uint64_t add_overflow(uint64_t a, uint64_t b, unsigned &overflow)
Compute a + b and set overflow accordingly.