diff options
| author | Cameron Cawley <ccawley2011@gmail.com> | 2025-10-02 23:09:58 +0100 |
|---|---|---|
| committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2026-02-17 23:23:12 +0100 |
| commit | e7cf8743d30281ca98cc65ada061e8b022643686 (patch) | |
| tree | 1f42469cc58f3222b486142c30fea858bb0ef7ab | |
| parent | 3e391c13074083eee416c424cccf1d87a32fd5bf (diff) | |
| download | Project-Tick-e7cf8743d30281ca98cc65ada061e8b022643686.tar.gz Project-Tick-e7cf8743d30281ca98cc65ada061e8b022643686.zip | |
Simplify alignment casts in Chorba code
| -rw-r--r-- | arch/generic/crc32_chorba_c.c | 26 | ||||
| -rw-r--r-- | arch/x86/crc32_chorba_sse2.c | 8 | ||||
| -rw-r--r-- | arch/x86/crc32_chorba_sse41.c | 10 | ||||
| -rw-r--r-- | arch/x86/x86_functions.h | 2 | ||||
| -rw-r--r-- | crc32_chorba_p.h | 8 |
5 files changed, 33 insertions, 21 deletions
diff --git a/arch/generic/crc32_chorba_c.c b/arch/generic/crc32_chorba_c.c index 87e4fdf674..2ef716de5d 100644 --- a/arch/generic/crc32_chorba_c.c +++ b/arch/generic/crc32_chorba_c.c @@ -36,7 +36,7 @@ * @note Requires minimum input size of 118960 + 512 bytes * @note Uses 128KB temporary buffer */ -Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive(uint32_t crc, const chorba_word_t *input, size_t len) { +Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive(uint32_t crc, const uint8_t *buf, size_t len) { #if defined(__EMSCRIPTEN__) chorba_word_t *bitbuffer = (chorba_word_t*)zng_alloc(bitbuffer_size_bytes); #else @@ -44,7 +44,9 @@ Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive(uint32_t crc, const chorb #endif const uint8_t *bitbuffer_bytes = (const uint8_t*)bitbuffer; uint64a_t *bitbuffer_qwords = (uint64a_t*)bitbuffer; - const uint64a_t *input_qwords = (const uint64a_t*)input; + /* The calling function ensured that this is aligned correctly */ + const chorba_word_t* input = (const chorba_word_t*)buf; + const uint64a_t* input_qwords = (const uint64a_t*)buf; size_t i = 0; @@ -486,7 +488,9 @@ Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive(uint32_t crc, const chorb # if CHORBA_W == 8 /* Implement Chorba algorithm from https://arxiv.org/abs/2412.16398 */ -Z_INTERNAL uint32_t crc32_chorba_32768_nondestructive(uint32_t crc, const uint64_t* input, size_t len) { +Z_INTERNAL uint32_t crc32_chorba_32768_nondestructive(uint32_t crc, const uint8_t* buf, size_t len) { + /* The calling function ensured that this is aligned correctly */ + const uint64_t* input = (const uint64_t*)buf; uint64_t bitbuffer[32768 / sizeof(uint64_t)]; const uint8_t *bitbuffer_bytes = (const uint8_t*)bitbuffer; memset(bitbuffer, 0, 32768); @@ -633,7 +637,9 @@ Z_INTERNAL uint32_t crc32_chorba_32768_nondestructive(uint32_t crc, const uint64 } /* Implement Chorba algorithm from https://arxiv.org/abs/2412.16398 */ -Z_INTERNAL uint32_t crc32_chorba_small_nondestructive(uint32_t crc, const uint64_t *input, size_t len) { +Z_INTERNAL uint32_t crc32_chorba_small_nondestructive(uint32_t crc, const uint8_t *buf, size_t len) { + /* The calling function ensured that this is aligned correctly */ + const uint64_t* input = (const uint64_t*)buf; uint64_t final[9] = {0}; uint64_t next1 = ~crc; crc = 0; @@ -1066,7 +1072,9 @@ Z_INTERNAL uint32_t crc32_chorba_small_nondestructive(uint32_t crc, const uint64 #else // CHORBA_W == 8 -Z_INTERNAL uint32_t crc32_chorba_small_nondestructive_32bit(uint32_t crc, const uint32_t *input, size_t len) { +Z_INTERNAL uint32_t crc32_chorba_small_nondestructive_32bit(uint32_t crc, const uint8_t *buf, size_t len) { + /* The calling function ensured that this is aligned correctly */ + const uint32_t* input = (const uint32_t*)buf; uint32_t final[20] = {0}; uint32_t next1 = ~crc; @@ -1250,13 +1258,13 @@ Z_INTERNAL uint32_t crc32_chorba(uint32_t crc, const uint8_t *buf, size_t len) { buf += align_diff; } if (len > CHORBA_LARGE_THRESHOLD) - return crc32_chorba_118960_nondestructive(crc, (const chorba_word_t*)buf, len); + return crc32_chorba_118960_nondestructive(crc, buf, len); #if CHORBA_W == 8 if (len > CHORBA_MEDIUM_LOWER_THRESHOLD && len <= CHORBA_MEDIUM_UPPER_THRESHOLD) - return crc32_chorba_32768_nondestructive(crc, (const uint64_t*)buf, len); - return crc32_chorba_small_nondestructive(crc, (const uint64_t*)buf, len); + return crc32_chorba_32768_nondestructive(crc, buf, len); + return crc32_chorba_small_nondestructive(crc, buf, len); #else - return crc32_chorba_small_nondestructive_32bit(crc, (const uint32_t*)buf, len); + return crc32_chorba_small_nondestructive_32bit(crc, buf, len); #endif } diff --git a/arch/x86/crc32_chorba_sse2.c b/arch/x86/crc32_chorba_sse2.c index 8ecd74443e..66191e046a 100644 --- a/arch/x86/crc32_chorba_sse2.c +++ b/arch/x86/crc32_chorba_sse2.c @@ -20,7 +20,9 @@ d = _mm_srli_epi64(invec, 20); \ } while (0); -Z_INTERNAL uint32_t chorba_small_nondestructive_sse2(uint32_t crc, const uint64_t *input, size_t len) { +Z_INTERNAL uint32_t chorba_small_nondestructive_sse2(uint32_t crc, const uint8_t *buf, size_t len) { + /* The calling function ensured that this is aligned correctly */ + const uint64_t* input = (const uint64_t*)buf; ALIGNED_(16) uint64_t final[9] = {0}; uint64_t next1 = ~crc; crc = 0; @@ -857,9 +859,9 @@ Z_INTERNAL uint32_t crc32_chorba_sse2(uint32_t crc, const uint8_t *buf, size_t l } #if !defined(WITHOUT_CHORBA) if (len > CHORBA_LARGE_THRESHOLD) - return crc32_chorba_118960_nondestructive(crc, (const chorba_word_t*)buf, len); + return crc32_chorba_118960_nondestructive(crc, buf, len); #endif - return chorba_small_nondestructive_sse2(crc, (const uint64_t*)buf, len); + return chorba_small_nondestructive_sse2(crc, buf, len); } Z_INTERNAL uint32_t crc32_copy_chorba_sse2(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { diff --git a/arch/x86/crc32_chorba_sse41.c b/arch/x86/crc32_chorba_sse41.c index 4e750cbd8d..6ef9612440 100644 --- a/arch/x86/crc32_chorba_sse41.c +++ b/arch/x86/crc32_chorba_sse41.c @@ -52,7 +52,9 @@ out3 = _mm_xor_si128(in[4], xor3); \ } while (0) -Z_FORCEINLINE static uint32_t crc32_chorba_32768_nondestructive_sse41(uint32_t crc, const uint64_t *input, size_t len) { +Z_FORCEINLINE static uint32_t crc32_chorba_32768_nondestructive_sse41(uint32_t crc, const uint8_t *buf, size_t len) { + /* The calling function ensured that this is aligned correctly */ + const uint64_t* input = (const uint64_t*)buf; ALIGNED_(16) uint64_t bitbuffer[32768 / sizeof(uint64_t)]; __m128i *bitbuffer_v = (__m128i*)bitbuffer; const uint8_t *bitbuffer_bytes = (const uint8_t*)bitbuffer; @@ -315,11 +317,11 @@ Z_INTERNAL uint32_t crc32_chorba_sse41(uint32_t crc, const uint8_t *buf, size_t } #if !defined(WITHOUT_CHORBA) if (len > CHORBA_LARGE_THRESHOLD) - return crc32_chorba_118960_nondestructive(crc, (chorba_word_t*)buf, len); + return crc32_chorba_118960_nondestructive(crc, buf, len); #endif if (len > CHORBA_MEDIUM_LOWER_THRESHOLD && len <= CHORBA_MEDIUM_UPPER_THRESHOLD) - return crc32_chorba_32768_nondestructive_sse41(crc, (const uint64_t*)buf, len); - return chorba_small_nondestructive_sse2(crc, (const uint64_t*)buf, len); + return crc32_chorba_32768_nondestructive_sse41(crc, buf, len); + return chorba_small_nondestructive_sse2(crc, buf, len); } Z_INTERNAL uint32_t crc32_copy_chorba_sse41(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { diff --git a/arch/x86/x86_functions.h b/arch/x86/x86_functions.h index b1d623cace..9162d7eab5 100644 --- a/arch/x86/x86_functions.h +++ b/arch/x86/x86_functions.h @@ -25,7 +25,7 @@ void slide_hash_sse2(deflate_state *s); # if !defined(WITHOUT_CHORBA_SSE) uint32_t crc32_chorba_sse2(uint32_t crc, const uint8_t *buf, size_t len); uint32_t crc32_copy_chorba_sse2(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len); - uint32_t chorba_small_nondestructive_sse2(uint32_t c, const uint64_t *aligned_buf, size_t aligned_len); + uint32_t chorba_small_nondestructive_sse2(uint32_t c, const uint8_t *aligned_buf, size_t aligned_len); # endif #endif diff --git a/crc32_chorba_p.h b/crc32_chorba_p.h index f599e707b0..75928a3e58 100644 --- a/crc32_chorba_p.h +++ b/crc32_chorba_p.h @@ -26,9 +26,9 @@ typedef uint32_t chorba_word_t; #endif -Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive (uint32_t crc, const chorba_word_t* input, size_t len); -Z_INTERNAL uint32_t crc32_chorba_32768_nondestructive (uint32_t crc, const uint64_t* input, size_t len); -Z_INTERNAL uint32_t crc32_chorba_small_nondestructive (uint32_t crc, const uint64_t* input, size_t len); -Z_INTERNAL uint32_t crc32_chorba_small_nondestructive_32bit (uint32_t crc, const uint32_t* input, size_t len); +Z_INTERNAL uint32_t crc32_chorba_118960_nondestructive (uint32_t crc, const uint8_t* input, size_t len); +Z_INTERNAL uint32_t crc32_chorba_32768_nondestructive (uint32_t crc, const uint8_t* input, size_t len); +Z_INTERNAL uint32_t crc32_chorba_small_nondestructive (uint32_t crc, const uint8_t* input, size_t len); +Z_INTERNAL uint32_t crc32_chorba_small_nondestructive_32bit (uint32_t crc, const uint8_t* input, size_t len); #endif /* CRC32_CHORBA_P_H_ */ |
