1 /* crc32_braid_comb.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016, 2018 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 "zbuild.h"
11 #include "zutil.h"
12 #include "crc32_braid_p.h"
13 #include "crc32_braid_tbl.h"
14 #include "crc32_braid_comb_p.h"
15
16 /* ========================================================================= */
crc32_combine_(uint32_t crc1,uint32_t crc2,z_off64_t len2)17 static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
18 return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;
19 }
crc32_combine_gen_(z_off64_t len2)20 static uint32_t crc32_combine_gen_(z_off64_t len2) {
21 return x2nmodp(len2, 3);
22 }
crc32_combine_op_(uint32_t crc1,uint32_t crc2,const uint32_t op)23 static uint32_t crc32_combine_op_(uint32_t crc1, uint32_t crc2, const uint32_t op) {
24 return multmodp(op, crc1) ^ crc2;
25 }
26
27 /* ========================================================================= */
28
29 #ifdef ZLIB_COMPAT
PREFIX(crc32_combine)30 unsigned long Z_EXPORT PREFIX(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off_t len2) {
31 return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2);
32 }
PREFIX4(crc32_combine)33 unsigned long Z_EXPORT PREFIX4(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off64_t len2) {
34 return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2);
35 }
PREFIX(crc32_combine_gen)36 unsigned long Z_EXPORT PREFIX(crc32_combine_gen)(z_off_t len2) {
37 return crc32_combine_gen_(len2);
38 }
PREFIX4(crc32_combine_gen)39 unsigned long Z_EXPORT PREFIX4(crc32_combine_gen)(z_off64_t len2) {
40 return crc32_combine_gen_(len2);
41 }
PREFIX(crc32_combine_op)42 unsigned long Z_EXPORT PREFIX(crc32_combine_op)(unsigned long crc1, unsigned long crc2, const unsigned long op) {
43 return (unsigned long)crc32_combine_op_((uint32_t)crc1, (uint32_t)crc2, (uint32_t)op);
44 }
45 #else
PREFIX4(crc32_combine)46 uint32_t Z_EXPORT PREFIX4(crc32_combine)(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
47 return crc32_combine_(crc1, crc2, len2);
48 }
PREFIX(crc32_combine_gen)49 uint32_t Z_EXPORT PREFIX(crc32_combine_gen)(z_off64_t len2) {
50 return crc32_combine_gen_(len2);
51 }
PREFIX(crc32_combine_op)52 uint32_t Z_EXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t op) {
53 return crc32_combine_op_(crc1, crc2, op);
54 }
55 #endif
56
57 /* ========================================================================= */
58