6#error "PURIFY_UINT_FN must be defined before including uint_impl.h"
9#ifndef PURIFY_UINT_WORDS
10#error "PURIFY_UINT_WORDS must be defined before including uint_impl.h"
32 for (i = 0; i < size; ++i) {
39 uint64_t combined = 0;
53 uint64_t undecided = (less | greater) ^ 1u;
54 less |= undecided & (uint64_t)(lhs[idx] < rhs[idx]);
55 greater |= undecided & (uint64_t)(lhs[idx] > rhs[idx]);
57 return (
int)greater - (int)less;
62 volatile uint64_t selected = (uint64_t)(flag != 0);
63 const uint64_t mask = (uint64_t)0 - selected;
66 value[i] ^= mask & (value[i] ^ other[i]);
71 uint64_t carry = addend;
74 uint64_t sum = value[i] + carry;
75 carry = sum < value[i] ? 1u : 0u;
98 uint64_t sum = value[i] + addend[i];
99 uint64_t carry1 = sum < value[i] ? 1u : 0u;
100 uint64_t next = sum + carry;
101 uint64_t carry2 = next < sum ? 1u : 0u;
103 carry = carry1 | carry2;
112 uint64_t rhs = subtrahend[i] + borrow;
113 uint64_t rhs_overflow = rhs < subtrahend[i] ? 1u : 0u;
114 uint64_t next = value[i] - rhs;
115 uint64_t needs_borrow = value[i] < rhs ? 1u : 0u;
117 borrow = rhs_overflow | needs_borrow;
126 if (value[idx] != 0) {
134 size_t word = index / 64u;
135 size_t shift = index % 64u;
139 return ((value[word] >> shift) & 1u) != 0;
143 size_t word = index / 64u;
144 size_t shift = index % 64u;
148 value[word] |= ((uint64_t)1u << shift);
153 size_t word_shift = bits / 64u;
154 size_t bit_shift = bits % 64u;
160 if (idx < word_shift) {
163 src = idx - word_shift;
164 out[idx] |= value[src] << bit_shift;
165 if (bit_shift != 0 && src > 0) {
166 out[idx] |= value[src - 1] >> (64u - bit_shift);
172 size_t word_shift = bits / 64u;
173 size_t bit_shift = bits % 64u;
177 size_t src = i + word_shift;
181 out[i] |= value[src] >> bit_shift;
183 out[i] |= value[src + 1] << (64u - bit_shift);
192 value[i] = (value[i] >> 1) | (next << 63);
198 const size_t full_words = bits / 64u;
199 const size_t extra_bits = bits % 64u;
201 if (bits >= total_bits) {
208 uint64_t mask = ((uint64_t)1u << extra_bits) - 1u;
209 value[full_words] &= mask;
216 assert(divisor != 0);
219 uint32_t next_rem = 0;
221 value[idx] = quotient;
224 return (uint32_t)rem;
230 uint64_t limb = value[i];
232 for (j = 0; j < 8u; ++j) {
static size_t purify_uint_bit_length_u64(uint64_t value)
#define PURIFY_UINT_FN(name)
static uint64_t purify_uint_add_u64_carry(uint64_t value, uint64_t addend, uint64_t *hi)
static uint64_t purify_uint_divmod_u32(uint64_t hi, uint64_t lo, uint32_t divisor, uint32_t *rem_out)
static uint64_t purify_uint_mul_u64(uint64_t lhs, uint64_t rhs, uint64_t *hi)
#define PURIFY_UINT_WORDS
void PURIFY_UINT_FN from_bytes_be(uint64_t out[PURIFY_UINT_WORDS], const unsigned char *data, size_t size)
size_t PURIFY_UINT_FN bit_length(const uint64_t value[PURIFY_UINT_WORDS])
void PURIFY_UINT_FN to_bytes_be(unsigned char out[PURIFY_UINT_WORDS *8], const uint64_t value[PURIFY_UINT_WORDS])
void PURIFY_UINT_FN mask_bits(uint64_t value[PURIFY_UINT_WORDS], size_t bits)
int PURIFY_UINT_FN try_add(uint64_t value[PURIFY_UINT_WORDS], const uint64_t addend[PURIFY_UINT_WORDS])
int PURIFY_UINT_FN bit(const uint64_t value[PURIFY_UINT_WORDS], size_t index)
int PURIFY_UINT_FN is_zero(const uint64_t value[PURIFY_UINT_WORDS])
int PURIFY_UINT_FN try_add_small(uint64_t value[PURIFY_UINT_WORDS], uint32_t addend)
void PURIFY_UINT_FN shifted_left(uint64_t out[PURIFY_UINT_WORDS], const uint64_t value[PURIFY_UINT_WORDS], size_t bits)
void PURIFY_UINT_FN set_u64(uint64_t out[PURIFY_UINT_WORDS], uint64_t value)
int PURIFY_UINT_FN try_sub(uint64_t value[PURIFY_UINT_WORDS], const uint64_t subtrahend[PURIFY_UINT_WORDS])
void PURIFY_UINT_FN shifted_right(uint64_t out[PURIFY_UINT_WORDS], const uint64_t value[PURIFY_UINT_WORDS], size_t bits)
int PURIFY_UINT_FN compare(const uint64_t lhs[PURIFY_UINT_WORDS], const uint64_t rhs[PURIFY_UINT_WORDS])
void PURIFY_UINT_FN conditional_assign(uint64_t value[PURIFY_UINT_WORDS], const uint64_t other[PURIFY_UINT_WORDS], int flag)
void PURIFY_UINT_FN shift_right_one(uint64_t value[PURIFY_UINT_WORDS])
int PURIFY_UINT_FN try_mul_small(uint64_t value[PURIFY_UINT_WORDS], uint32_t factor)
uint32_t PURIFY_UINT_FN divmod_small(uint64_t value[PURIFY_UINT_WORDS], uint32_t divisor)
void PURIFY_UINT_FN set_zero(uint64_t out[PURIFY_UINT_WORDS])
int PURIFY_UINT_FN try_set_bit(uint64_t value[PURIFY_UINT_WORDS], size_t index)