From 28e3d4fe081d45e362745ab04549b2699ac5f663 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 24 Jul 2025 16:52:17 +0200 Subject: [PATCH] Put those functions into the right place. --- src/utils/crc32.c | 76 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/utils/crc32.c b/src/utils/crc32.c index 9eacb3921..719f3a237 100644 --- a/src/utils/crc32.c +++ b/src/utils/crc32.c @@ -243,44 +243,6 @@ static void once(once_t *state, void (*init)(void)) { /* State for once(). */ static once_t made = ONCE_INIT; -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -static crc_t multmodp(crc_t a, crc_t b) { - crc_t m, p; - - m = (crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -static crc_t x2nmodp(z_off64_t n, unsigned k) { - crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - /* Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. @@ -553,6 +515,44 @@ static void braid(crc_t ltl[][256], word_t big[][256], int n, int w) { */ #ifdef ARMCRC32 +/* + Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, + reflected. For speed, this requires that a not be zero. + */ +static crc_t multmodp(crc_t a, crc_t b) { + crc_t m, p; + + m = (crc_t)1 << 31; + p = 0; + for (;;) { + if (a & m) { + p ^= b; + if ((a & (m - 1)) == 0) + break; + } + m >>= 1; + b = b & 1 ? (b >> 1) ^ POLY : b >> 1; + } + return p; +} + +/* + Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been + initialized. + */ +static crc_t x2nmodp(z_off64_t n, unsigned k) { + crc_t p; + + p = (z_crc_t)1 << 31; /* x^0 == 1 */ + while (n) { + if (n & 1) + p = multmodp(x2n_table[k & 31], p); + n >>= 1; + k++; + } + return p; +} + /* Constants empirically determined to maximize speed. These values are from measurements on a Cortex-A57. Your mileage may vary.