Line | Count | Source |
1 | | /* crc32_p.h -- Private inline functions and macros shared with |
2 | | * different computation of the CRC-32 checksum |
3 | | * of a data stream. |
4 | | * Copyright (C) 2026 Nathan Moinvaziri |
5 | | * For conditions of distribution and use, see copyright notice in zlib.h |
6 | | */ |
7 | | |
8 | | #ifndef CRC32_P_H |
9 | | #define CRC32_P_H |
10 | | |
11 | 0 | #define CRC_DO1(c, buf, i) c = crc_table[(c ^ buf[i]) & 0xff] ^ (c >> 8) |
12 | 0 | #define CRC_DO2(c, buf, i) {CRC_DO1(c, buf, i); CRC_DO1(c, buf, i+1);} |
13 | 0 | #define CRC_DO4(c, buf, i) {CRC_DO2(c, buf, i); CRC_DO2(c, buf, i+2);} |
14 | 0 | #define CRC_DO8(c, buf, i) {CRC_DO4(c, buf, i); CRC_DO4(c, buf, i+4);} |
15 | | |
16 | | Z_FORCEINLINE static uint32_t crc32_copy_small(uint32_t crc, uint8_t *dst, const uint8_t *buf, size_t len, |
17 | 0 | const int MAX_LEN, const int COPY) { |
18 | 0 | if (MAX_LEN >= 8) { |
19 | 0 | while (len >= 8) { |
20 | 0 | if (COPY) { |
21 | 0 | memcpy(dst, buf, 8); |
22 | 0 | dst += 8; |
23 | 0 | } |
24 | 0 | CRC_DO8(crc, buf, 0); |
25 | 0 | buf += 8; |
26 | 0 | len -= 8; |
27 | 0 | } |
28 | 0 | } |
29 | 0 | if (len & 4) { |
30 | 0 | if (COPY) { |
31 | 0 | memcpy(dst, buf, 4); |
32 | 0 | dst += 4; |
33 | 0 | } |
34 | 0 | CRC_DO4(crc, buf, 0); |
35 | 0 | buf += 4; |
36 | 0 | } |
37 | 0 | if (len & 2) { |
38 | 0 | if (COPY) { |
39 | 0 | memcpy(dst, buf, 2); |
40 | 0 | dst += 2; |
41 | 0 | } |
42 | 0 | CRC_DO2(crc, buf, 0); |
43 | 0 | buf += 2; |
44 | 0 | } |
45 | 0 | if (len & 1) { |
46 | 0 | if (COPY) |
47 | 0 | *dst = *buf; |
48 | 0 | CRC_DO1(crc, buf, 0); |
49 | 0 | } |
50 | |
|
51 | 0 | return crc; |
52 | 0 | } Unexecuted instantiation: crc32_pclmulqdq.c:crc32_copy_small Unexecuted instantiation: crc32_vpclmulqdq.c:crc32_copy_small Unexecuted instantiation: crc32_braid_c.c:crc32_copy_small |
53 | | |
54 | | #endif /* CRC32_P_H */ |