summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pop <s.pop@samsung.com>2019-04-01 15:05:53 -0500
committerHans Kristian Rosbach <hk-github@circlestorm.org>2019-04-04 10:13:26 +0200
commit098f73a45e1e346b7634b6caa15675095f764dfc (patch)
tree515a8da69d4f9776e65668580ff1bb31ab51dde1
parent3ac4f5de069564698c263097996669e6153286f3 (diff)
cleanup arm/adler32_neon.c code
-rw-r--r--adler32.c3
-rw-r--r--adler32_p.h2
-rw-r--r--arch/arm/adler32_neon.c17
3 files changed, 7 insertions, 15 deletions
diff --git a/adler32.c b/adler32.c
index feff67b..af41047 100644
--- 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);
diff --git a/adler32_p.h b/adler32_p.h
index 131513a..6766530 100644
--- a/adler32_p.h
+++ b/adler32_p.h
@@ -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 */
diff --git a/arch/arm/adler32_neon.c b/arch/arm/adler32_neon.c
index f8573ec..3e0ee4d 100644
--- a/arch/arm/adler32_neon.c
+++ b/arch/arm/adler32_neon.c
@@ -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. */