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 | | #include "crc32_braid_tbl.h" |
12 | | |
13 | 8.37M | #define CRC_DO1(c, buf, i) c = crc_table[(c ^ buf[i]) & 0xff] ^ (c >> 8) |
14 | 3.25M | #define CRC_DO2(c, buf, i) {CRC_DO1(c, buf, i); CRC_DO1(c, buf, i+1);} |
15 | 1.17M | #define CRC_DO4(c, buf, i) {CRC_DO2(c, buf, i); CRC_DO2(c, buf, i+2);} |
16 | 400k | #define CRC_DO8(c, buf, i) {CRC_DO4(c, buf, i); CRC_DO4(c, buf, i+4);} |
17 | | |
18 | | Z_FORCEINLINE static uint32_t crc32_copy_small(uint32_t crc, uint8_t *dst, const uint8_t *buf, size_t len, |
19 | 2.82M | const int MAX_LEN, const int COPY) { |
20 | 2.82M | if (MAX_LEN >= 8) { |
21 | 3.22M | while (len >= 8) { |
22 | 400k | if (COPY) { |
23 | 2.13k | memcpy(dst, buf, 8); |
24 | 2.13k | dst += 8; |
25 | 2.13k | } |
26 | 400k | CRC_DO8(crc, buf, 0); |
27 | 400k | buf += 8; |
28 | 400k | len -= 8; |
29 | 400k | } |
30 | 2.82M | } |
31 | 2.82M | if (len & 4) { |
32 | 377k | if (COPY) { |
33 | 2.02k | memcpy(dst, buf, 4); |
34 | 2.02k | dst += 4; |
35 | 2.02k | } |
36 | 377k | CRC_DO4(crc, buf, 0); |
37 | 377k | buf += 4; |
38 | 377k | } |
39 | 2.82M | if (len & 2) { |
40 | 894k | if (COPY) { |
41 | 1.99k | memcpy(dst, buf, 2); |
42 | 1.99k | dst += 2; |
43 | 1.99k | } |
44 | 894k | CRC_DO2(crc, buf, 0); |
45 | 894k | buf += 2; |
46 | 894k | } |
47 | 2.82M | if (len & 1) { |
48 | 1.87M | if (COPY) |
49 | 1.84k | *dst = *buf; |
50 | 1.87M | CRC_DO1(crc, buf, 0); |
51 | 1.87M | } |
52 | | |
53 | 2.82M | return crc; |
54 | 2.82M | } crc32_pclmulqdq.c:crc32_copy_small Line | Count | Source | 19 | 2.82M | const int MAX_LEN, const int COPY) { | 20 | 2.82M | if (MAX_LEN >= 8) { | 21 | 3.22M | while (len >= 8) { | 22 | 400k | if (COPY) { | 23 | 2.13k | memcpy(dst, buf, 8); | 24 | 2.13k | dst += 8; | 25 | 2.13k | } | 26 | 400k | CRC_DO8(crc, buf, 0); | 27 | 400k | buf += 8; | 28 | 400k | len -= 8; | 29 | 400k | } | 30 | 2.82M | } | 31 | 2.82M | if (len & 4) { | 32 | 377k | if (COPY) { | 33 | 2.02k | memcpy(dst, buf, 4); | 34 | 2.02k | dst += 4; | 35 | 2.02k | } | 36 | 377k | CRC_DO4(crc, buf, 0); | 37 | 377k | buf += 4; | 38 | 377k | } | 39 | 2.82M | if (len & 2) { | 40 | 894k | if (COPY) { | 41 | 1.99k | memcpy(dst, buf, 2); | 42 | 1.99k | dst += 2; | 43 | 1.99k | } | 44 | 894k | CRC_DO2(crc, buf, 0); | 45 | 894k | buf += 2; | 46 | 894k | } | 47 | 2.82M | if (len & 1) { | 48 | 1.87M | if (COPY) | 49 | 1.84k | *dst = *buf; | 50 | 1.87M | CRC_DO1(crc, buf, 0); | 51 | 1.87M | } | 52 | | | 53 | 2.82M | return crc; | 54 | 2.82M | } |
Unexecuted instantiation: crc32_vpclmulqdq_avx2.c:crc32_copy_small Unexecuted instantiation: crc32_vpclmulqdq_avx512.c:crc32_copy_small Unexecuted instantiation: crc32_braid_c.c:crc32_copy_small Unexecuted instantiation: crc32.c:crc32_copy_small |
55 | | |
56 | | #endif /* CRC32_P_H */ |