61 #ifndef HAVE_128BIT_INTEGERS
72 ret.l = 0xffffffffffffffff;
73 ret.h = (uint64_t)1 << (bits - 64);
78 ret.l = (uint64_t)1 << bits;
90 uint64_t t = (
n.l + 1);
92 n.h += ((
n.l ^ t) &
n.l) >> 63;
104 uint64_t t = (
n.l - 1);
105 n.h -= ((t ^
n.l) & t) >> 63;
118 uint64_t tmp = (((a.l & b.l) & 1) + (a.l >> 1) + (b.l >> 1)) >> 63;
120 ret.h = a.h + b.h + tmp;
134 c = (((ret.l & b.l) & 1) + (b.l >> 1) + (ret.l >> 1)) >> 63;
135 ret.h = a.h - (b.h + c);
147 uint64_t u1 = (u & 0xffffffff);
148 uint64_t v1 = (v & 0xffffffff);
150 uint64_t t = (u1 * v1);
152 uint64_t w3 = (t & 0xffffffff);
154 uint64_t k = (t >> 32);
160 k = (t & 0xffffffff);
167 ret.h = (u * v) + w1 + k;
168 ret.l = (t << 32) + w3;
182 ret.h += (
n.h * m.l) + (
n.l * m.h);
197 num.h = num.l << (bits - 64);
200 num.h = (num.h << bits) | (num.l >> (64 - bits));
216 num.l = num.h >> (bits - 64);
219 num.l = (num.l >> bits) | (num.h << (64 - bits));
252 return (a.h == b.h) && (a.l == b.l);
260 if (a.h < b.h)
return false;
261 if (a.h > b.h)
return true;
284 #define uint128_gen_mask(_bits) (((_bits) >= 128) ? ~(uint128_t)0x00 : (((uint128_t)1) << (_bits)) - 1)
286 #define uint128_increment(_a) (*_a++)
287 #define uint128_decrement(_a) (*_a--)
288 #define uint128_add(_a, _b) (_a + _b)
289 #define uint128_sub(_a, _b) (_a - _b)
290 #define uint128_mul64(_a, _b) (((uint128_t)(_a)) * ((uint128_t)(_b)))
291 #define uint128_mul(_a, _b) ((_a) * (_b))
293 #define uint128_lshift(_num, _bits) (_num << _bits)
294 #define uint128_rshift(_num, _bits) (_num >> _bits)
295 #define uint128_band(_a, _b) (_a & _b)
296 #define uint128_bor(_a, _b) (_a | _b)
298 #define uint128_eq(_a, _b) (_a == _b)
299 #define uint128_gt(_a, _b) (_a > _b)
301 #define uint128_new(_a, _b) ((uint128_t)_b | ((uint128_t)_a << 64))
303 #define uint128_to_64(_a) ((uint64_t)(_a))
static uint128_t uint128_new(uint64_t h, uint64_t l)
Creates a new uint128_t from a uint64_t.
static uint128_t uint128_band(uint128_t a, uint128_t b)
Perform bitwise & of two 128bit unsigned integers.
static uint128_t uint128_gen_mask(uint8_t bits)
Create a 128 bit integer value with n bits high.
static uint64_t uint128_to_64(uint128_t a)
Returns the low bits of a 128bit integer.
static uint128_t uint128_increment(uint128_t n)
Increment a 128bit unsigned integer.
static uint128_t uint128_bor(uint128_t a, uint128_t b)
Perform bitwise | of two 128bit unsigned integers.
static uint128_t uint128_lshift(uint128_t num, uint8_t bits)
Left shift 128 bit integer.
static bool uint128_gt(uint128_t a, uint128_t b)
Return whether one integer is greater than the other.
static bool uint128_eq(uint128_t a, uint128_t b)
Return whether the integers are equal.
static uint128_t uint128_mul64(uint64_t u, uint64_t v)
Multiply two unsigned 64bit integers to get an unsigned 128bit integer.
static uint128_t uint128_sub(uint128_t a, uint128_t b)
Subtract one 128bit integer from another.
static uint128_t uint128_rshift(uint128_t num, uint8_t bits)
Right shift 128 bit integer.
static uint128_t uint128_add(uint128_t a, uint128_t b)
Add two 128bit unsigned integers.
static uint128_t uint128_decrement(uint128_t n)
Decrement a 128bit unsigned integer.
static uint128_t uint128_mul(uint128_t n, uint128_t m)
Multiply two unsigned 128bit integers.