Coverage Report

Created: 2026-02-24 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/adler32_p.h
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
225k
#define BASE 65521U     /* largest prime smaller than 65536 */
12
26.5k
#define NMAX 5552
13
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
14
15
304k
#define ADLER_DO1(sum1, sum2, buf, i)  {(sum1) += buf[(i)]; (sum2) += (sum1);}
16
142k
#define ADLER_DO2(sum1, sum2, buf, i)  {ADLER_DO1(sum1, sum2, buf, i); ADLER_DO1(sum1, sum2, buf, i+1);}
17
59.2k
#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
40.4k
                                                uint32_t sum2, const int REBASE, const int MAX_LEN, const int COPY) {
53
40.4k
    if (len) {
54
        /* DO16 loop for large remainders only (scalar, risc-v). */
55
39.6k
        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
98.9k
        while (len >= 4) {
68
59.2k
            if (COPY) {
69
15.3k
                memcpy(dst, buf, 4);
70
15.3k
                dst += 4;
71
15.3k
            }
72
59.2k
            len -= 4;
73
59.2k
            ADLER_DO4(adler, sum2, buf, 0);
74
59.2k
            buf += 4;
75
59.2k
        }
76
39.6k
        if (len & 2) {
77
24.1k
            if (COPY) {
78
6.35k
                memcpy(dst, buf, 2);
79
6.35k
                dst += 2;
80
6.35k
            }
81
24.1k
            ADLER_DO2(adler, sum2, buf, 0);
82
24.1k
            buf += 2;
83
24.1k
        }
84
39.6k
        if (len & 1) {
85
18.9k
            if (COPY)
86
4.95k
                *dst = *buf;
87
18.9k
            ADLER_DO1(adler, sum2, buf, 0);
88
18.9k
        }
89
39.6k
    }
90
40.4k
    if (REBASE) {
91
39.9k
        adler %= BASE;
92
39.9k
        sum2 %= BASE;
93
39.9k
    }
94
    /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */
95
40.4k
    return adler | (sum2 << 16);
96
40.4k
}
adler32_ssse3.c:adler32_copy_tail
Line
Count
Source
52
13.2k
                                                uint32_t sum2, const int REBASE, const int MAX_LEN, const int COPY) {
53
13.2k
    if (len) {
54
        /* DO16 loop for large remainders only (scalar, risc-v). */
55
12.7k
        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
34.1k
        while (len >= 4) {
68
21.3k
            if (COPY) {
69
0
                memcpy(dst, buf, 4);
70
0
                dst += 4;
71
0
            }
72
21.3k
            len -= 4;
73
21.3k
            ADLER_DO4(adler, sum2, buf, 0);
74
21.3k
            buf += 4;
75
21.3k
        }
76
12.7k
        if (len & 2) {
77
8.35k
            if (COPY) {
78
0
                memcpy(dst, buf, 2);
79
0
                dst += 2;
80
0
            }
81
8.35k
            ADLER_DO2(adler, sum2, buf, 0);
82
8.35k
            buf += 2;
83
8.35k
        }
84
12.7k
        if (len & 1) {
85
6.31k
            if (COPY)
86
0
                *dst = *buf;
87
6.31k
            ADLER_DO1(adler, sum2, buf, 0);
88
6.31k
        }
89
12.7k
    }
90
13.2k
    if (REBASE) {
91
12.7k
        adler %= BASE;
92
12.7k
        sum2 %= BASE;
93
12.7k
    }
94
    /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */
95
13.2k
    return adler | (sum2 << 16);
96
13.2k
}
adler32_sse42.c:adler32_copy_tail
Line
Count
Source
52
4.50k
                                                uint32_t sum2, const int REBASE, const int MAX_LEN, const int COPY) {
53
4.50k
    if (len) {
54
        /* DO16 loop for large remainders only (scalar, risc-v). */
55
4.50k
        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
11.4k
        while (len >= 4) {
68
6.95k
            if (COPY) {
69
6.95k
                memcpy(dst, buf, 4);
70
6.95k
                dst += 4;
71
6.95k
            }
72
6.95k
            len -= 4;
73
6.95k
            ADLER_DO4(adler, sum2, buf, 0);
74
6.95k
            buf += 4;
75
6.95k
        }
76
4.50k
        if (len & 2) {
77
2.90k
            if (COPY) {
78
2.90k
                memcpy(dst, buf, 2);
79
2.90k
                dst += 2;
80
2.90k
            }
81
2.90k
            ADLER_DO2(adler, sum2, buf, 0);
82
2.90k
            buf += 2;
83
2.90k
        }
84
4.50k
        if (len & 1) {
85
2.02k
            if (COPY)
86
2.02k
                *dst = *buf;
87
2.02k
            ADLER_DO1(adler, sum2, buf, 0);
88
2.02k
        }
89
4.50k
    }
90
4.50k
    if (REBASE) {
91
4.50k
        adler %= BASE;
92
4.50k
        sum2 %= BASE;
93
4.50k
    }
94
    /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */
95
4.50k
    return adler | (sum2 << 16);
96
4.50k
}
adler32_avx2.c:adler32_copy_tail
Line
Count
Source
52
22.6k
                                                uint32_t sum2, const int REBASE, const int MAX_LEN, const int COPY) {
53
22.6k
    if (len) {
54
        /* DO16 loop for large remainders only (scalar, risc-v). */
55
22.3k
        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
53.3k
        while (len >= 4) {
68
30.9k
            if (COPY) {
69
8.39k
                memcpy(dst, buf, 4);
70
8.39k
                dst += 4;
71
8.39k
            }
72
30.9k
            len -= 4;
73
30.9k
            ADLER_DO4(adler, sum2, buf, 0);
74
30.9k
            buf += 4;
75
30.9k
        }
76
22.3k
        if (len & 2) {
77
12.8k
            if (COPY) {
78
3.45k
                memcpy(dst, buf, 2);
79
3.45k
                dst += 2;
80
3.45k
            }
81
12.8k
            ADLER_DO2(adler, sum2, buf, 0);
82
12.8k
            buf += 2;
83
12.8k
        }
84
22.3k
        if (len & 1) {
85
10.6k
            if (COPY)
86
2.92k
                *dst = *buf;
87
10.6k
            ADLER_DO1(adler, sum2, buf, 0);
88
10.6k
        }
89
22.3k
    }
90
22.6k
    if (REBASE) {
91
22.6k
        adler %= BASE;
92
22.6k
        sum2 %= BASE;
93
22.6k
    }
94
    /* D = B * 65536 + A, see: https://en.wikipedia.org/wiki/Adler-32. */
95
22.6k
    return adler | (sum2 << 16);
96
22.6k
}
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 */