]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
cleanup arm/adler32_neon.c code
authorSebastian Pop <s.pop@samsung.com>
Mon, 1 Apr 2019 20:05:53 +0000 (15:05 -0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 4 Apr 2019 08:13:26 +0000 (10:13 +0200)
adler32.c
adler32_p.h
arch/arm/adler32_neon.c

index feff67bccee0fe22e8117d8bf491140cb7fe0f4a..af410477835a781fff1c970b727a9d3a6c7b0fc0 100644 (file)
--- a/adler32.c
+++ b/adler32.c
@@ -13,9 +13,6 @@
 uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t len);
 static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2);
 
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
 #define DO1(buf, i)  {adler += (buf)[i]; sum2 += adler;}
 #define DO2(buf, i)  DO1(buf, i); DO1(buf, i+1);
 #define DO4(buf, i)  DO2(buf, i); DO2(buf, i+2);
index 131513a89dac1c25776f39559be4ebcfcef0d5df..6766530408e14b3e0a532cdfe55320fa3b01237e 100644 (file)
@@ -9,6 +9,8 @@
 #define ADLER32_P_H
 
 #define BASE 65521U     /* largest prime smaller than 65536 */
+#define NMAX 5552
+/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
 
 /* use NO_DIVIDE if your processor does not do division in hardware --
    try it both ways to see which is faster */
index f8573ec5536e3bdbf50e8ff85bf8b7a369ddde07..3e0ee4dd853e75fe62a1a0360739e3f9b41f1a34 100644 (file)
@@ -72,7 +72,6 @@ static void NEON_accum32(uint32_t *s, const unsigned char *buf, size_t len) {
 }
 
 static void NEON_handle_tail(uint32_t *pair, const unsigned char *buf, size_t len) {
-    /* Oldie K&R code integration. */
     unsigned int i;
     for (i = 0; i < len; ++i) {
         pair[0] += buf[i];
@@ -97,15 +96,9 @@ uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len) {
     if (len < 16)
         return adler32_len_16(adler, buf, len, sum2);
 
-    /* The largest prime smaller than 65536. */
-    const uint32_t M_BASE = 65521;
-    /* This is the threshold where doing accumulation may overflow. */
-    const int M_NMAX = 5552;
-
     uint32_t pair[2];
-    int n = M_NMAX;
+    int n = NMAX;
     unsigned int done = 0;
-    /* Oldie K&R code integration. */
     unsigned int i;
 
     /* Split Adler-32 into component sums, it can be supplied by
@@ -122,8 +115,8 @@ uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len) {
             break;
 
         NEON_accum32(pair, buf + i, n / 16);
-        pair[0] %= M_BASE;
-        pair[1] %= M_BASE;
+        pair[0] %= BASE;
+        pair[1] %= BASE;
 
         done += (n / 16) * 16;
     }
@@ -131,8 +124,8 @@ uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len) {
     /* Handle the tail elements. */
     if (done < len) {
         NEON_handle_tail(pair, (buf + done), len - done);
-        pair[0] %= M_BASE;
-        pair[1] %= M_BASE;
+        pair[0] %= BASE;
+        pair[1] %= BASE;
     }
 
     /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */