]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Improve LoongArch64 crc32_fold* implementation
authorVladislav Shchapov <vladislav@shchapov.ru>
Tue, 10 Jun 2025 16:42:21 +0000 (21:42 +0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 11 Jul 2025 14:12:18 +0000 (16:12 +0200)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
arch/loongarch/crc32_la.c
arch/loongarch/loongarch_functions.h
functable.c

index 05c7866d90e4008a3877023a0a913055a0efc229..4277acbed8ac4d0d47c7bd85cc0d24cc8440e285 100644 (file)
@@ -6,6 +6,8 @@
 #if defined(LOONGARCH_CRC)
 #include "zbuild.h"
 #include "zmemory.h"
+#include "zutil.h"
+#include "crc32.h"
 #include <stdint.h>
 
 #include <larchintrin.h>
@@ -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
index ce982469a29fd2df2504c06726bd4f11a91ef065..e73c8e6648650233585612869823e85fa07e74ef 100644 (file)
@@ -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
index 1c7c679b2c8b2a4dc27fe07b07f50738f14d5c88..1903310e7a597cfe940130422862add66ddcc1a5 100644 (file)
@@ -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