Skip to content

Commit

Permalink
Added CRC32_INITIAL_VALUE to prevent initial call to crc32 function.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz authored and Dead2 committed Aug 13, 2021
1 parent 0064010 commit db59b63
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions arch/x86/crc_folding.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@

#include "crc_folding.h"

Z_INTERNAL uint32_t crc_fold_init(unsigned int crc0[4 * 5]) {
Z_INTERNAL void crc_fold_init(unsigned int crc0[4 * 5]) {
/* CRC_SAVE */
_mm_storeu_si128((__m128i *)crc0 + 0, _mm_cvtsi32_si128(0x9db42487));
_mm_storeu_si128((__m128i *)crc0 + 1, _mm_setzero_si128());
_mm_storeu_si128((__m128i *)crc0 + 2, _mm_setzero_si128());
_mm_storeu_si128((__m128i *)crc0 + 3, _mm_setzero_si128());

return 0;
}

static void fold_1(__m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2, __m128i *xmm_crc3) {
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/crc_folding.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "../../zutil.h"

Z_INTERNAL uint32_t crc_fold_init(unsigned int crc0[4 * 5]);
Z_INTERNAL void crc_fold_init(unsigned int crc0[4 * 5]);
Z_INTERNAL uint32_t crc_fold_512to32(unsigned int crc0[4 * 5]);
Z_INTERNAL void crc_fold_copy(unsigned int crc0[4 * 5], unsigned char *, const unsigned char *, long);

Expand Down
5 changes: 2 additions & 3 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ Z_INTERNAL void crc_reset(deflate_state *const s) {
#ifdef X86_PCLMULQDQ_CRC
x86_check_features();
if (x86_cpu_has_pclmulqdq) {
s->strm->adler = crc_fold_init(s->crc0);
return;
crc_fold_init(s->crc0);
}
#endif
s->strm->adler = PREFIX(crc32)(0L, NULL, 0);
s->strm->adler = CRC32_INITIAL_VALUE;
}

Z_INTERNAL void copy_with_crc(PREFIX3(stream) *strm, unsigned char *dst, unsigned long size) {
Expand Down
4 changes: 2 additions & 2 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
if (state->wbits == 0)
state->wbits = 15;
state->check = PREFIX(crc32)(0L, NULL, 0);
state->check = CRC32_INITIAL_VALUE;
CRC2(state->check, hold);
INITBITS();
state->mode = FLAGS;
Expand Down Expand Up @@ -578,7 +578,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
state->head->hcrc = (int)((state->flags >> 9) & 1);
state->head->done = 1;
}
strm->adler = state->check = PREFIX(crc32)(0L, NULL, 0);
strm->adler = state->check = CRC32_INITIAL_VALUE;
state->mode = TYPE;
break;
#endif
Expand Down
1 change: 1 addition & 0 deletions zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */

#define ADLER32_INITIAL_VALUE 1 /* initial adler-32 hash value */
#define CRC32_INITIAL_VALUE 0 /* initial crc-32 hash value */

/* target dependencies */

Expand Down

0 comments on commit db59b63

Please sign in to comment.