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"
31 for (i = 0; i < size; ++i) {
52 if (lhs[idx] < rhs[idx]) {
55 if (lhs[idx] > rhs[idx]) {
63 uint64_t carry = addend;
66 uint64_t sum = value[i] + carry;
67 carry = sum < value[i] ? 1u : 0u;
90 uint64_t sum = value[i] + addend[i];
91 uint64_t carry1 = sum < value[i] ? 1u : 0u;
92 uint64_t next = sum + carry;
93 uint64_t carry2 = next < sum ? 1u : 0u;
95 carry = carry1 | carry2;
104 uint64_t rhs = subtrahend[i] + borrow;
105 uint64_t rhs_overflow = rhs < subtrahend[i] ? 1u : 0u;
106 uint64_t next = value[i] - rhs;
107 uint64_t needs_borrow = value[i] < rhs ? 1u : 0u;
109 borrow = rhs_overflow | needs_borrow;
118 if (value[idx] != 0) {
126 size_t word = index / 64u;
127 size_t shift = index % 64u;
131 return ((value[word] >> shift) & 1u) != 0;
135 size_t word = index / 64u;
136 size_t shift = index % 64u;
140 value[word] |= ((uint64_t)1u << shift);
145 size_t word_shift = bits / 64u;
146 size_t bit_shift = bits % 64u;
152 if (idx < word_shift) {
155 src = idx - word_shift;
156 out[idx] |= value[src] << bit_shift;
157 if (bit_shift != 0 && src > 0) {
158 out[idx] |= value[src - 1] >> (64u - bit_shift);
164 size_t word_shift = bits / 64u;
165 size_t bit_shift = bits % 64u;
169 size_t src = i + word_shift;
173 out[i] |= value[src] >> bit_shift;
175 out[i] |= value[src + 1] << (64u - bit_shift);
184 value[i] = (value[i] >> 1) | (next << 63);
190 const size_t full_words = bits / 64u;
191 const size_t extra_bits = bits % 64u;
193 if (bits >= total_bits) {
200 uint64_t mask = ((uint64_t)1u << extra_bits) - 1u;
201 value[full_words] &= mask;
208 assert(divisor != 0);
211 uint32_t next_rem = 0;
213 value[idx] = quotient;
216 return (uint32_t)rem;
222 uint64_t limb = value[i];
224 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
int PURIFY_UINT_FN() try_sub(uint64_t value[PURIFY_UINT_WORDS], const uint64_t subtrahend[PURIFY_UINT_WORDS])
void PURIFY_UINT_FN() mask_bits(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() compare(const uint64_t lhs[PURIFY_UINT_WORDS], const uint64_t rhs[PURIFY_UINT_WORDS])
void PURIFY_UINT_FN() shift_right_one(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])
int PURIFY_UINT_FN() try_mul_small(uint64_t value[PURIFY_UINT_WORDS], uint32_t factor)
int PURIFY_UINT_FN() try_add_small(uint64_t value[PURIFY_UINT_WORDS], uint32_t addend)
int PURIFY_UINT_FN() try_set_bit(uint64_t value[PURIFY_UINT_WORDS], size_t index)
void PURIFY_UINT_FN() from_bytes_be(uint64_t out[PURIFY_UINT_WORDS], const unsigned char *data, size_t size)
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() try_add(uint64_t value[PURIFY_UINT_WORDS], const uint64_t addend[PURIFY_UINT_WORDS])
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() is_zero(const uint64_t value[PURIFY_UINT_WORDS])
int PURIFY_UINT_FN() bit(const uint64_t value[PURIFY_UINT_WORDS], size_t index)
void PURIFY_UINT_FN() shifted_left(uint64_t out[PURIFY_UINT_WORDS], const uint64_t value[PURIFY_UINT_WORDS], size_t bits)
size_t PURIFY_UINT_FN() bit_length(const uint64_t value[PURIFY_UINT_WORDS])