]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Synchronise ARMv8 and Loongarch CRC32 implementations
authorCameron Cawley <ccawley2011@gmail.com>
Thu, 25 Sep 2025 15:30:53 +0000 (16:30 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 27 Sep 2025 23:02:03 +0000 (01:02 +0200)
arch/arm/arm_functions.h
arch/arm/crc32_armv8.c
arch/loongarch/crc32_la.c
functable.c

index b7b24f8838e3479fd2d3d845f37bb947cab6ae91..8a89c7c4fc5886379eab46e3d5d0eae969f3d511 100644 (file)
@@ -22,6 +22,8 @@ void inflate_fast_neon(PREFIX3(stream) *strm, uint32_t start);
 
 #ifdef ARM_CRC32
 uint32_t crc32_armv8(uint32_t crc, const uint8_t *buf, size_t len);
+void     crc32_fold_copy_armv8(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len);
+void     crc32_fold_armv8(crc32_fold *crc, const uint8_t *src, size_t len, uint32_t init_crc);
 #endif
 
 #ifdef ARM_SIMD
@@ -62,6 +64,10 @@ void slide_hash_armv6(deflate_state *s);
 #  if (defined(ARM_CRC32) && defined(__ARM_FEATURE_CRC32))
 #    undef native_crc32
 #    define native_crc32 crc32_armv8
+#    undef native_crc32_fold
+#    define native_crc32_fold crc32_fold_armv8
+#    undef native_crc32_fold_copy
+#    define native_crc32_fold_copy crc32_fold_copy_armv8
 #  endif
 #endif
 
index c3561d5159ff7f90ab04561d87b44a8e6240ab92..3fa36a121f09287345dd121ac768868da5d1e05e 100644 (file)
@@ -2,12 +2,12 @@
  * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
  * Copyright (C) 2016 Yang Zhang
  * For conditions of distribution and use, see copyright notice in zlib.h
- *
-*/
+ */
 
 #if defined(ARM_CRC32)
 #include "acle_intrins.h"
 #include "zbuild.h"
+#include "crc32.h"
 
 Z_INTERNAL Z_TARGET_CRC uint32_t crc32_armv8(uint32_t crc, const uint8_t *buf, size_t len) {
     Z_REGISTER uint32_t c;
@@ -52,25 +52,35 @@ Z_INTERNAL Z_TARGET_CRC uint32_t crc32_armv8(uint32_t crc, const uint8_t *buf, s
         buf += sizeof(uint64_t);
     }
 
-    if (len >= sizeof(uint32_t)) {
+    if (len & sizeof(uint32_t)) {
         buf4 = *((uint32_t*)buf);
         c = __crc32w(c, buf4);
-        len -= sizeof(uint32_t);
         buf += sizeof(uint32_t);
     }
 
-    if (len >= sizeof(uint16_t)) {
+    if (len & sizeof(uint16_t)) {
         buf2 = *((uint16_t*)buf);
         c = __crc32h(c, buf2);
-        len -= sizeof(uint16_t);
         buf += sizeof(uint16_t);
     }
 
-    if (len) {
+    if (len & sizeof(uint8_t)) {
         c = __crc32b(c, *buf);
     }
 
     c = ~c;
     return c;
 }
+
+/* Note: Based on generic crc32_fold_* implementation with functable call replaced by direct call. */
+Z_INTERNAL Z_TARGET_CRC void crc32_fold_copy_armv8(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len) {
+    crc->value = crc32_armv8(crc->value, src, len);
+    memcpy(dst, src, len);
+}
+
+Z_INTERNAL Z_TARGET_CRC void crc32_fold_armv8(crc32_fold *crc, const uint8_t *src, size_t len, uint32_t init_crc) {
+    Z_UNUSED(init_crc);
+    crc->value = crc32_armv8(crc->value, src, len);
+}
+
 #endif
index 034bf7f17e3fe9d390a051f3d0422a661aa0f986..38c63eea0faf8f8265acc822dbe82a851696384e 100644 (file)
@@ -5,15 +5,11 @@
 
 #if defined(LOONGARCH_CRC)
 #include "zbuild.h"
-#include "zmemory.h"
-#include "zutil.h"
 #include "crc32.h"
 #include <stdint.h>
-
 #include <larchintrin.h>
 
-Z_INTERNAL uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf,
-                                      size_t len) {
+Z_INTERNAL uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf, size_t len) {
     Z_REGISTER uint32_t c;
     Z_REGISTER uint16_t buf2;
     Z_REGISTER uint32_t buf4;
@@ -76,7 +72,6 @@ Z_INTERNAL uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf,
     return c;
 }
 
-
 /* 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);
index dd6400df3f92c08660140034303e857b26c97fbe..f09544d1267f63c68a18742fd61e9153999f39ee 100644 (file)
@@ -206,6 +206,8 @@ static void init_functable(void) {
 #ifdef ARM_CRC32
     if (cf.arm.has_crc32) {
         ft.crc32 = &crc32_armv8;
+        ft.crc32_fold = &crc32_fold_armv8;
+        ft.crc32_fold_copy = &crc32_fold_copy_armv8;
     }
 #endif