Line | Count | Source |
1 | | /* adler32_p.h -- Private inline functions and macros shared with |
2 | | * different computation of the Adler-32 checksum |
3 | | * of a data stream. |
4 | | * Copyright (C) 1995-2011, 2016 Mark Adler |
5 | | * For conditions of distribution and use, see copyright notice in zlib.h |
6 | | */ |
7 | | |
8 | | #ifndef ADLER32_P_H |
9 | | #define ADLER32_P_H |
10 | | |
11 | 605M | #define BASE 65521U /* largest prime smaller than 65536 */ |
12 | 0 | #define NMAX 5552 |
13 | | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ |
14 | | |
15 | 302M | #define ADLER_DO1(sum1, sum2, buf, i) {(sum1) += buf[(i)]; (sum2) += (sum1);} |
16 | 0 | #define ADLER_DO2(sum1, sum2, buf, i) {ADLER_DO1(sum1, sum2, buf, i); ADLER_DO1(sum1, sum2, buf, i+1);} |
17 | 0 | #define ADLER_DO4(sum1, sum2, buf, i) {ADLER_DO2(sum1, sum2, buf, i); ADLER_DO2(sum1, sum2, buf, i+2);} |
18 | 0 | #define ADLER_DO8(sum1, sum2, buf, i) {ADLER_DO4(sum1, sum2, buf, i); ADLER_DO4(sum1, sum2, buf, i+4);} |
19 | 0 | #define ADLER_DO16(sum1, sum2, buf) {ADLER_DO8(sum1, sum2, buf, 0); ADLER_DO8(sum1, sum2, buf, 8);} |
20 | | |
21 | | Z_FORCEINLINE static void adler32_copy_align(uint32_t *Z_RESTRICT adler, uint8_t *dst, const uint8_t *buf, size_t len, |
22 | 0 | uint32_t *Z_RESTRICT sum2, const int MAX_LEN, const int COPY) { |
23 | 0 | Z_UNUSED(MAX_LEN); |
24 | 0 | if (len & 1) { |
25 | 0 | if (COPY) { |
26 | 0 | *dst = *buf; |
27 | 0 | dst += 1; |
28 | 0 | } |
29 | 0 | ADLER_DO1(*adler, *sum2, buf, 0); |
30 | 0 | buf += 1; |
31 | 0 | } |
32 | 0 | if (len & 2) { |
33 | 0 | if (COPY) { |
34 | 0 | memcpy(dst, buf, 2); |
35 | 0 | dst += 2; |
36 | 0 | } |
37 | 0 | ADLER_DO2(*adler, *sum2, buf, 0); |
38 | 0 | buf += 2; |
39 | 0 | } |
40 | 0 | while (len >= 4) { |
41 | 0 | if (COPY) { |
42 | 0 | memcpy(dst, buf, 4); |
43 | 0 | dst += 4; |
44 | 0 | } |
45 | 0 | len -= 4; |
46 | 0 | ADLER_DO4(*adler, *sum2, buf, 0); |
47 | 0 | buf += 4; |
48 | 0 | } |
49 | 0 | } Unexecuted instantiation: adler32_ssse3.c:adler32_copy_align Unexecuted instantiation: adler32_sse42.c:adler32_copy_align Unexecuted instantiation: adler32_avx2.c:adler32_copy_align Unexecuted instantiation: adler32_avx512.c:adler32_copy_align Unexecuted instantiation: adler32_avx512_vnni.c:adler32_copy_align Unexecuted instantiation: adler32_c.c:adler32_copy_align |
50 | | |
51 | | Z_FORCEINLINE static uint32_t adler32_copy_tail(uint32_t adler, uint8_t *dst, const uint8_t *buf, size_t len, |
52 | 302M | uint32_t sum2, const int REBASE, const int MAX_LEN, const int COPY) { |
53 | 302M | if (len) { |
54 | | /* DO16 loop for large remainders only (scalar, risc-v). */ |
55 | 302M | if (MAX_LEN >= 32) { |
56 | 0 | while (len >= 16) { |
57 | 0 | if (COPY) { |
58 | 0 | memcpy(dst, buf, 16); |
59 | 0 | dst += 16; |
60 | 0 | } |
61 | 0 | len -= 16; |
62 | 0 | ADLER_DO16(adler, sum2, buf); |
63 | 0 | buf += 16; |
64 | 0 | } |
65 | 0 | } |
66 | | /* DO4 loop avoids GCC x86 register pressure from hoisted DO8/DO16 loads. */ |
67 | 302M | while (len >= 4) { |
68 | 0 | if (COPY) { |
69 | 0 | memcpy(dst, buf, 4); |
70 | 0 | dst += 4; |
71 | 0 | } |
72 | 0 | len -= 4; |
73 | 0 | ADLER_DO4(adler, sum2, buf, 0); |
74 | 0 | buf += 4; |
75 | 0 | } |
76 | 302M | if (len & 2) { |
77 | 0 | if (COPY) { |
78 | 0 | memcpy(dst, buf, 2); |
79 | 0 | dst += 2; |
80 | 0 | } |
81 | 0 | ADLER_DO2(adler, sum2, buf, 0); |
82 | 0 | buf += 2; |
83 | 0 | } |
84 | 302M | if (len & 1) { |
85 | 302M | if (COPY) |
86 | 302M | *dst = *buf; |
87 | 302M | ADLER_DO1(adler, sum2, buf, 0); |
88 | 302M | } |
89 | 302M | } |
90 | 302M | if (REBASE) { |
91 | 302M | adler %= BASE; |
92 | 302M | sum2 %= BASE; |
93 | 302M | } |
94 | | /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */ |
95 | 302M | return adler | (sum2 << 16); |
96 | 302M | } Unexecuted instantiation: adler32_ssse3.c:adler32_copy_tail Unexecuted instantiation: adler32_sse42.c:adler32_copy_tail adler32_avx2.c:adler32_copy_tail Line | Count | Source | 52 | 302M | uint32_t sum2, const int REBASE, const int MAX_LEN, const int COPY) { | 53 | 302M | if (len) { | 54 | | /* DO16 loop for large remainders only (scalar, risc-v). */ | 55 | 302M | if (MAX_LEN >= 32) { | 56 | 0 | while (len >= 16) { | 57 | 0 | if (COPY) { | 58 | 0 | memcpy(dst, buf, 16); | 59 | 0 | dst += 16; | 60 | 0 | } | 61 | 0 | len -= 16; | 62 | 0 | ADLER_DO16(adler, sum2, buf); | 63 | 0 | buf += 16; | 64 | 0 | } | 65 | 0 | } | 66 | | /* DO4 loop avoids GCC x86 register pressure from hoisted DO8/DO16 loads. */ | 67 | 302M | while (len >= 4) { | 68 | 0 | if (COPY) { | 69 | 0 | memcpy(dst, buf, 4); | 70 | 0 | dst += 4; | 71 | 0 | } | 72 | 0 | len -= 4; | 73 | 0 | ADLER_DO4(adler, sum2, buf, 0); | 74 | 0 | buf += 4; | 75 | 0 | } | 76 | 302M | if (len & 2) { | 77 | 0 | if (COPY) { | 78 | 0 | memcpy(dst, buf, 2); | 79 | 0 | dst += 2; | 80 | 0 | } | 81 | 0 | ADLER_DO2(adler, sum2, buf, 0); | 82 | 0 | buf += 2; | 83 | 0 | } | 84 | 302M | if (len & 1) { | 85 | 302M | if (COPY) | 86 | 302M | *dst = *buf; | 87 | 302M | ADLER_DO1(adler, sum2, buf, 0); | 88 | 302M | } | 89 | 302M | } | 90 | 302M | if (REBASE) { | 91 | 302M | adler %= BASE; | 92 | 302M | sum2 %= BASE; | 93 | 302M | } | 94 | | /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */ | 95 | 302M | return adler | (sum2 << 16); | 96 | 302M | } |
Unexecuted instantiation: adler32_avx512.c:adler32_copy_tail Unexecuted instantiation: adler32_avx512_vnni.c:adler32_copy_tail Unexecuted instantiation: adler32_c.c:adler32_copy_tail |
97 | | |
98 | | #endif /* ADLER32_P_H */ |