From: Vladislav Shchapov Date: Tue, 10 Jun 2025 16:42:21 +0000 (+0500) Subject: Improve LoongArch64 crc32_fold* implementation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=673d90ab96e928f1c63b487c8d1aa8b0c214ba4e;p=thirdparty%2Fzlib-ng.git Improve LoongArch64 crc32_fold* implementation Signed-off-by: Vladislav Shchapov --- diff --git a/arch/loongarch/crc32_la.c b/arch/loongarch/crc32_la.c index 05c7866d..4277acbe 100644 --- a/arch/loongarch/crc32_la.c +++ b/arch/loongarch/crc32_la.c @@ -6,6 +6,8 @@ #if defined(LOONGARCH_CRC) #include "zbuild.h" #include "zmemory.h" +#include "zutil.h" +#include "crc32.h" #include #include @@ -34,4 +36,16 @@ Z_INTERNAL uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf, return crc ^ 0xffffffff; } + +/* Note: Based on generic crc32_fold_* implementation with functable call replaced by direct call. */ +Z_INTERNAL void crc32_fold_copy_loongarch64(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len) { + crc->value = crc32_loongarch64(crc->value, src, len); + memcpy(dst, src, len); +} + +Z_INTERNAL void crc32_fold_loongarch64(crc32_fold *crc, const uint8_t *src, size_t len, uint32_t init_crc) { + Z_UNUSED(init_crc); + crc->value = crc32_loongarch64(crc->value, src, len); +} + #endif diff --git a/arch/loongarch/loongarch_functions.h b/arch/loongarch/loongarch_functions.h index ce982469..e73c8e66 100644 --- a/arch/loongarch/loongarch_functions.h +++ b/arch/loongarch/loongarch_functions.h @@ -10,6 +10,8 @@ #ifdef LOONGARCH_CRC uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf, size_t len); +void crc32_fold_copy_loongarch64(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len); +void crc32_fold_loongarch64(crc32_fold *crc, const uint8_t *src, size_t len, uint32_t init_crc); #endif #ifdef LOONGARCH_LSX @@ -25,6 +27,10 @@ void slide_hash_lasx(deflate_state *s); # if defined(LOONGARCH_CRC) # undef native_crc32 # define native_crc32 crc32_loongarch64 +# undef native_crc32_fold +# define native_crc32_fold crc32_fold_loongarch64 +# undef native_crc32_fold_copy +# define native_crc32_fold_copy crc32_fold_copy_loongarch64 # endif # if defined(LOONGARCH_LSX) && defined(__loongarch_sx) # undef native_slide_hash diff --git a/functable.c b/functable.c index 1c7c679b..1903310e 100644 --- a/functable.c +++ b/functable.c @@ -273,6 +273,8 @@ static void init_functable(void) { #ifdef LOONGARCH_CRC if (cf.loongarch.has_crc) { ft.crc32 = crc32_loongarch64; + ft.crc32_fold = &crc32_fold_loongarch64; + ft.crc32_fold_copy = &crc32_fold_copy_loongarch64; } #endif #ifdef LOONGARCH_LSX