diff options
| author | Mattias Andrée <m@maandree.se> | 2025-12-06 16:24:06 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-12-06 16:24:06 +0100 |
| commit | 5a0ff887b2bdb6d3643b85a7f7042ae20a30e8ab (patch) | |
| tree | 2c4e3765c62bcd022479a62151b1f0d7278ff773 /common.h | |
| parent | Refine implementation of Wu's Colour Quantiser (diff) | |
| download | libquanta-5a0ff887b2bdb6d3643b85a7f7042ae20a30e8ab.tar.gz libquanta-5a0ff887b2bdb6d3643b85a7f7042ae20a30e8ab.tar.bz2 libquanta-5a0ff887b2bdb6d3643b85a7f7042ae20a30e8ab.tar.xz | |
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'common.h')
| -rw-r--r-- | common.h | 79 |
1 files changed, 0 insertions, 79 deletions
@@ -11,82 +11,3 @@ #define PALETTE_VALUE_TYPE uint64_t #define PALETTE_VALUE_SIZE sizeof(PALETTE_VALUE_TYPE) #define PALETTE_VALUE_MAX_BITS 64U - - -struct bigint { - uintmax_t high, low; -}; - - -#if defined(__GNUC__) -__attribute__((__visibility__("hidden"))) -#endif -uintmax_t libquanta_bigint_divmod_small__(struct bigint *big, uintmax_t small); -#define bigint_divmod_small libquanta_bigint_divmod_small__ - - -static inline void -bigint_add_small(struct bigint *big, uintmax_t small) -{ -#if defined(__GNUC__) - if (__builtin_add_overflow(big->low, small, &big->low)) - big->high += 1U; -#else - if (big->low > UINTMAX_MAX - small) - big->high += 1U; - big->low += small; -#endif -} - - -static inline void -bigint_sub_small(struct bigint *big, uintmax_t small) -{ -#if defined(__GNUC__) - if (__builtin_sub_overflow(big->low, small, &big->low)) - big->high -= 1U; -#else - if (big->low < small) - big->high -= 1U; - big->low -= small; -#endif -} - - -static inline void -bigint_add_big(struct bigint *res, const struct bigint *restrict other) -{ - bigint_add_small(res, other->low); - res->high += other->high; -} - - -static inline void -bigint_sub_big(struct bigint *res, const struct bigint *restrict other) -{ - bigint_sub_small(res, other->low); - res->high -= other->high; -} - - -static inline void -bigint_rsub_big(struct bigint *res, const struct bigint *restrict other) -{ - res->high = other->high - res->high; -#if defined(__GNUC__) - if (__builtin_sub_overflow(other->low, res->low, &res->low)) - res->high -= 1U; -#else - if (res->low > other->low) - res->high -= 1U; - res->low = other->low - res->low; -#endif -} - - -static inline uintmax_t -bigint_div_small(const struct bigint *big, uintmax_t small) -{ - struct bigint big_copy = *big; - return bigint_divmod_small(&big_copy, small); -} |
