Make zlib go faster

This commit is contained in:
Justine Tunney 2022-09-18 06:30:45 -07:00
parent be29b709b7
commit 224c12f54d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
6 changed files with 16 additions and 43 deletions

View file

@ -2,6 +2,7 @@
* Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "libc/nexgen32e/x86feature.h"
#include "third_party/zlib/macros.internal.h"
#include "third_party/zlib/zconf.h"
#include "third_party/zlib/zutil.internal.h"
@ -62,10 +63,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
# define MOD63(a) a %= BASE
#endif
//# include "cpu_features.h"
#if defined(ADLER32_SIMD_SSSE3) || defined(ADLER32_SIMD_NEON)
# include "adler32_simd.h"
#endif
uint32_t ZLIB_INTERNAL adler32_simd_(uint32_t, const unsigned char *, z_size_t);
/* ========================================================================= */
uLong ZEXPORT adler32_z(adler, buf, len)
@ -77,7 +75,7 @@ uLong ZEXPORT adler32_z(adler, buf, len)
unsigned n;
#if defined(ADLER32_SIMD_SSSE3)
if (buf != Z_NULL && len >= 64 && x86_cpu_enable_ssse3)
if (buf != Z_NULL && len >= 64 && X86_HAVE(SSSE3))
return adler32_simd_(adler, buf, len);
#elif defined(ADLER32_SIMD_NEON)
if (buf != Z_NULL && len >= 64)
@ -99,24 +97,9 @@ uLong ZEXPORT adler32_z(adler, buf, len)
return adler | (sum2 << 16);
}
#if defined(ADLER32_SIMD_SSSE3)
/*
* Use SSSE3 to compute the adler32. Since this routine can be
* freely used, check CPU features here. zlib convention is to
* call adler32(0, NULL, 0), before making calls to adler32().
* So this is a good early (and infrequent) place to cache CPU
* features for those later, more interesting adler32() calls.
*/
if (buf == Z_NULL) {
if (!len) /* Assume user is calling adler32(0, NULL, 0); */
cpu_check_features();
return 1L;
}
#else
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL)
return 1L;
#endif
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {