/src/zlib-ng/crc32_braid_comb.c
Line | Count | Source |
1 | | /* crc32_braid_comb.c -- compute the CRC-32 of a data stream |
2 | | * Copyright (C) 1995-2022 Mark Adler |
3 | | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | | * |
5 | | * This interleaved implementation of a CRC makes use of pipelined multiple |
6 | | * arithmetic-logic units, commonly found in modern CPU cores. It is due to |
7 | | * Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution. |
8 | | */ |
9 | | |
10 | | #include "zutil.h" |
11 | | #include "crc32_braid_p.h" |
12 | | #include "crc32_braid_tbl.h" |
13 | | #include "crc32_braid_comb_p.h" |
14 | | |
15 | | /* ========================================================================= */ |
16 | 1.97k | static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) { |
17 | 1.97k | return multmodp(x2nmodp(len2, 3), crc1) ^ crc2; |
18 | 1.97k | } |
19 | 1.31k | static uint32_t crc32_combine_gen_(z_off64_t len2) { |
20 | 1.31k | return x2nmodp(len2, 3); |
21 | 1.31k | } |
22 | 1.79M | static uint32_t crc32_combine_op_(uint32_t crc1, uint32_t crc2, const uint32_t op) { |
23 | 1.79M | return multmodp(op, crc1) ^ crc2; |
24 | 1.79M | } |
25 | | |
26 | | /* ========================================================================= */ |
27 | | |
28 | | #ifdef ZLIB_COMPAT |
29 | | unsigned long Z_EXPORT PREFIX(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off_t len2) { |
30 | | return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2); |
31 | | } |
32 | | unsigned long Z_EXPORT PREFIX4(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off64_t len2) { |
33 | | return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2); |
34 | | } |
35 | | unsigned long Z_EXPORT PREFIX(crc32_combine_gen)(z_off_t len2) { |
36 | | return crc32_combine_gen_(len2); |
37 | | } |
38 | | unsigned long Z_EXPORT PREFIX4(crc32_combine_gen)(z_off64_t len2) { |
39 | | return crc32_combine_gen_(len2); |
40 | | } |
41 | | unsigned long Z_EXPORT PREFIX(crc32_combine_op)(unsigned long crc1, unsigned long crc2, const unsigned long op) { |
42 | | return (unsigned long)crc32_combine_op_((uint32_t)crc1, (uint32_t)crc2, (uint32_t)op); |
43 | | } |
44 | | #else |
45 | 1.97k | uint32_t Z_EXPORT PREFIX4(crc32_combine)(uint32_t crc1, uint32_t crc2, z_off64_t len2) { |
46 | 1.97k | return crc32_combine_(crc1, crc2, len2); |
47 | 1.97k | } |
48 | 1.31k | uint32_t Z_EXPORT PREFIX(crc32_combine_gen)(z_off64_t len2) { |
49 | 1.31k | return crc32_combine_gen_(len2); |
50 | 1.31k | } |
51 | 1.79M | uint32_t Z_EXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t op) { |
52 | 1.79M | return crc32_combine_op_(crc1, crc2, op); |
53 | 1.79M | } |
54 | | #endif |
55 | | |
56 | | /* ========================================================================= */ |