#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32_z)(unsigned long adler, const unsigned char *buf, size_t len) {
+ if (buf == NULL)
+ return ADLER32_INITIAL_VALUE;
return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
}
#else
uint32_t Z_EXPORT PREFIX(adler32_z)(uint32_t adler, const unsigned char *buf, size_t len) {
+ if (buf == NULL)
+ return ADLER32_INITIAL_VALUE;
return FUNCTABLE_CALL(adler32)(adler, buf, len);
}
#endif
/* ========================================================================= */
#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32)(unsigned long adler, const unsigned char *buf, unsigned int len) {
+ if (buf == NULL)
+ return ADLER32_INITIAL_VALUE;
return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
}
#else
uint32_t Z_EXPORT PREFIX(adler32)(uint32_t adler, const unsigned char *buf, uint32_t len) {
+ if (buf == NULL)
+ return ADLER32_INITIAL_VALUE;
return FUNCTABLE_CALL(adler32)(adler, buf, len);
}
#endif
if (UNLIKELY(len == 1))
return adler32_copy_len_1(adler, dst, src, sum2, COPY);
- /* initial Adler-32 value (deferred check for len == 1 speed) */
- if (UNLIKELY(src == NULL))
- return 1L;
-
/* in case short lengths are provided, keep it somewhat fast */
if (UNLIKELY(len < 16))
return adler32_copy_len_16(adler, dst, src, len, sum2, COPY);
if (UNLIKELY(len == 1))
return adler32_copy_len_1(adler, NULL, buf, sum2, 0);
- /* initial Adler-32 value (deferred check for len == 1 speed) */
- if (UNLIKELY(buf == NULL))
- return 1L;
-
/* in case short lengths are provided, keep it somewhat fast */
if (UNLIKELY(len < 16))
return adler32_copy_len_16(adler, NULL, buf, len, sum2, 0);
extern uint32_t adler32_lsx(uint32_t adler, const uint8_t *src, size_t len);
Z_FORCEINLINE static uint32_t adler32_copy_impl(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len, const int COPY) {
- if (UNLIKELY(src == NULL)) return 1L;
- if (UNLIKELY(len == 0)) return adler;
-
uint32_t adler0, adler1;
adler1 = (adler >> 16) & 0xffff;
adler0 = adler & 0xffff;
}
Z_FORCEINLINE static uint32_t adler32_copy_impl(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len, const int COPY) {
- if (UNLIKELY(src == NULL)) return 1L;
- if (UNLIKELY(len == 0)) return adler;
-
uint32_t adler0, adler1;
adler1 = (adler >> 16) & 0xffff;
adler0 = adler & 0xffff;
if (UNLIKELY(len == 1))
return adler32_copy_len_1(s1, NULL, buf, s2, 0);
- /* If buffer is empty or len=0 we need to return adler initial value. */
- if (UNLIKELY(buf == NULL))
- return 1;
-
/* This is faster than VSX code for len < 64. */
if (len < 64)
return adler32_copy_len_64(s1, NULL, buf, len, s2, 0);
if (UNLIKELY(len == 1))
return adler32_copy_len_1(adler, NULL, buf, sum2, 0);
- /* initial Adler-32 value (deferred check for len == 1 speed) */
- if (UNLIKELY(buf == NULL))
- return 1L;
-
/* in case short lengths are provided, keep it somewhat fast */
if (UNLIKELY(len < 16))
return adler32_copy_len_16(adler, NULL, buf, len, sum2, 0);
unsigned long len = (unsigned long) _len;
- if (p == (const unsigned char *) 0x0)
- return 0;
-
crc ^= 0xffffffff;
if (len < VMX_ALIGN + VMX_ALIGN_MASK) {
if (UNLIKELY(len == 1))
return adler32_copy_len_1(adler, dst, src, sum2, COPY);
- /* initial Adler-32 value (deferred check for len == 1 speed) */
- if (UNLIKELY(src == NULL))
- return 1L;
-
/* in case short lengths are provided, keep it somewhat fast */
if (UNLIKELY(len < 16))
return adler32_copy_len_16(adler, dst, src, len, sum2, COPY);
extern uint32_t adler32_ssse3(uint32_t adler, const uint8_t *src, size_t len);
Z_FORCEINLINE static uint32_t adler32_copy_impl(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len, const int COPY) {
- if (UNLIKELY(src == NULL)) return 1L;
- if (UNLIKELY(len == 0)) return adler;
-
uint32_t adler0, adler1;
adler1 = (adler >> 16) & 0xffff;
adler0 = adler & 0xffff;
#include "adler32_avx512_p.h"
Z_FORCEINLINE static uint32_t adler32_copy_impl(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len, const int COPY) {
- if (UNLIKELY(src == NULL)) return 1L;
- if (UNLIKELY(len == 0)) return adler;
-
uint32_t adler0, adler1;
adler1 = (adler >> 16) & 0xffff;
adler0 = adler & 0xffff;
#include "adler32_avx2_p.h"
Z_INTERNAL uint32_t adler32_avx512_vnni(uint32_t adler, const uint8_t *src, size_t len) {
- if (UNLIKELY(src == NULL)) return 1L;
- if (UNLIKELY(len == 0)) return adler;
-
uint32_t adler0, adler1;
adler1 = (adler >> 16) & 0xffff;
adler0 = adler & 0xffff;
/* Use 256-bit vectors when copying because 512-bit variant is slower. */
Z_INTERNAL uint32_t adler32_copy_avx512_vnni(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len) {
- if (UNLIKELY(src == NULL)) return 1L;
- if (UNLIKELY(len == 0)) return adler;
-
uint32_t adler0, adler1;
adler1 = (adler >> 16) & 0xffff;
adler0 = adler & 0xffff;
if (UNLIKELY(len == 1))
return adler32_copy_len_1(adler, NULL, buf, sum2, 0);
- /* initial Adler-32 value (deferred check for len == 1 speed) */
- if (UNLIKELY(buf == NULL))
- return 1L;
-
/* in case short lengths are provided, keep it somewhat fast */
if (UNLIKELY(len < 16))
return adler32_copy_len_16(adler, NULL, buf, len, sum2, 0);
#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(crc32_z)(unsigned long crc, const unsigned char *buf, size_t len) {
- if (buf == NULL) return 0;
-
+ if (buf == NULL)
+ return CRC32_INITIAL_VALUE;
return (unsigned long)FUNCTABLE_CALL(crc32)((uint32_t)crc, buf, len);
}
#else
uint32_t Z_EXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t len) {
- if (buf == NULL) return 0;
-
+ if (buf == NULL)
+ return CRC32_INITIAL_VALUE;
return FUNCTABLE_CALL(crc32)(crc, buf, len);
}
#endif
#ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(crc32)(unsigned long crc, const unsigned char *buf, unsigned int len) {
+ if (buf == NULL)
+ return CRC32_INITIAL_VALUE;
return (unsigned long)PREFIX(crc32_z)((uint32_t)crc, buf, len);
}
#else
uint32_t Z_EXPORT PREFIX(crc32)(uint32_t crc, const unsigned char *buf, uint32_t len) {
+ if (buf == NULL)
+ return CRC32_INITIAL_VALUE;
return PREFIX(crc32_z)(crc, buf, len);
}
#endif
} hash_test;
static const hash_test hash_tests[] = {
- {0, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0},
- {0, (const uint8_t *)0x0, 0xffffffff, 0x1, 0xffffffff, 0x0},
- {255, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0}, /* BZ 174799. */
- {256, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0},
- {257, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0},
- {32767, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0},
- {32768, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0},
- {32769, (const uint8_t *)0x0, 0x0, 0x1, 0x0, 0x0},
{0, (const uint8_t *)"", 0x1, 0x1, 0x0, 0x0},
{1, (const uint8_t *)"", 0x1, 0x10001, 0x0, 0xd202ef8d},
{0, (const uint8_t *)"", 0xffffffff, 0x000e000e, 0xffffffff, 0xffffffff},
{100, (const uint8_t *)"r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 0x1, 0xfbdb1e96, 0x0, 0xeaa52777},
{100, (const uint8_t *)"h{bcmdC+a;t+Cf{6Y_dFq-{X4Yu&7uNfVDh?q&_u.UWJU],-GiH7ADzb7-V.Q%4=+v!$L9W+T=bP]$_:]Vyg}A.ygD.r;h-D]m%&", 0x1, 0x47a61ec8, 0x0, 0xcd472048},
{5552, (const uint8_t *)long_string, 0x1, 0x8b81718f, 0x0, 0x426fa73b},
- {0, (const uint8_t *)0x0, 0x7a30360d, 0x1, 0x0, 0x0},
{6, (const uint8_t *)"abacus", 0x1, 0x8400270, 0x7a30360d, 0xf8655a84},
{1, (const uint8_t *)"", 0x6fd767ee, 0xd7c567ee, 0x6fd767ee, 0x95dff795},
{1, (const uint8_t *)"a", 0xefeb7589, 0x65e475ea, 0x0, 0xe8b7be43},
void adler32_copy_test(adler32_copy_func copyfunc, hash_test params) {
ASSERT_LE(params.len, HASH_TEST_MAX_LENGTH);
- if (params.buf == NULL) {
- GTEST_SKIP();
- }
-
uint32_t adler = copyfunc(params.initial_adler, dstbuf, params.buf, params.len);
EXPECT_EQ(adler, params.expect_adler);
class crc32_variant : public ::testing::TestWithParam<hash_test> {
public:
void hash(hash_test param, crc32_func crc32) {
- uint32_t crc = 0;
- if (param.buf != NULL) {
- if (param.len) {
- crc = crc32(param.initial_crc, param.buf, param.len);
- } else {
- crc = param.initial_crc;
- }
- }
+ uint32_t crc = crc32(param.initial_crc, param.buf, param.len);
EXPECT_EQ(crc, param.expect_crc);
}
};
public:
void hash(int param, crc32_func crc32) {
uint8_t *buf = (uint8_t*)zng_alloc(sizeof(uint8_t) * (128 + param));
- if (buf != NULL) {
- (void)crc32(0, buf + param, 128);
- } else {
- FAIL();
- }
+ (void)crc32(0, buf + param, 128);
zng_free(buf);
}
};
void crc32_copy_test(crc32_copy_func copyfunc, hash_test params) {
ASSERT_LE(params.len, HASH_TEST_MAX_LENGTH);
- if (params.buf == NULL) {
- GTEST_SKIP();
- }
-
uint32_t crc = copyfunc(params.initial_crc, dstbuf, params.buf, params.len);
EXPECT_EQ(crc, params.expect_crc);