]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Reuse unrolled ARMv8 CRC32 implementation for LoongArch64.
authorVladislav Shchapov <vladislav@shchapov.ru>
Fri, 27 Mar 2026 21:39:33 +0000 (02:39 +0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Mon, 13 Apr 2026 09:59:56 +0000 (11:59 +0200)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
arch/loongarch/crc32_la.c

index f1bd314e6592a4e5b2b9a039d8fd5ec81017ab7a..6bff320aaf8bdb33fb2a4c287ee06765a2b5030c 100644 (file)
@@ -9,63 +9,23 @@
 
 #include <larchintrin.h>
 
-Z_INTERNAL uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf, size_t len) {
-    uint32_t c = ~crc;
-
-    if (UNLIKELY(len == 1)) {
-        c = (uint32_t)__crc_w_b_w((char)(*buf), (int)c);
-        c = ~c;
-        return c;
-    }
-
-    uintptr_t align_diff = ALIGN_DIFF(buf, 8);
-    if (align_diff) {
-        if (len && (align_diff & 1)) {
-            c = (uint32_t)__crc_w_b_w((char)(*buf++), (int)c);
-            len--;
-        }
-
-        if (len >= 2 && (align_diff & 2)) {
-            c = (uint32_t)__crc_w_h_w((short)*((uint16_t*)buf), (int)c);
-            buf += 2;
-            len -= 2;
-        }
-
-        if (len >= 4 && (align_diff & 4)) {
-            c = (uint32_t)__crc_w_w_w((int)*((uint32_t*)buf), (int)c);
-            len -= 4;
-            buf += 4;
-        }
+#define Z_TARGET_CRC
+#define CRC32B(crc, val) (uint32_t)__crc_w_b_w((char)(val), (int)(crc))
+#define CRC32H(crc, val) (uint32_t)__crc_w_h_w((short)(val), (int)(crc))
+#define CRC32W(crc, val) (uint32_t)__crc_w_w_w((int)(val), (int)(crc))
+#define CRC32D(crc, val) (uint32_t)__crc_w_d_w((long int)(val), (int)(crc))
 
-    }
+#include "arch/shared/crc32_hw_common_tpl.h"
 
-    while (len >= 8) {
-        c = (uint32_t)__crc_w_d_w((long int)*((uint64_t*)buf), (int)c);
-        len -= 8;
-        buf += 8;
-    }
+#include "arch/shared/crc32_hw_copy_impl_tpl.h"
 
-    if (len & 4) {
-        c = (uint32_t)__crc_w_w_w((int)*((uint32_t*)buf), (int)c);
-        buf += 4;
-    }
 
-    if (len & 2) {
-        c = (uint32_t)__crc_w_h_w((short)*((uint16_t*)buf), (int)c);
-        buf += 2;
-    }
-
-    if (len & 1) {
-        c = (uint32_t)__crc_w_b_w((char)(*buf), (int)c);
-    }
-
-    c = ~c;
-    return c;
+Z_INTERNAL uint32_t crc32_loongarch64(uint32_t crc, const uint8_t *buf, size_t len) {
+    return crc32_hw_copy_impl(crc, NULL, buf, len, 0);
 }
 
 Z_INTERNAL uint32_t crc32_copy_loongarch64(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) {
-    crc = crc32_loongarch64(crc, src, len);
-    memcpy(dst, src, len);
-    return crc;
+    return crc32_hw_copy_impl(crc, dst, src, len, 1);
 }
+
 #endif