Compare commits

...

No commits in common. "imports/c9/zlib-1.2.11-34.el9" and "c8" have entirely different histories.

14 changed files with 1514 additions and 916 deletions

View File

@ -1,139 +1,240 @@
From d1155b9ab9a2ef643ec82285d1fb767dcfd00d16 Mon Sep 17 00:00:00 2001
From: Ondrej Dubaj <odubaj@redhat.com>
Date: Thu, 1 Aug 2019 12:17:06 +0200
Subject: [PATCH] Optimized CRC32 for POWER 8+ architectures.
From 64af50f69caa52e676a3d7066c2b07ff43d33862 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:41:11 +0100
Subject: [PATCH] 0002-PATCH-Add-Power8-optimized-crc32.patch
---
Makefile.in | 8 +
configure | 77 ++
contrib/power8-crc/clang_workaround.h | 82 ++
contrib/power8-crc/crc32_constants.h | 1206 +++++++++++++++++++++++++
contrib/power8-crc/vec_crc32.c | 674 ++++++++++++++
crc32.c | 100 +-
6 files changed, 2135 insertions(+), 12 deletions(-)
create mode 100644 contrib/power8-crc/clang_workaround.h
create mode 100644 contrib/power8-crc/crc32_constants.h
create mode 100644 contrib/power8-crc/vec_crc32.c
CMakeLists.txt | 7 +-
Makefile.in | 43 +-
configure | 7 +-
contrib/README.contrib | 3 +-
contrib/power/clang_workaround.h | 82 ++
contrib/power/crc32_constants.h | 1206 ++++++++++++++++++++++++++++++
contrib/power/crc32_z_power8.c | 679 +++++++++++++++++
contrib/power/crc32_z_resolver.c | 15 +
contrib/power/power.h | 4 +
crc32.c | 12 +
test/crc32_test.c | 205 +++++
12 files changed, 2252 insertions(+), 14 deletions(-)
create mode 100644 contrib/power/clang_workaround.h
create mode 100644 contrib/power/crc32_constants.h
create mode 100644 contrib/power/crc32_z_power8.c
create mode 100644 contrib/power/crc32_z_resolver.c
create mode 100644 test/crc32_test.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e762023..abf606c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -184,7 +184,8 @@ if(CMAKE_COMPILER_IS_GNUCC)
if(POWER8)
add_definitions(-DZ_POWER8)
- set(ZLIB_POWER8 )
+ set(ZLIB_POWER8
+ contrib/power/crc32_z_power8.c)
set_source_files_properties(
${ZLIB_POWER8}
@@ -301,6 +302,10 @@ add_executable(example test/example.c)
target_link_libraries(example zlib)
add_test(example example)
+add_executable(crc32_test test/crc32_test.c)
+target_link_libraries(crc32_test zlib)
+add_test(crc32_test crc32_test)
+
add_executable(minigzip test/minigzip.c)
target_link_libraries(minigzip zlib)
diff --git a/Makefile.in b/Makefile.in
index b7bdbf2..55f6489 100644
index e756e2f..d392616 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -167,6 +167,9 @@ minigzip64.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
adler32.o: $(SRCDIR)adler32.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)adler32.c
@@ -75,11 +75,11 @@ PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
+crc32_power8.o: $(SRCDIR)contrib/power8-crc/vec_crc32.c
+ $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)contrib/power8-crc/vec_crc32.c
all: static shared
-static: example$(EXE) minigzip$(EXE)
+static: crc32_test$(EXE) example$(EXE) minigzip$(EXE)
-shared: examplesh$(EXE) minigzipsh$(EXE)
+shared: crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE)
-all64: example64$(EXE) minigzip64$(EXE)
+all64: crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE)
check: test
@@ -87,7 +87,7 @@ test: all teststatic testshared
teststatic: static
@TMPST=tmpst_$$; \
- if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
+ if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST && ./crc32_test; then \
echo ' *** zlib test OK ***'; \
else \
echo ' *** zlib test FAILED ***'; false; \
@@ -100,7 +100,7 @@ testshared: shared
DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
TMPSH=tmpsh_$$; \
- if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
+ if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH && ./crc32_testsh; then \
echo ' *** zlib shared test OK ***'; \
else \
echo ' *** zlib shared test FAILED ***'; false; \
@@ -109,7 +109,7 @@ testshared: shared
test64: all64
@TMP64=tmp64_$$; \
- if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
+ if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64 && ./crc32_test64; then \
echo ' *** zlib 64-bit test OK ***'; \
else \
echo ' *** zlib 64-bit test FAILED ***'; false; \
@@ -151,12 +151,18 @@ dfltcc.lo: $(SRCDIR)contrib/s390/dfltcc.c $(SRCDIR)zlib.h zconf.h
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/s390/dfltcc.c
-@mv objs/dfltcc.o $@
+crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h
+ $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c
+
example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c
minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c
+crc32_test64.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h
+ $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/crc32_test.c
+
example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c
@@ -170,6 +176,9 @@ adler32.o: $(SRCDIR)adler32.c
crc32.o: $(SRCDIR)crc32.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c
@@ -215,6 +218,11 @@ adler32.lo: $(SRCDIR)adler32.c
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/adler32.o $(SRCDIR)adler32.c
-@mv objs/adler32.o $@
+crc32_power8.lo: $(SRCDIR)contrib/power8-crc/vec_crc32.c
+ -@mkdir objs 2>/dev/null || test -d objs
+ $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32_power8.o $(SRCDIR)contrib/power8-crc/vec_crc32.c
+ -@mv objs/crc32_power8.o $@
+crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c
+ $(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c
+
crc32.lo: $(SRCDIR)crc32.c
-@mkdir objs 2>/dev/null || test -d objs
deflate.o: $(SRCDIR)deflate.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c
@@ -220,6 +229,11 @@ crc32.lo: $(SRCDIR)crc32.c
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c
-@mv objs/crc32.o $@
+crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c
+ -@mkdir objs 2>/dev/null || test -d objs
+ $(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c
+ -@mv objs/crc32_z_power8.o $@
+
deflate.lo: $(SRCDIR)deflate.c
-@mkdir objs 2>/dev/null || test -d objs
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c
@@ -293,18 +307,27 @@ placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
ln -s $@ $(SHAREDLIBM)
-@rmdir objs
+crc32_test$(EXE): crc32_test.o $(STATICLIB)
+ $(CC) $(CFLAGS) -o $@ crc32_test.o $(TEST_LDFLAGS)
+
example$(EXE): example.o $(STATICLIB)
$(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
minigzip$(EXE): minigzip.o $(STATICLIB)
$(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
+crc32_testsh$(EXE): crc32_test.o $(SHAREDLIBV)
+ $(CC) $(CFLAGS) -o $@ crc32_test.o -L. $(SHAREDLIBV)
+
examplesh$(EXE): example.o $(SHAREDLIBV)
$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
+crc32_test64$(EXE): crc32_test64.o $(STATICLIB)
+ $(CC) $(CFLAGS) -o $@ crc32_test64.o $(TEST_LDFLAGS)
+
example64$(EXE): example64.o $(STATICLIB)
$(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
@@ -374,8 +397,8 @@ zconf: $(SRCDIR)zconf.h.in
mostlyclean: clean
clean:
rm -f *.o *.lo *~ \
- example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
- example64$(EXE) minigzip64$(EXE) \
+ crc32_test$(EXE) example$(EXE) minigzip$(EXE) crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
+ crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE) \
infcover \
libz.* foo.gz so_locations \
_match.s maketree contrib/infback9/*.o
@@ -399,7 +422,7 @@ tags:
adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
-compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
+compress.o crc32_test.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
@@ -409,7 +432,7 @@ trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)tr
adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
-compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
+compress.lo crc32_test.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
diff --git a/configure b/configure
index cd9eeef..e93ff99 100755
index 0538d58..e37dac8 100755
--- a/configure
+++ b/configure
@@ -839,6 +839,83 @@ else
echo "Checking for sys/sdt.h ... No." | tee -a configure.log
fi
@@ -876,6 +876,9 @@ cat > $test.c <<EOF
#ifndef _ARCH_PPC
#error "Target is not Power"
#endif
+#if !(defined(__PPC64__) || defined(__powerpc64__))
+ #error "Target is not 64 bits"
+#endif
#ifndef HAVE_IFUNC
#error "Target doesn't support ifunc"
#endif
@@ -889,8 +892,8 @@ if tryboth $CC -c $CFLAGS $test.c; then
+# test to see if Power8+ implementation is compile time possible
+echo >> configure.log
+cat > $test.c <<EOF
+#if _ARCH_PWR8==1
+#if __BYTE_ORDER == __BIG_ENDIAN && defined(__clang__)
+#error "Clang vector instructions aren't big endian compatible"
+#endif
+#if defined(__BUILTIN_CPU_SUPPORTS__)
+/* good and easy */
+#else
+#include <sys/auxv.h>
+#include <bits/hwcap.h>
+int main()
+{
+ return (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07);
+}
+#endif
+#else
+#error No Power 8 or newer architecture, may need -mcpu=power8
+#endif
+EOF
+
+if tryboth $CC -c $CFLAGS $test.c; then
+ OBJC="$OBJC crc32_power8.o"
+ PIC_OBJC="$PIC_OBJC crc32_power8.lo"
+ echo "Checking for runtime cpu detection and Power 8 (or newer) Architecture support... Yes." | tee -a configure.log
+else
+ echo "Checking for runtime cpu detection and Power 8 (or newer) Architecture support... No." | tee -a configure.log
+fi
+
+# test to see if we can use a gnu indirection function to detect and load optimized code at runtime
+echo >> configure.log
+cat > $test.c <<EOF
+static unsigned int crc32_real_optimized(unsigned int crc, unsigned char *p,
+ unsigned long len)
+{
+ return 1;
+}
+static unsigned int (*(crc32_ifunc(void)))(unsigned int, unsigned char *,unsigned long)
+{
+ return crc32_real_optimized;
+}
+unsigned int crc32(unsigned int, unsigned char *,unsigned long)
+ __attribute__ ((ifunc ("crc32_ifunc")));
+EOF
+
+if tryboth $CC -c $CFLAGS $test.c; then
+ SFLAGS="${SFLAGS} -DZ_IFUNC_NATIVE"
+ echo "Checking for attribute(ifunc) support... Yes." | tee -a configure.log
+else
+ echo "Checking for attribute(ifunc) support... No." | tee -a configure.log
+
+ # alternately can we can use a gnu indirection using __asm__ attributes to detect and load optimized code at runtime
+ echo >> configure.log
+ cat > $test.c <<EOF
+static unsigned int crc32_real_optimized(unsigned int crc, unsigned char *p,
+ unsigned long len)
+{
+ return 1;
+}
+static unsigned int (*(crc32_ifunc(void)))(unsigned int, unsigned char *,unsigned long)
+ __asm__ ("crc32");
+static unsigned int (*(crc32_ifunc(void)))(unsigned int, unsigned char *,unsigned long)
+{
+ return crc32_real_optimized;
+}
+__asm__(".type crc32, %gnu_indirect_function");
+EOF
+
+ if tryboth $CC -c $CFLAGS $test.c; then
+ SFLAGS="${SFLAGS} -DZ_IFUNC_ASM"
+ echo "Checking for asm .type %gnu_indirect_function support... Yes." | tee -a configure.log
+ else
+ echo "Checking for asm .type %gnu_indirect_function support... No." | tee -a configure.log
+ fi
+fi
+
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
diff --git a/contrib/power8-crc/clang_workaround.h b/contrib/power8-crc/clang_workaround.h
if tryboth $CC -c $CFLAGS -mcpu=power8 $test.c; then
POWER8="-DZ_POWER8"
- PIC_OBJC="${PIC_OBJC}"
- OBJC="${OBJC}"
+ PIC_OBJC="${PIC_OBJC} crc32_z_power8.lo"
+ OBJC="${OBJC} crc32_z_power8.o"
echo "Checking for -mcpu=power8 support... Yes." | tee -a configure.log
else
echo "Checking for -mcpu=power8 support... No." | tee -a configure.log
diff --git a/contrib/README.contrib b/contrib/README.contrib
index 2a53f90..5411ec6 100644
--- a/contrib/README.contrib
+++ b/contrib/README.contrib
@@ -67,7 +67,8 @@ minizip/ by Gilles Vollant <info@winimage.com>
pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al.
Support for Pascal
-power/ by Matheus Castanho <msc@linux.ibm.com>
+power/ by Daniel Black <daniel@linux.ibm.com>
+ Matheus Castanho <msc@linux.ibm.com>
and Rogerio Alves <rcardoso@linux.ibm.com>
Optimized functions for Power processors
diff --git a/contrib/power/clang_workaround.h b/contrib/power/clang_workaround.h
new file mode 100644
index 0000000..09c411b
index 0000000..b5e7dae
--- /dev/null
+++ b/contrib/power8-crc/clang_workaround.h
+++ b/contrib/power/clang_workaround.h
@@ -0,0 +1,82 @@
+#ifndef CLANG_WORKAROUNDS_H
+#define CLANG_WORKAROUNDS_H
@ -217,12 +318,11 @@ index 0000000..09c411b
+#endif /* vec_xxpermdi */
+
+#endif
\ No newline at end of file
diff --git a/contrib/power8-crc/crc32_constants.h b/contrib/power8-crc/crc32_constants.h
diff --git a/contrib/power/crc32_constants.h b/contrib/power/crc32_constants.h
new file mode 100644
index 0000000..58088dc
--- /dev/null
+++ b/contrib/power8-crc/crc32_constants.h
+++ b/contrib/power/crc32_constants.h
@@ -0,0 +1,1206 @@
+/*
+*
@ -1430,12 +1530,12 @@ index 0000000..58088dc
+#endif /* POWER8_INTRINSICS */
+
+#endif /* __ASSEMBLER__ */
diff --git a/contrib/power8-crc/vec_crc32.c b/contrib/power8-crc/vec_crc32.c
diff --git a/contrib/power/crc32_z_power8.c b/contrib/power/crc32_z_power8.c
new file mode 100644
index 0000000..bb2204b
index 0000000..7858cfe
--- /dev/null
+++ b/contrib/power8-crc/vec_crc32.c
@@ -0,0 +1,674 @@
+++ b/contrib/power/crc32_z_power8.c
@@ -0,0 +1,679 @@
+/*
+ * Calculate the checksum of data that is 16 byte aligned and a multiple of
+ * 16 bytes.
@ -1468,6 +1568,8 @@ index 0000000..bb2204b
+ */
+
+#include <altivec.h>
+#include "../../zutil.h"
+#include "power.h"
+
+#define POWER8_INTRINSICS
+#define CRC_TABLE
@ -1502,16 +1604,18 @@ index 0000000..bb2204b
+static unsigned int __attribute__ ((aligned (32)))
+__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len);
+
+#ifndef CRC32_FUNCTION
+#define CRC32_FUNCTION crc32_vpmsum
+#endif
+
+unsigned int CRC32_FUNCTION(unsigned int crc, const unsigned char *p,
+ unsigned long len)
+unsigned long ZLIB_INTERNAL _crc32_z_power8(uLong _crc, const Bytef *_p,
+ z_size_t _len)
+{
+ unsigned int prealign;
+ unsigned int tail;
+
+ /* Map zlib API to crc32_vpmsum API */
+ unsigned int crc = (unsigned int) (0xffffffff & _crc);
+ const unsigned char *p = _p;
+ unsigned long len = (unsigned long) _len;
+
+ if (p == (const unsigned char *) 0x0) return 0;
+#ifdef CRC_XOR
+ crc ^= 0xffffffff;
+#endif
@ -1541,7 +1645,8 @@ index 0000000..bb2204b
+ crc ^= 0xffffffff;
+#endif
+
+ return crc;
+ /* Convert to zlib API */
+ return (unsigned long) crc;
+}
+
+#if defined (__clang__)
@ -2110,149 +2215,280 @@ index 0000000..bb2204b
+
+ return result;
+}
diff --git a/contrib/power/crc32_z_resolver.c b/contrib/power/crc32_z_resolver.c
new file mode 100644
index 0000000..f4e9aa4
--- /dev/null
+++ b/contrib/power/crc32_z_resolver.c
@@ -0,0 +1,15 @@
+/* Copyright (C) 2019 Matheus Castanho <msc@linux.ibm.com>, IBM
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "../gcc/zifunc.h"
+#include "power.h"
+
+Z_IFUNC(crc32_z) {
+#ifdef Z_POWER8
+ if (__builtin_cpu_supports("arch_2_07"))
+ return _crc32_z_power8;
+#endif
+
+ return crc32_z_default;
+}
diff --git a/contrib/power/power.h b/contrib/power/power.h
index b42c7d6..79123aa 100644
--- a/contrib/power/power.h
+++ b/contrib/power/power.h
@@ -2,3 +2,7 @@
* 2019 Rogerio Alves <rogerio.alves@ibm.com>, IBM
* For conditions of distribution and use, see copyright notice in zlib.h
*/
+
+#include "../../zconf.h"
+
+unsigned long _crc32_z_power8(unsigned long, const Bytef *, z_size_t);
diff --git a/crc32.c b/crc32.c
index 9580440..406d350 100644
index 9580440..b0cda20 100644
--- a/crc32.c
+++ b/crc32.c
@@ -199,13 +199,78 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
@@ -199,6 +199,13 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* ========================================================================= */
-unsigned long ZEXPORT crc32_z(crc, buf, len)
+local
+unsigned long ZEXPORT crc32_table_lookup(crc, buf, len)
+#ifdef Z_POWER_OPT
+/* Rename function so resolver can use its symbol. The default version will be
+ * returned by the resolver if the host has no support for an optimized version.
+ */
+#define crc32_z crc32_z_default
+#endif /* Z_POWER_OPT */
+
unsigned long ZEXPORT crc32_z(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
z_size_t len;
{
if (buf == Z_NULL) return 0UL;
+ crc = crc ^ 0xffffffffUL;
+ while (len >= 8) {
+ DO8;
+ len -= 8;
+ }
+ if (len) do {
+ DO1;
+ } while (--len);
+ return crc ^ 0xffffffffUL;
+}
+
+/* Small helper function to compare optfun against the reference table lookup
+ * return test_ref_comparision_##optfn in crc32_z_ifunc
+#include <assert.h>
+#define TEST_COMPARE(optfn) \
+ static unsigned long test_ref_comparision_ ## optfn(unsigned long crc, const unsigned char FAR *p, z_size_t len) \
+ { \
+ unsigned long crc_tbl_lookup = crc32_table_lookup(crc, p, len); \
+ unsigned long optcrc = optfn(crc, p, len); \
+ assert( optcrc == crc_tbl_lookup ); \
+ return optcrc; \
+ }
+*/
+
+#ifdef Z_IFUNC_ASM
+unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *, z_size_t)
+ __asm__ ("crc32_z");
+__asm__(".type crc32_z, %gnu_indirect_function");
+#elif defined(Z_IFUNC_NATIVE)
+unsigned long ZEXPORT crc32_z(
+ unsigned long crc,
+ const unsigned char FAR *buf,
+ z_size_t len)
+ __attribute__ ((ifunc ("crc32_z_ifunc")));
+#endif
+
+#if _ARCH_PWR8==1
+unsigned long crc32_vpmsum(unsigned long, const unsigned char FAR *, z_size_t);
+/* for testing TEST_COMPARE(crc32_vpmsum) */
+#ifndef __BUILTIN_CPU_SUPPORTS__
+#include <sys/auxv.h>
+#include <bits/hwcap.h>
+#endif
+#endif
+
+/* due to a quirk of gnu_indirect_function - "local" (aka static) is applied to
+ * crc32_z which is not desired. crc32_z_ifunc is implictly "local" */
+#ifndef Z_IFUNC_ASM
+local
+#endif
+unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *, z_size_t)
+{
+#if _ARCH_PWR8==1
+#if defined(__BUILTIN_CPU_SUPPORTS__)
+ if (__builtin_cpu_supports("arch_2_07"))
+ return crc32_vpmsum;
+#else
+ if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07)
+ return crc32_vpmsum;
+#endif
+#endif /* _ARCH_PWR8 */
+
+/* return a function pointer for optimized arches here */
+
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
@@ -217,22 +282,31 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
endian = 1;
if (*((unsigned char *)(&endian)))
- return crc32_little(crc, buf, len);
+ return crc32_little;
else
- return crc32_big(crc, buf, len);
+ return crc32_big;
}
#endif /* BYFOUR */
- crc = crc ^ 0xffffffffUL;
- while (len >= 8) {
- DO8;
- len -= 8;
- }
- if (len) do {
- DO1;
- } while (--len);
- return crc ^ 0xffffffffUL;
+
+ return crc32_table_lookup;
@@ -233,6 +240,11 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
return crc ^ 0xffffffffUL;
}
+#if !defined(Z_IFUNC_ASM) && !defined(Z_IFUNC_NATIVE)
+
+unsigned long ZEXPORT crc32_z(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ z_size_t len;
+{
+ static unsigned long ZEXPORT (*crc32_func)(unsigned long, const unsigned char FAR *, z_size_t) = NULL;
+
+ if (!crc32_func)
+ crc32_func = crc32_z_ifunc();
+ return (*crc32_func)(crc, buf, len);
+}
+
+#endif /* defined(Z_IFUNC_ASM) || defined(Z_IFUNC_NATIVE) */
+#ifdef Z_POWER_OPT
+#undef crc32_z
+#include "contrib/power/crc32_z_resolver.c"
+#endif /* Z_POWER_OPT */
+
/* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc;
@@ -271,6 +345,7 @@ local unsigned long crc32_little(crc, buf, len)
register z_crc_t c;
register const z_crc_t FAR *buf4;
+ if (buf == Z_NULL) return 0UL;
c = (z_crc_t)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
@@ -311,6 +386,7 @@ local unsigned long crc32_big(crc, buf, len)
register z_crc_t c;
register const z_crc_t FAR *buf4;
+ if (buf == Z_NULL) return 0UL;
c = ZSWAP32((z_crc_t)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
diff --git a/test/crc32_test.c b/test/crc32_test.c
new file mode 100644
index 0000000..3155553
--- /dev/null
+++ b/test/crc32_test.c
@@ -0,0 +1,205 @@
+/* crc32_tes.c -- unit test for crc32 in the zlib compression library
+ * Copyright (C) 1995-2006, 2010, 2011, 2016, 2019 Rogerio Alves
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zlib.h"
+#include <stdio.h>
+
+#ifdef STDC
+# include <string.h>
+# include <stdlib.h>
+#endif
+
+void test_crc32 OF((uLong crc, Byte* buf, z_size_t len, uLong chk, int line));
+int main OF((void));
+
+typedef struct {
+ int line;
+ uLong crc;
+ char* buf;
+ int len;
+ uLong expect;
+} crc32_test;
+
+void test_crc32(crc, buf, len, chk, line)
+ uLong crc;
+ Byte *buf;
+ z_size_t len;
+ uLong chk;
+ int line;
+{
+ uLong res = crc32(crc, buf, len);
+ if (res != chk) {
+ fprintf(stderr, "FAIL [%d]: crc32 returned 0x%08X expected 0x%08X\n",
+ line, (unsigned int)res, (unsigned int)chk);
+ exit(1);
+ }
+}
+
+static const crc32_test tests[] = {
+ {__LINE__, 0x0, 0x0, 0, 0x0},
+ {__LINE__, 0xffffffff, 0x0, 0, 0x0},
+ {__LINE__, 0x0, 0x0, 255, 0x0}, /* BZ 174799. */
+ {__LINE__, 0x0, 0x0, 256, 0x0},
+ {__LINE__, 0x0, 0x0, 257, 0x0},
+ {__LINE__, 0x0, 0x0, 32767, 0x0},
+ {__LINE__, 0x0, 0x0, 32768, 0x0},
+ {__LINE__, 0x0, 0x0, 32769, 0x0},
+ {__LINE__, 0x0, "", 0, 0x0},
+ {__LINE__, 0xffffffff, "", 0, 0xffffffff},
+ {__LINE__, 0x0, "abacus", 6, 0xc3d7115b},
+ {__LINE__, 0x0, "backlog", 7, 0x269205},
+ {__LINE__, 0x0, "campfire", 8, 0x22a515f8},
+ {__LINE__, 0x0, "delta", 5, 0x9643fed9},
+ {__LINE__, 0x0, "executable", 10, 0xd68eda01},
+ {__LINE__, 0x0, "file", 4, 0x8c9f3610},
+ {__LINE__, 0x0, "greatest", 8, 0xc1abd6cd},
+ {__LINE__, 0x0, "hello", 5, 0x3610a686},
+ {__LINE__, 0x0, "inverter", 8, 0xc9e962c9},
+ {__LINE__, 0x0, "jigsaw", 6, 0xce4e3f69},
+ {__LINE__, 0x0, "karate", 6, 0x890be0e2},
+ {__LINE__, 0x0, "landscape", 9, 0xc4e0330b},
+ {__LINE__, 0x0, "machine", 7, 0x1505df84},
+ {__LINE__, 0x0, "nanometer", 9, 0xd4e19f39},
+ {__LINE__, 0x0, "oblivion", 8, 0xdae9de77},
+ {__LINE__, 0x0, "panama", 6, 0x66b8979c},
+ {__LINE__, 0x0, "quest", 5, 0x4317f817},
+ {__LINE__, 0x0, "resource", 8, 0xbc91f416},
+ {__LINE__, 0x0, "secret", 6, 0x5ca2e8e5},
+ {__LINE__, 0x0, "test", 4, 0xd87f7e0c},
+ {__LINE__, 0x0, "ultimate", 8, 0x3fc79b0b},
+ {__LINE__, 0x0, "vector", 6, 0x1b6e485b},
+ {__LINE__, 0x0, "walrus", 6, 0xbe769b97},
+ {__LINE__, 0x0, "xeno", 4, 0xe7a06444},
+ {__LINE__, 0x0, "yelling", 7, 0xfe3944e5},
+ {__LINE__, 0x0, "zlib", 4, 0x73887d3a},
+ {__LINE__, 0x0, "4BJD7PocN1VqX0jXVpWB", 20, 0xd487a5a1},
+ {__LINE__, 0x0, "F1rPWI7XvDs6nAIRx41l", 20, 0x61a0132e},
+ {__LINE__, 0x0, "ldhKlsVkPFOveXgkGtC2", 20, 0xdf02f76},
+ {__LINE__, 0x0, "5KKnGOOrs8BvJ35iKTOS", 20, 0x579b2b0a},
+ {__LINE__, 0x0, "0l1tw7GOcem06Ddu7yn4", 20, 0xf7d16e2d},
+ {__LINE__, 0x0, "MCr47CjPIn9R1IvE1Tm5", 20, 0x731788f5},
+ {__LINE__, 0x0, "UcixbzPKTIv0SvILHVdO", 20, 0x7112bb11},
+ {__LINE__, 0x0, "dGnAyAhRQDsWw0ESou24", 20, 0xf32a0dac},
+ {__LINE__, 0x0, "di0nvmY9UYMYDh0r45XT", 20, 0x625437bb},
+ {__LINE__, 0x0, "2XKDwHfAhFsV0RhbqtvH", 20, 0x896930f9},
+ {__LINE__, 0x0, "ZhrANFIiIvRnqClIVyeD", 20, 0x8579a37},
+ {__LINE__, 0x0, "v7Q9ehzioTOVeDIZioT1", 20, 0x632aa8e0},
+ {__LINE__, 0x0, "Yod5hEeKcYqyhfXbhxj2", 20, 0xc829af29},
+ {__LINE__, 0x0, "GehSWY2ay4uUKhehXYb0", 20, 0x1b08b7e8},
+ {__LINE__, 0x0, "kwytJmq6UqpflV8Y8GoE", 20, 0x4e33b192},
+ {__LINE__, 0x0, "70684206568419061514", 20, 0x59a179f0},
+ {__LINE__, 0x0, "42015093765128581010", 20, 0xcd1013d7},
+ {__LINE__, 0x0, "88214814356148806939", 20, 0xab927546},
+ {__LINE__, 0x0, "43472694284527343838", 20, 0x11f3b20c},
+ {__LINE__, 0x0, "49769333513942933689", 20, 0xd562d4ca},
+ {__LINE__, 0x0, "54979784887993251199", 20, 0x233395f7},
+ {__LINE__, 0x0, "58360544869206793220", 20, 0x2d167fd5},
+ {__LINE__, 0x0, "27347953487840714234", 20, 0x8b5108ba},
+ {__LINE__, 0x0, "07650690295365319082", 20, 0xc46b3cd8},
+ {__LINE__, 0x0, "42655507906821911703", 20, 0xc10b2662},
+ {__LINE__, 0x0, "29977409200786225655", 20, 0xc9a0f9d2},
+ {__LINE__, 0x0, "85181542907229116674", 20, 0x9341357b},
+ {__LINE__, 0x0, "87963594337989416799", 20, 0xf0424937},
+ {__LINE__, 0x0, "21395988329504168551", 20, 0xd7c4c31f},
+ {__LINE__, 0x0, "51991013580943379423", 20, 0xf11edcc4},
+ {__LINE__, 0x0, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x40795df4},
+ {__LINE__, 0x0, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0xdd61a631},
+ {__LINE__, 0x0, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xca907a99},
+ {__LINE__, 0x0, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0xf652deac},
+ {__LINE__, 0x0, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0xaf39a5a9},
+ {__LINE__, 0x0, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x6bebb4cf},
+ {__LINE__, 0x0, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0x76430bac},
+ {__LINE__, 0x0, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x6c80c388},
+ {__LINE__, 0x0, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xd54d977d},
+ {__LINE__, 0x0, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0xe3966ad5},
+ {__LINE__, 0x0, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xe7c71db9},
+ {__LINE__, 0x0, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xeaa52777},
+ {__LINE__, 0x0, "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%&", 100, 0xcd472048},
+ {__LINE__, 0x7a30360d, "abacus", 6, 0xf8655a84},
+ {__LINE__, 0x6fd767ee, "backlog", 7, 0x1ed834b1},
+ {__LINE__, 0xefeb7589, "campfire", 8, 0x686cfca},
+ {__LINE__, 0x61cf7e6b, "delta", 5, 0x1554e4b1},
+ {__LINE__, 0xdc712e2, "executable", 10, 0x761b4254},
+ {__LINE__, 0xad23c7fd, "file", 4, 0x7abdd09b},
+ {__LINE__, 0x85cb2317, "greatest", 8, 0x4ba91c6b},
+ {__LINE__, 0x9eed31b0, "inverter", 8, 0xd5e78ba5},
+ {__LINE__, 0xb94f34ca, "jigsaw", 6, 0x23649109},
+ {__LINE__, 0xab058a2, "karate", 6, 0xc5591f41},
+ {__LINE__, 0x5bff2b7a, "landscape", 9, 0xf10eb644},
+ {__LINE__, 0x605c9a5f, "machine", 7, 0xbaa0a636},
+ {__LINE__, 0x51bdeea5, "nanometer", 9, 0x6af89afb},
+ {__LINE__, 0x85c21c79, "oblivion", 8, 0xecae222b},
+ {__LINE__, 0x97216f56, "panama", 6, 0x47dffac4},
+ {__LINE__, 0x18444af2, "quest", 5, 0x70c2fe36},
+ {__LINE__, 0xbe6ce359, "resource", 8, 0x1471d925},
+ {__LINE__, 0x843071f1, "secret", 6, 0x50c9a0db},
+ {__LINE__, 0xf2480c60, "ultimate", 8, 0xf973daf8},
+ {__LINE__, 0x2d2feb3d, "vector", 6, 0x344ac03d},
+ {__LINE__, 0x7490310a, "walrus", 6, 0x6d1408ef},
+ {__LINE__, 0x97d247d4, "xeno", 4, 0xe62670b5},
+ {__LINE__, 0x93cf7599, "yelling", 7, 0x1b36da38},
+ {__LINE__, 0x73c84278, "zlib", 4, 0x6432d127},
+ {__LINE__, 0x228a87d1, "4BJD7PocN1VqX0jXVpWB", 20, 0x997107d0},
+ {__LINE__, 0xa7a048d0, "F1rPWI7XvDs6nAIRx41l", 20, 0xdc567274},
+ {__LINE__, 0x1f0ded40, "ldhKlsVkPFOveXgkGtC2", 20, 0xdcc63870},
+ {__LINE__, 0xa804a62f, "5KKnGOOrs8BvJ35iKTOS", 20, 0x6926cffd},
+ {__LINE__, 0x508fae6a, "0l1tw7GOcem06Ddu7yn4", 20, 0xb52b38bc},
+ {__LINE__, 0xe5adaf4f, "MCr47CjPIn9R1IvE1Tm5", 20, 0xf83b8178},
+ {__LINE__, 0x67136a40, "UcixbzPKTIv0SvILHVdO", 20, 0xc5213070},
+ {__LINE__, 0xb00c4a10, "dGnAyAhRQDsWw0ESou24", 20, 0xbc7648b0},
+ {__LINE__, 0x2e0c84b5, "di0nvmY9UYMYDh0r45XT", 20, 0xd8123a72},
+ {__LINE__, 0x81238d44, "2XKDwHfAhFsV0RhbqtvH", 20, 0xd5ac5620},
+ {__LINE__, 0xf853aa92, "ZhrANFIiIvRnqClIVyeD", 20, 0xceae099d},
+ {__LINE__, 0x5a692325, "v7Q9ehzioTOVeDIZioT1", 20, 0xb07d2b24},
+ {__LINE__, 0x3275b9f, "Yod5hEeKcYqyhfXbhxj2", 20, 0x24ce91df},
+ {__LINE__, 0x38371feb, "GehSWY2ay4uUKhehXYb0", 20, 0x707b3b30},
+ {__LINE__, 0xafc8bf62, "kwytJmq6UqpflV8Y8GoE", 20, 0x16abc6a9},
+ {__LINE__, 0x9b07db73, "70684206568419061514", 20, 0xae1fb7b7},
+ {__LINE__, 0xe75b214, "42015093765128581010", 20, 0xd4eecd2d},
+ {__LINE__, 0x72d0fe6f, "88214814356148806939", 20, 0x4660ec7},
+ {__LINE__, 0xf857a4b1, "43472694284527343838", 20, 0xfd8afdf7},
+ {__LINE__, 0x54b8e14, "49769333513942933689", 20, 0xc6d1b5f2},
+ {__LINE__, 0xd6aa5616, "54979784887993251199", 20, 0x32476461},
+ {__LINE__, 0x11e63098, "58360544869206793220", 20, 0xd917cf1a},
+ {__LINE__, 0xbe92385, "27347953487840714234", 20, 0x4ad14a12},
+ {__LINE__, 0x49511de0, "07650690295365319082", 20, 0xe37b5c6c},
+ {__LINE__, 0x3db13bc1, "42655507906821911703", 20, 0x7cc497f1},
+ {__LINE__, 0xbb899bea, "29977409200786225655", 20, 0x99781bb2},
+ {__LINE__, 0xf6cd9436, "85181542907229116674", 20, 0x132256a1},
+ {__LINE__, 0x9109e6c3, "87963594337989416799", 20, 0xbfdb2c83},
+ {__LINE__, 0x75770fc, "21395988329504168551", 20, 0x8d9d1e81},
+ {__LINE__, 0x69b1d19b, "51991013580943379423", 20, 0x7b6d4404},
+ {__LINE__, 0xc6132975, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x8619f010},
+ {__LINE__, 0xd58cb00c, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0x15746ac3},
+ {__LINE__, 0xb63b8caa, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xaccf812f},
+ {__LINE__, 0x8a45a2b8, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0x78af45de},
+ {__LINE__, 0xcbe95b78, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0x25b06b59},
+ {__LINE__, 0x4ef8a54b, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x4ba0d08f},
+ {__LINE__, 0x76ad267a, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0xe26b6aac},
+ {__LINE__, 0x569e613c, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x7e2b0a66},
+ {__LINE__, 0x36aa61da, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xb3430dc7},
+ {__LINE__, 0xf67222df, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0x626c17a},
+ {__LINE__, 0x74b34fd3, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xccf98060},
+ {__LINE__, 0x351fd770, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xd8b95312},
+ {__LINE__, 0xc45aef77, "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%&", 100, 0xbb1c9912},
+ {__LINE__, 0xc45aef77, "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%&"
+ "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%&"
+ "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%&"
+ "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%&"
+ "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%&"
+ "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%&", 600, 0x888AFA5B}
+};
+
+static const int test_size = sizeof(tests) / sizeof(tests[0]);
+
+int main(void)
+{
+ int i;
+ for (i = 0; i < test_size; i++) {
+ test_crc32(tests[i].crc, (Byte*) tests[i].buf, tests[i].len,
+ tests[i].expect, tests[i].line);
+ }
+ return 0;
+}
--
2.19.1
2.39.1

View File

@ -0,0 +1,73 @@
From 5eaae2af0defeca148c2a281873bb31a15246876 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:34:24 +0100
Subject: [PATCH] 2155328
---
contrib/s390/dfltcc.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/contrib/s390/dfltcc.c b/contrib/s390/dfltcc.c
index 72099e7..f8dc21c 100644
--- a/contrib/s390/dfltcc.c
+++ b/contrib/s390/dfltcc.c
@@ -456,7 +456,10 @@ again:
*strm->next_out = (Bytef)state->bi_buf;
/* Honor history and check value */
param->nt = 0;
- param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler;
+ if (state->wrap == 1)
+ param->cv = strm->adler;
+ else if (state->wrap == 2)
+ param->cv = ZSWAP32(strm->adler);
/* When opening a block, choose a Huffman-Table Type */
if (!param->bcf) {
@@ -488,7 +491,10 @@ again:
state->bi_buf = 0; /* Avoid accessing next_out */
else
state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1);
- strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv;
+ if (state->wrap == 1)
+ strm->adler = param->cv;
+ else if (state->wrap == 2)
+ strm->adler = ZSWAP32(param->cv);
/* Unmask the input data */
strm->avail_in += masked_avail_in;
@@ -600,11 +606,12 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
}
/* Translate stream to parameter block */
- param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32;
+ param->cvt = ((state->wrap & 4) && state->flags) ? CVT_CRC32 : CVT_ADLER32;
param->sbb = state->bits;
if (param->hl)
param->nt = 0; /* Honor history for the first block */
- param->cv = state->flags ? ZSWAP32(state->check) : state->check;
+ if (state->wrap & 4)
+ param->cv = state->flags ? ZSWAP32(state->check) : state->check;
/* Inflate */
do {
@@ -615,7 +622,9 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
state->last = cc == DFLTCC_CC_OK;
state->bits = param->sbb;
- strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
+ if (state->wrap & 4)
+ strm->adler = state->check = state->flags ?
+ ZSWAP32(param->cv) : param->cv;
if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
/* Report an error if stream is corrupted */
state->mode = BAD;
@@ -1077,4 +1086,4 @@ int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(strm, dictionary, dict_length)
if (dict_length)
*dict_length = param->hl;
return Z_OK;
-}
\ No newline at end of file
+}
--
2.39.1

View File

@ -0,0 +1,54 @@
From 480b65cae6c20a41aa698a6c9d3b260f6f744004 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:41:32 +0100
Subject: [PATCH] 0003-PATCH-Fix-clang-s-behavior-on-versions-7.patch
---
contrib/power/clang_workaround.h | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/contrib/power/clang_workaround.h b/contrib/power/clang_workaround.h
index b5e7dae..915f7e5 100644
--- a/contrib/power/clang_workaround.h
+++ b/contrib/power/clang_workaround.h
@@ -39,7 +39,12 @@ __vector unsigned long long __builtin_pack_vector (unsigned long __a,
return __v;
}
-#ifndef vec_xxpermdi
+/*
+ * Clang 7 changed the behavior of vec_xxpermdi in order to provide the same
+ * behavior of GCC. That means code adapted to Clang >= 7 does not work on
+ * Clang <= 6. So, fallback to __builtin_unpack_vector() on Clang <= 6.
+ */
+#if !defined vec_xxpermdi || __clang_major__ <= 6
static inline
unsigned long __builtin_unpack_vector (__vector unsigned long long __v,
@@ -62,9 +67,9 @@ static inline
unsigned long __builtin_unpack_vector_0 (__vector unsigned long long __v)
{
#if defined(__BIG_ENDIAN__)
- return vec_xxpermdi(__v, __v, 0x0)[1];
- #else
return vec_xxpermdi(__v, __v, 0x0)[0];
+ #else
+ return vec_xxpermdi(__v, __v, 0x3)[0];
#endif
}
@@ -72,9 +77,9 @@ static inline
unsigned long __builtin_unpack_vector_1 (__vector unsigned long long __v)
{
#if defined(__BIG_ENDIAN__)
- return vec_xxpermdi(__v, __v, 0x3)[1];
- #else
return vec_xxpermdi(__v, __v, 0x3)[0];
+ #else
+ return vec_xxpermdi(__v, __v, 0x0)[0];
#endif
}
#endif /* vec_xxpermdi */
--
2.39.1

View File

@ -1,3 +1,6 @@
Source from https://gitlab.com/redhat/centos-stream/rpms/zlib/-/merge_requests/9
Author: Ilya Leoshkevich
--- a/compress.c
+++ b/compress.c
@@ -5,9 +5,15 @@

View File

@ -0,0 +1,17 @@
--- zlib-1.2.11/contrib/s390/dfltcc_deflate.h.old 2023-05-04 09:39:23.423753908 +0000
+++ zlib-1.2.11/contrib/s390/dfltcc_deflate.h 2023-05-04 09:39:48.087753908 +0000
@@ -45,11 +45,11 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dic
#define DEFLATE_DONE dfltcc_deflate_done
#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
do { \
- if (dfltcc_can_deflate((strm))) \
+ if (deflateStateCheck((strm)) || dfltcc_can_deflate((strm))) \
(complen) = DEFLATE_BOUND_COMPLEN(source_len); \
} while (0)
#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
#define DEFLATE_HOOK dfltcc_deflate
#define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
-#endif
\ No newline at end of file
+#endif

View File

@ -0,0 +1,11 @@
--- a/contrib/s390/dfltcc.c
+++ b/contrib/s390/dfltcc.c
@@ -623,7 +623,7 @@
state->bits = param->sbb;
state->whave = param->hl;
state->wnext = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
- state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
+ strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
/* Report an error if stream is corrupted */
state->mode = BAD;

View File

@ -0,0 +1,299 @@
--- a/contrib/s390/dfltcc.c
+++ b/contrib/s390/dfltcc.c
@@ -539,10 +539,6 @@ int ZLIB_INTERNAL dfltcc_can_inflate(strm)
struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
- /* Unsupported compression settings */
- if (state->wbits != HB_BITS)
- return 0;
-
/* Unsupported hardware */
return is_bit_set(dfltcc_state->af.fns, DFLTCC_XPND) &&
is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0);
@@ -606,8 +602,6 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
/* Translate stream to parameter block */
param->cvt = state->flags ? CVT_CRC32 : CVT_ADLER32;
param->sbb = state->bits;
- param->hl = state->whave; /* Software and hardware history formats match */
- param->ho = (state->wnext - state->whave) & ((1 << HB_BITS) - 1);
if (param->hl)
param->nt = 0; /* Honor history for the first block */
param->cv = state->flags ? ZSWAP32(state->check) : state->check;
@@ -621,8 +615,6 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(strm, flush, ret)
strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
state->last = cc == DFLTCC_CC_OK;
state->bits = param->sbb;
- state->whave = param->hl;
- state->wnext = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
strm->adler = state->check = state->flags ? ZSWAP32(param->cv) : param->cv;
if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
/* Report an error if stream is corrupted */
@@ -644,11 +636,52 @@ int ZLIB_INTERNAL dfltcc_was_inflate_used(strm)
return !param->nt;
}
+/*
+ Rotates a circular buffer.
+ The implementation is based on https://cplusplus.com/reference/algorithm/rotate/
+ */
+local void rotate OF((Bytef *start, Bytef *pivot, Bytef *end));
+local void rotate(start, pivot, end)
+ Bytef *start;
+ Bytef *pivot;
+ Bytef *end;
+{
+ Bytef *p = pivot;
+ Bytef tmp;
+
+ while (p != start) {
+ tmp = *start;
+ *start = *p;
+ *p = tmp;
+
+ start++;
+ p++;
+
+ if (p == end)
+ p = pivot;
+ else if (start == pivot)
+ pivot = p;
+ }
+}
+
+#define MIN(x, y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ _x < _y ? _x : _y; \
+})
+
+#define MAX(x, y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ _x > _y ? _x : _y; \
+})
+
int ZLIB_INTERNAL dfltcc_inflate_disable(strm)
z_streamp strm;
{
struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
+ struct dfltcc_param_v0 *param = &dfltcc_state->param;
if (!dfltcc_can_inflate(strm))
return 0;
@@ -660,6 +693,9 @@ int ZLIB_INTERNAL dfltcc_inflate_disable(strm)
return 1;
/* DFLTCC was not used yet - decompress in software */
memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af));
+ /* Convert the window from the hardware to the software format */
+ rotate(state->window, state->window + param->ho, state->window + HB_SIZE);
+ state->whave = state->wnext = MIN(param->hl, state->wsize);
return 0;
}
@@ -830,9 +866,9 @@ voidpf ZLIB_INTERNAL dfltcc_alloc_window(strm, items, size)
voidpf p, w;
/* To simplify freeing, we store the pointer to the allocated buffer right
- * before the window.
+ * before the window. Note that DFLTCC always uses HB_SIZE bytes.
*/
- p = ZALLOC(strm, sizeof(voidpf) + items * size + PAGE_ALIGN,
+ p = ZALLOC(strm, sizeof(voidpf) + MAX(items * size, HB_SIZE) + PAGE_ALIGN,
sizeof(unsigned char));
if (p == NULL)
return NULL;
@@ -841,6 +877,14 @@ voidpf ZLIB_INTERNAL dfltcc_alloc_window(strm, items, size)
return w;
}
+void ZLIB_INTERNAL dfltcc_copy_window(dest, src, n)
+ void *dest;
+ const void *src;
+ size_t n;
+{
+ memcpy(dest, src, MAX(n, HB_SIZE));
+}
+
void ZLIB_INTERNAL dfltcc_free_window(strm, w)
z_streamp strm;
voidpf w;
@@ -951,6 +995,24 @@ local void append_history(param, history, buf, count)
}
}
+local void get_history OF((struct dfltcc_param_v0 FAR *param,
+ const Bytef *history,
+ Bytef *buf));
+local void get_history(param, history, buf)
+ struct dfltcc_param_v0 FAR *param;
+ const Bytef *history;
+ Bytef *buf;
+{
+ if (param->ho + param->hl <= HB_SIZE)
+ /* Circular history buffer does not wrap - copy one chunk */
+ memcpy(buf, history + param->ho, param->hl);
+ else {
+ /* Circular history buffer wraps - copy two chunks */
+ memcpy(buf, history + param->ho, HB_SIZE - param->ho);
+ memcpy(buf + HB_SIZE - param->ho, history, param->ho + param->hl - HB_SIZE);
+ }
+}
+
int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(strm, dictionary, dict_length)
z_streamp strm;
const Bytef *dictionary;
@@ -975,20 +1037,43 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(strm, dictionary, dict_length)
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 FAR *param = &dfltcc_state->param;
- if (dictionary) {
- if (param->ho + param->hl <= HB_SIZE)
- /* Circular history buffer does not wrap - copy one chunk */
- zmemcpy(dictionary, state->window + param->ho, param->hl);
- else {
- /* Circular history buffer wraps - copy two chunks */
- zmemcpy(dictionary,
- state->window + param->ho,
- HB_SIZE - param->ho);
- zmemcpy(dictionary + HB_SIZE - param->ho,
- state->window,
- param->ho + param->hl - HB_SIZE);
- }
+ if (dictionary)
+ get_history(param, state->window, dictionary);
+ if (dict_length)
+ *dict_length = param->hl;
+ return Z_OK;
+}
+
+int ZLIB_INTERNAL dfltcc_inflate_set_dictionary(strm, dictionary, dict_length)
+ z_streamp strm;
+ const Bytef *dictionary;
+ uInt dict_length;
+{
+ struct inflate_state *state = (struct inflate_state *)strm->state;
+ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
+ struct dfltcc_param_v0 *param = &dfltcc_state->param;
+
+ if (inflate_ensure_window(state)) {
+ state->mode = MEM;
+ return Z_MEM_ERROR;
}
+
+ append_history(param, state->window, dictionary, dict_length);
+ state->havedict = 1;
+ return Z_OK;
+}
+
+int ZLIB_INTERNAL dfltcc_inflate_get_dictionary(strm, dictionary, dict_length)
+ z_streamp strm;
+ Bytef *dictionary;
+ uInt *dict_length;
+{
+ struct inflate_state *state = (struct inflate_state *)strm->state;
+ struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
+ struct dfltcc_param_v0 *param = &dfltcc_state->param;
+
+ if (dictionary && state->window)
+ get_history(param, state->window, dictionary);
if (dict_length)
*dict_length = param->hl;
return Z_OK;
--- a/contrib/s390/dfltcc.h
+++ b/contrib/s390/dfltcc.h
@@ -11,6 +11,8 @@ void ZLIB_INTERNAL dfltcc_copy_state OF((voidpf dst, const voidpf src,
void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size));
voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items,
uInt size));
+void ZLIB_INTERNAL dfltcc_copy_window OF((void *dest, const void *src,
+ size_t n));
void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w));
#define DFLTCC_BLOCK_HEADER_BITS 3
#define DFLTCC_HLITS_COUNT_BITS 5
@@ -44,11 +46,18 @@ dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate OF((z_streamp strm,
int flush, int *ret));
int ZLIB_INTERNAL dfltcc_was_inflate_used OF((z_streamp strm));
int ZLIB_INTERNAL dfltcc_inflate_disable OF((z_streamp strm));
+int ZLIB_INTERNAL dfltcc_inflate_set_dictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dict_length));
+int ZLIB_INTERNAL dfltcc_inflate_get_dictionary OF((z_streamp strm,
+ Bytef *dictionary,
+ uInt* dict_length));
#define ZALLOC_STATE dfltcc_alloc_state
#define ZFREE_STATE ZFREE
#define ZCOPY_STATE dfltcc_copy_state
#define ZALLOC_WINDOW dfltcc_alloc_window
+#define ZCOPY_WINDOW dfltcc_copy_window
#define ZFREE_WINDOW dfltcc_free_window
#define TRY_FREE_WINDOW dfltcc_free_window
#define INFLATE_RESET_KEEP_HOOK(strm) \
@@ -77,5 +86,15 @@ int ZLIB_INTERNAL dfltcc_inflate_disable OF((z_streamp strm));
do { \
if (dfltcc_was_inflate_used((strm))) return Z_STREAM_ERROR; \
} while (0)
+#define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \
+ do { \
+ if (dfltcc_can_inflate(strm)) \
+ return dfltcc_inflate_set_dictionary(strm, dict, dict_len); \
+ } while (0)
+#define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) \
+ do { \
+ if (dfltcc_can_inflate(strm)) \
+ return dfltcc_inflate_get_dictionary(strm, dict, dict_len); \
+ } while (0)
#endif
\ No newline at end of file
diff --git a/inflate.c b/inflate.c
index 3750152..a0e2169 100644
--- a/inflate.c
+++ b/inflate.c
@@ -93,6 +93,7 @@
#define ZFREE_STATE ZFREE
#define ZCOPY_STATE zmemcpy
#define ZALLOC_WINDOW ZALLOC
+#define ZCOPY_WINDOW zmemcpy
#define ZFREE_WINDOW ZFREE
#define INFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
#define INFLATE_PRIME_HOOK(strm, bits, value) do {} while (0)
@@ -101,6 +102,8 @@
#define INFLATE_NEED_UPDATEWINDOW(strm) 1
#define INFLATE_MARK_HOOK(strm) do {} while (0)
#define INFLATE_SYNC_POINT_HOOK(strm) do {} while (0)
+#define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
+#define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
#endif
#ifdef MAKEFIXED
@@ -1330,6 +1333,8 @@ uInt *dictLength;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
+ INFLATE_GET_DICTIONARY_HOOK(strm, dictionary, dictLength);
+
/* copy dictionary */
if (state->whave && dictionary != Z_NULL) {
zmemcpy(dictionary, state->window + state->wnext,
@@ -1365,6 +1370,8 @@ uInt dictLength;
return Z_DATA_ERROR;
}
+ INFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength);
+
/* copy dictionary to window using updatewindow(), which will amend the
existing dictionary if appropriate */
ret = updatewindow(strm, dictionary + dictLength, dictLength);
@@ -1529,8 +1536,7 @@ z_streamp source;
}
copy->next = copy->codes + (state->next - state->codes);
if (window != Z_NULL) {
- wsize = 1U << state->wbits;
- zmemcpy(window, state->window, wsize);
+ ZCOPY_WINDOW(window, state->window, 1U << state->wbits);
}
copy->window = window;
dest->state = (struct internal_state FAR *)copy;

View File

@ -0,0 +1,69 @@
From 2d80d3f6b52f9fa454c26c89d2d6a1790e1cecb0 Mon Sep 17 00:00:00 2001
From: Mark Adler <madler@alumni.caltech.edu>
Date: Sat, 21 Jan 2017 01:50:26 -0800
Subject: [PATCH] Limit hash table inserts after switch from stored deflate.
This limits hash table inserts to the available data in the window
and to the sliding window size in deflate_stored(). The hash table
inserts are deferred until deflateParams() switches to a non-zero
compression level.
---
deflate.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/deflate.c b/deflate.c
index 20bda4f..d368b25 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1513,6 +1513,8 @@ local void fill_window(s)
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
+ if (s->insert > s->strstart)
+ s->insert = s->strstart;
slide_hash(s);
more += wsize;
}
@@ -1742,6 +1744,7 @@ local block_state deflate_stored(s, flush)
s->matches = 2; /* clear hash */
zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
s->strstart = s->w_size;
+ s->insert = s->strstart;
}
else {
if (s->window_size - s->strstart <= used) {
@@ -1750,12 +1753,14 @@ local block_state deflate_stored(s, flush)
zmemcpy(s->window, s->window + s->w_size, s->strstart);
if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */
+ if (s->insert > s->strstart)
+ s->insert = s->strstart;
}
zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
s->strstart += used;
+ s->insert += MIN(used, s->w_size - s->insert);
}
s->block_start = s->strstart;
- s->insert += MIN(used, s->w_size - s->insert);
}
if (s->high_water < s->strstart)
s->high_water = s->strstart;
@@ -1779,12 +1784,15 @@ local block_state deflate_stored(s, flush)
if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */
have += s->w_size; /* more space now */
+ if (s->insert > s->strstart)
+ s->insert = s->strstart;
}
if (have > s->strm->avail_in)
have = s->strm->avail_in;
if (have) {
read_buf(s->strm, s->window + s->strstart, have);
s->strstart += have;
+ s->insert += MIN(have, s->w_size - s->insert);
}
if (s->high_water < s->strstart)
s->high_water = s->strstart;
--
2.39.1

View File

@ -0,0 +1,282 @@
From 14730a26e830eb2b09d1f7097910616f23c1476e Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 2 Feb 2023 19:40:32 +0100
Subject: [PATCH] 0001-PATCH-Preparation-for-Power-optimizations.patch
---
CMakeLists.txt | 67 ++++++++++++++++++++++++++++++++++++++++++
configure | 66 +++++++++++++++++++++++++++++++++++++++++
contrib/README.contrib | 8 +++++
contrib/gcc/zifunc.h | 60 +++++++++++++++++++++++++++++++++++++
contrib/power/power.h | 4 +++
5 files changed, 205 insertions(+)
create mode 100644 contrib/gcc/zifunc.h
create mode 100644 contrib/power/power.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0fe939d..e762023 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,7 @@ set(VERSION "1.2.11")
option(ASM686 "Enable building i686 assembly implementation")
option(AMD64 "Enable building amd64 assembly implementation")
+option(POWER "Enable building power implementation")
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
@@ -140,6 +141,72 @@ if(CMAKE_COMPILER_IS_GNUCC)
add_definitions(-DASMV)
set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
endif()
+
+ # test to see if we can use a GNU indirect function to detect and load optimized code at runtime
+ CHECK_C_SOURCE_COMPILES("
+ static int test_ifunc_native(void)
+ {
+ return 1;
+ }
+ static int (*(check_ifunc_native(void)))(void)
+ {
+ return test_ifunc_native;
+ }
+ int test_ifunc(void) __attribute__ ((ifunc (\"check_ifunc_native\")));
+ int main(void)
+ {
+ return 0;
+ }
+ " HAS_C_ATTR_IFUNC)
+
+ if(HAS_C_ATTR_IFUNC)
+ add_definitions(-DHAVE_IFUNC)
+ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/gcc/zifunc.h)
+ endif()
+
+ if(POWER)
+ # Test to see if we can use the optimizations for Power
+ CHECK_C_SOURCE_COMPILES("
+ #ifndef _ARCH_PPC
+ #error \"Target is not Power\"
+ #endif
+ #ifndef __BUILTIN_CPU_SUPPORTS__
+ #error \"Target doesn't support __builtin_cpu_supports()\"
+ #endif
+ int main() { return 0; }
+ " HAS_POWER_SUPPORT)
+
+ if(HAS_POWER_SUPPORT AND HAS_C_ATTR_IFUNC)
+ add_definitions(-DZ_POWER_OPT)
+
+ set(CMAKE_REQUIRED_FLAGS -mcpu=power8)
+ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER8)
+
+ if(POWER8)
+ add_definitions(-DZ_POWER8)
+ set(ZLIB_POWER8 )
+
+ set_source_files_properties(
+ ${ZLIB_POWER8}
+ PROPERTIES COMPILE_FLAGS -mcpu=power8)
+ endif()
+
+ set(CMAKE_REQUIRED_FLAGS -mcpu=power9)
+ CHECK_C_SOURCE_COMPILES("int main(void){return 0;}" POWER9)
+
+ if(POWER9)
+ add_definitions(-DZ_POWER9)
+ set(ZLIB_POWER9 )
+
+ set_source_files_properties(
+ ${ZLIB_POWER9}
+ PROPERTIES COMPILE_FLAGS -mcpu=power9)
+ endif()
+
+ set(ZLIB_PRIVATE_HDRS ${ZLIB_PRIVATE_HDRS} contrib/power/power.h)
+ set(ZLIB_SRCS ${ZLIB_SRCS} ${ZLIB_POWER8} ${ZLIB_POWER9})
+ endif()
+ endif()
endif()
if(MSVC)
diff --git a/configure b/configure
index d026b35..0538d58 100755
--- a/configure
+++ b/configure
@@ -846,6 +846,72 @@ else
echo "Checking for sys/sdt.h ... No." | tee -a configure.log
fi
+# test to see if we can use a gnu indirection function to detect and load optimized code at runtime
+echo >> configure.log
+cat > $test.c <<EOF
+static int test_ifunc_native(void)
+{
+ return 1;
+}
+
+static int (*(check_ifunc_native(void)))(void)
+{
+ return test_ifunc_native;
+}
+
+int test_ifunc(void) __attribute__ ((ifunc ("check_ifunc_native")));
+EOF
+
+if tryboth $CC -c $CFLAGS $test.c; then
+ SFLAGS="${SFLAGS} -DHAVE_IFUNC"
+ CFLAGS="${CFLAGS} -DHAVE_IFUNC"
+ echo "Checking for attribute(ifunc) support... Yes." | tee -a configure.log
+else
+ echo "Checking for attribute(ifunc) support... No." | tee -a configure.log
+fi
+
+# Test to see if we can use the optimizations for Power
+echo >> configure.log
+cat > $test.c <<EOF
+#ifndef _ARCH_PPC
+ #error "Target is not Power"
+#endif
+#ifndef HAVE_IFUNC
+ #error "Target doesn't support ifunc"
+#endif
+#ifndef __BUILTIN_CPU_SUPPORTS__
+ #error "Target doesn't support __builtin_cpu_supports()"
+#endif
+EOF
+
+if tryboth $CC -c $CFLAGS $test.c; then
+ echo "int main(void){return 0;}" > $test.c
+
+ if tryboth $CC -c $CFLAGS -mcpu=power8 $test.c; then
+ POWER8="-DZ_POWER8"
+ PIC_OBJC="${PIC_OBJC}"
+ OBJC="${OBJC}"
+ echo "Checking for -mcpu=power8 support... Yes." | tee -a configure.log
+ else
+ echo "Checking for -mcpu=power8 support... No." | tee -a configure.log
+ fi
+
+ if tryboth $CC -c $CFLAGS -mcpu=power9 $test.c; then
+ POWER9="-DZ_POWER9"
+ PIC_OBJC="${PIC_OBJC}"
+ OBJC="${OBJC}"
+ echo "Checking for -mcpu=power9 support... Yes." | tee -a configure.log
+ else
+ echo "Checking for -mcpu=power9 support... No." | tee -a configure.log
+ fi
+
+ SFLAGS="${SFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT"
+ CFLAGS="${CFLAGS} ${POWER8} ${POWER9} -DZ_POWER_OPT"
+ echo "Checking for Power optimizations support... Yes." | tee -a configure.log
+else
+ echo "Checking for Power optimizations support... No." | tee -a configure.log
+fi
+
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
diff --git a/contrib/README.contrib b/contrib/README.contrib
index b4d3b18..2a53f90 100644
--- a/contrib/README.contrib
+++ b/contrib/README.contrib
@@ -19,6 +19,10 @@ asm686/ by Brian Raiter <breadbox@muppetlabs.com>
blast/ by Mark Adler <madler@alumni.caltech.edu>
Decompressor for output of PKWare Data Compression Library (DCL)
+gcc/ by Matheus Castanho <msc@linux.ibm.com>
+ and Rogerio Alves <rcardoso@linux.ibm.com>
+ Optimization helpers using GCC-specific extensions
+
delphi/ by Cosmin Truta <cosmint@cs.ubbcluj.ro>
Support for Delphi and C++ Builder
@@ -63,6 +67,10 @@ minizip/ by Gilles Vollant <info@winimage.com>
pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al.
Support for Pascal
+power/ by Matheus Castanho <msc@linux.ibm.com>
+ and Rogerio Alves <rcardoso@linux.ibm.com>
+ Optimized functions for Power processors
+
puff/ by Mark Adler <madler@alumni.caltech.edu>
Small, low memory usage inflate. Also serves to provide an
unambiguous description of the deflate format.
diff --git a/contrib/gcc/zifunc.h b/contrib/gcc/zifunc.h
new file mode 100644
index 0000000..daf4fe4
--- /dev/null
+++ b/contrib/gcc/zifunc.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2019 Matheus Castanho <msc@linux.ibm.com>, IBM
+ * 2019 Rogerio Alves <rogerio.alves@ibm.com>, IBM
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#ifndef Z_IFUNC_H_
+#define Z_IFUNC_H_
+
+/* Helpers for arch optimizations */
+
+#define Z_IFUNC(fname) \
+ typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \
+ local typeof(fname) *fname##_resolver(void)
+/* This is a helper macro to declare a resolver for an indirect function
+ * (ifunc). Let's say you have function
+ *
+ * int foo (int a);
+ *
+ * for which you want to provide different implementations, for example:
+ *
+ * int foo_clever (int a) {
+ * ... clever things ...
+ * }
+ *
+ * int foo_smart (int a) {
+ * ... smart things ...
+ * }
+ *
+ * You will have to declare foo() as an indirect function and also provide a
+ * resolver for it, to choose between foo_clever() and foo_smart() based on
+ * some criteria you define (e.g. processor features).
+ *
+ * Since most likely foo() has a default implementation somewhere in zlib, you
+ * may have to rename it so the 'foo' symbol can be used by the ifunc without
+ * conflicts.
+ *
+ * #define foo foo_default
+ * int foo (int a) {
+ * ...
+ * }
+ * #undef foo
+ *
+ * Now you just have to provide a resolver function to choose which function
+ * should be used (decided at runtime on the first call to foo()):
+ *
+ * Z_IFUNC(foo) {
+ * if (... some condition ...)
+ * return foo_clever;
+ *
+ * if (... other condition ...)
+ * return foo_smart;
+ *
+ * return foo_default;
+ * }
+ *
+ * All calls to foo() throughout the code can remain untouched, all the magic
+ * will be done by the linker using the resolver function.
+ */
+
+#endif /* Z_IFUNC_H_ */
diff --git a/contrib/power/power.h b/contrib/power/power.h
new file mode 100644
index 0000000..b42c7d6
--- /dev/null
+++ b/contrib/power/power.h
@@ -0,0 +1,4 @@
+/* Copyright (C) 2019 Matheus Castanho <msc@linux.ibm.com>, IBM
+ * 2019 Rogerio Alves <rogerio.alves@ibm.com>, IBM
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
--
2.39.1

View File

@ -1,65 +0,0 @@
From 1e56dd1e7285d3026092ba794078edb290b4c1b1 Mon Sep 17 00:00:00 2001
From: Ondrej Dubaj <odubaj@redhat.com>
Date: Mon, 15 Mar 2021 13:06:35 +0100
Subject: [PATCH] fixed isues found by covscan
---
contrib/minizip/mztools.c | 8 ++++++++
contrib/minizip/zip.c | 4 ++--
deflate.c | 5 +++--
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c
index 96891c2..1197928 100644
--- a/contrib/minizip/mztools.c
+++ b/contrib/minizip/mztools.c
@@ -286,6 +286,14 @@ uLong* bytesRecovered;
}
} else {
err = Z_STREAM_ERROR;
+ if(fpZip != NULL)
+ fclose(fpZip);
+
+ if(fpOut != NULL)
+ fclose(fpOut);
+
+ if(fpOutCD != NULL)
+ fclose(fpOutCD);
}
return err;
}
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 44e88a9..a753c17 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -526,8 +526,8 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
break;
}
- if (uPosFound!=0)
- break;
+ if (uPosFound!=0)
+ break;
}
TRYFREE(buf);
return uPosFound;
diff --git a/deflate.c b/deflate.c
index 085abbe..3963e79 100644
--- a/deflate.c
+++ b/deflate.c
@@ -203,9 +203,10 @@ local const config configuration_table[10] = {
* Initialize the hash table (avoiding 64K overflow for 16 bit systems).
* prev[] will be initialized on the fly.
*/
-#define CLEAR_HASH(s) \
+#define CLEAR_HASH(s) do { \
s->head[s->hash_size-1] = NIL; \
- zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
+ zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); \
+} while (0)
/* ===========================================================================
* Slide the hash table when sliding the window down (could be avoided with 32
--
2.26.0

View File

@ -9,19 +9,6 @@ Subject: [PATCH] fixed covscan issues
test/crc32_test.c | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/crc32.c b/crc32.c
index 406d350..34132ea 100644
--- a/crc32.c
+++ b/crc32.c
@@ -302,7 +302,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
if (!crc32_func)
crc32_func = crc32_z_ifunc();
- return (*crc32_func)(crc, buf, len);
+ return (*crc32_func)(crc, buf, len);
}
#endif /* defined(Z_IFUNC_ASM) || defined(Z_IFUNC_NATIVE) */
diff --git a/deflate.c b/deflate.c
index 089285a..9b09718 100644
--- a/deflate.c
@ -35,40 +22,4 @@ index 089285a..9b09718 100644
bstate = DEFLATE_HOOK(strm, flush, &bstate) ? bstate :
s->level == 0 ? deflate_stored(s, flush) :
diff --git a/test/crc32_test.c b/test/crc32_test.c
index 5d73128..2d2a6c7 100644
--- a/test/crc32_test.c
+++ b/test/crc32_test.c
@@ -11,25 +11,25 @@
# include <stdlib.h>
#endif
-void test_crc32 OF((uLong crc, Byte* buf, z_size_t len, uLong chk, int line));
+void test_crc32 OF((uLong crc, char* buf, z_size_t len, uLong chk, int line));
int main OF((void));
typedef struct {
int line;
uLong crc;
- Byte* buf;
+ char* buf;
int len;
uLong expect;
} crc32_test;
void test_crc32(crc, buf, len, chk, line)
uLong crc;
- Byte *buf;
+ char *buf;
z_size_t len;
uLong chk;
int line;
{
- uLong res = crc32(crc, buf, len);
+ uLong res = crc32(crc, (Bytef *) buf, len);
if (res != chk) {
fprintf(stderr, "FAIL [%d]: crc32 returned 0x%08X expected 0x%08X\n",
line, (unsigned int)res, (unsigned int)chk);
--
2.19.1

View File

@ -1,365 +0,0 @@
From 27a84de4a30cd35f8565937397f6d1205b912818 Mon Sep 17 00:00:00 2001
From: Ondrej Dubaj <odubaj@redhat.com>
Date: Thu, 5 Sep 2019 09:16:35 +0200
Subject: [PATCH 1/2] fix: power8 crc32 - return 0 with 0 ptr passed
---
contrib/power8-crc/vec_crc32.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/contrib/power8-crc/vec_crc32.c b/contrib/power8-crc/vec_crc32.c
index bb2204b..5ce9cd2 100644
--- a/contrib/power8-crc/vec_crc32.c
+++ b/contrib/power8-crc/vec_crc32.c
@@ -74,6 +74,7 @@ unsigned int CRC32_FUNCTION(unsigned int crc, const unsigned char *p,
unsigned int prealign;
unsigned int tail;
+ if (p == (const unsigned char *) 0x0) return 0;
#ifdef CRC_XOR
crc ^= 0xffffffff;
#endif
--
2.19.1
From c066ac92982a2ffe5b1e9bd36000058927437bd5 Mon Sep 17 00:00:00 2001
From: Ondrej Dubaj <odubaj@redhat.com>
Date: Thu, 5 Sep 2019 09:36:47 +0200
Subject: [PATCH 2/2] Add CRC32 tests (crc32_test)
This commit includes a CRC32 test (crc32_test). This tests are important
since some architectures may want include CPU dependent optimizations for
CRC32 algorithm like using vector instructions and we may want to
validate those.
---
Makefile.in | 35 +++++---
test/crc32_test.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 230 insertions(+), 10 deletions(-)
create mode 100644 test/crc32_test.c
diff --git a/Makefile.in b/Makefile.in
index 40b5cfb..6070dcc 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -75,11 +75,11 @@ PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
all: static shared
-static: example$(EXE) minigzip$(EXE)
+static: crc32_test$(EXE) example$(EXE) minigzip$(EXE)
-shared: examplesh$(EXE) minigzipsh$(EXE)
+shared: crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE)
-all64: example64$(EXE) minigzip64$(EXE)
+all64: crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE)
check: test
@@ -87,7 +87,7 @@ test: all teststatic testshared
teststatic: static
@TMPST=tmpst_$$; \
- if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
+ if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST && ./crc32_test; then \
echo ' *** zlib test OK ***'; \
else \
echo ' *** zlib test FAILED ***'; false; \
@@ -100,7 +100,7 @@ testshared: shared
DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
TMPSH=tmpsh_$$; \
- if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
+ if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH && ./crc32_testsh; then \
echo ' *** zlib shared test OK ***'; \
else \
echo ' *** zlib shared test FAILED ***'; false; \
@@ -109,7 +109,7 @@ testshared: shared
test64: all64
@TMP64=tmp64_$$; \
- if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
+ if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64 && ./crc32_test64; then \
echo ' *** zlib 64-bit test OK ***'; \
else \
echo ' *** zlib 64-bit test FAILED ***'; false; \
@@ -157,6 +157,12 @@ example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c
+crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h
+ $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c
+
+crc32_test64.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h
+ $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/crc32_test.c
+
example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c
@@ -307,12 +313,21 @@ example$(EXE): example.o $(STATICLIB)
minigzip$(EXE): minigzip.o $(STATICLIB)
$(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
+crc32_test$(EXE): crc32_test.o $(STATICLIB)
+ $(CC) $(CFLAGS) -o $@ crc32_test.o $(TEST_LDFLAGS)
+
+crc32_testsh$(EXE): crc32_test.o $(SHAREDLIBV)
+ $(CC) $(CFLAGS) -o $@ crc32_test.o -L. $(SHAREDLIBV)
+
examplesh$(EXE): example.o $(SHAREDLIBV)
$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
+crc32_test64$(EXE): crc32_test64.o $(STATICLIB)
+ $(CC) $(CFLAGS) -o $@ crc32_test64.o $(TEST_LDFLAGS)
+
example64$(EXE): example64.o $(STATICLIB)
$(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
@@ -382,8 +397,8 @@ zconf: $(SRCDIR)zconf.h.in
mostlyclean: clean
clean:
rm -f *.o *.lo *~ \
- example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
- example64$(EXE) minigzip64$(EXE) \
+ crc32_test$(EXE) example$(EXE) minigzip$(EXE) crc32_testsh$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
+ crc32_test64$(EXE) example64$(EXE) minigzip64$(EXE) \
infcover \
libz.* foo.gz so_locations \
_match.s maketree contrib/infback9/*.o
@@ -407,7 +422,7 @@ tags:
adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
-compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
+compress.o crc32_test.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
@@ -417,7 +432,7 @@ trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)tr
adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
-compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
+compress.lo crc32_test.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
diff --git a/test/crc32_test.c b/test/crc32_test.c
new file mode 100644
index 0000000..5d73128
--- /dev/null
+++ b/test/crc32_test.c
@@ -0,0 +1,205 @@
+/* crc32_tes.c -- unit test for crc32 in the zlib compression library
+ * Copyright (C) 1995-2006, 2010, 2011, 2016, 2019 Rogerio Alves
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zlib.h"
+#include <stdio.h>
+
+#ifdef STDC
+# include <string.h>
+# include <stdlib.h>
+#endif
+
+void test_crc32 OF((uLong crc, Byte* buf, z_size_t len, uLong chk, int line));
+int main OF((void));
+
+typedef struct {
+ int line;
+ uLong crc;
+ Byte* buf;
+ int len;
+ uLong expect;
+} crc32_test;
+
+void test_crc32(crc, buf, len, chk, line)
+ uLong crc;
+ Byte *buf;
+ z_size_t len;
+ uLong chk;
+ int line;
+{
+ uLong res = crc32(crc, buf, len);
+ if (res != chk) {
+ fprintf(stderr, "FAIL [%d]: crc32 returned 0x%08X expected 0x%08X\n",
+ line, (unsigned int)res, (unsigned int)chk);
+ exit(1);
+ }
+}
+
+static const crc32_test tests[] = {
+ {__LINE__, 0x0, 0x0, 0, 0x0},
+ {__LINE__, 0xffffffff, 0x0, 0, 0x0},
+ {__LINE__, 0x0, 0x0, 255, 0x0}, /* BZ 174799. */
+ {__LINE__, 0x0, 0x0, 256, 0x0},
+ {__LINE__, 0x0, 0x0, 257, 0x0},
+ {__LINE__, 0x0, 0x0, 32767, 0x0},
+ {__LINE__, 0x0, 0x0, 32768, 0x0},
+ {__LINE__, 0x0, 0x0, 32769, 0x0},
+ {__LINE__, 0x0, "", 0, 0x0},
+ {__LINE__, 0xffffffff, "", 0, 0xffffffff},
+ {__LINE__, 0x0, "abacus", 6, 0xc3d7115b},
+ {__LINE__, 0x0, "backlog", 7, 0x269205},
+ {__LINE__, 0x0, "campfire", 8, 0x22a515f8},
+ {__LINE__, 0x0, "delta", 5, 0x9643fed9},
+ {__LINE__, 0x0, "executable", 10, 0xd68eda01},
+ {__LINE__, 0x0, "file", 4, 0x8c9f3610},
+ {__LINE__, 0x0, "greatest", 8, 0xc1abd6cd},
+ {__LINE__, 0x0, "hello", 5, 0x3610a686},
+ {__LINE__, 0x0, "inverter", 8, 0xc9e962c9},
+ {__LINE__, 0x0, "jigsaw", 6, 0xce4e3f69},
+ {__LINE__, 0x0, "karate", 6, 0x890be0e2},
+ {__LINE__, 0x0, "landscape", 9, 0xc4e0330b},
+ {__LINE__, 0x0, "machine", 7, 0x1505df84},
+ {__LINE__, 0x0, "nanometer", 9, 0xd4e19f39},
+ {__LINE__, 0x0, "oblivion", 8, 0xdae9de77},
+ {__LINE__, 0x0, "panama", 6, 0x66b8979c},
+ {__LINE__, 0x0, "quest", 5, 0x4317f817},
+ {__LINE__, 0x0, "resource", 8, 0xbc91f416},
+ {__LINE__, 0x0, "secret", 6, 0x5ca2e8e5},
+ {__LINE__, 0x0, "test", 4, 0xd87f7e0c},
+ {__LINE__, 0x0, "ultimate", 8, 0x3fc79b0b},
+ {__LINE__, 0x0, "vector", 6, 0x1b6e485b},
+ {__LINE__, 0x0, "walrus", 6, 0xbe769b97},
+ {__LINE__, 0x0, "xeno", 4, 0xe7a06444},
+ {__LINE__, 0x0, "yelling", 7, 0xfe3944e5},
+ {__LINE__, 0x0, "zlib", 4, 0x73887d3a},
+ {__LINE__, 0x0, "4BJD7PocN1VqX0jXVpWB", 20, 0xd487a5a1},
+ {__LINE__, 0x0, "F1rPWI7XvDs6nAIRx41l", 20, 0x61a0132e},
+ {__LINE__, 0x0, "ldhKlsVkPFOveXgkGtC2", 20, 0xdf02f76},
+ {__LINE__, 0x0, "5KKnGOOrs8BvJ35iKTOS", 20, 0x579b2b0a},
+ {__LINE__, 0x0, "0l1tw7GOcem06Ddu7yn4", 20, 0xf7d16e2d},
+ {__LINE__, 0x0, "MCr47CjPIn9R1IvE1Tm5", 20, 0x731788f5},
+ {__LINE__, 0x0, "UcixbzPKTIv0SvILHVdO", 20, 0x7112bb11},
+ {__LINE__, 0x0, "dGnAyAhRQDsWw0ESou24", 20, 0xf32a0dac},
+ {__LINE__, 0x0, "di0nvmY9UYMYDh0r45XT", 20, 0x625437bb},
+ {__LINE__, 0x0, "2XKDwHfAhFsV0RhbqtvH", 20, 0x896930f9},
+ {__LINE__, 0x0, "ZhrANFIiIvRnqClIVyeD", 20, 0x8579a37},
+ {__LINE__, 0x0, "v7Q9ehzioTOVeDIZioT1", 20, 0x632aa8e0},
+ {__LINE__, 0x0, "Yod5hEeKcYqyhfXbhxj2", 20, 0xc829af29},
+ {__LINE__, 0x0, "GehSWY2ay4uUKhehXYb0", 20, 0x1b08b7e8},
+ {__LINE__, 0x0, "kwytJmq6UqpflV8Y8GoE", 20, 0x4e33b192},
+ {__LINE__, 0x0, "70684206568419061514", 20, 0x59a179f0},
+ {__LINE__, 0x0, "42015093765128581010", 20, 0xcd1013d7},
+ {__LINE__, 0x0, "88214814356148806939", 20, 0xab927546},
+ {__LINE__, 0x0, "43472694284527343838", 20, 0x11f3b20c},
+ {__LINE__, 0x0, "49769333513942933689", 20, 0xd562d4ca},
+ {__LINE__, 0x0, "54979784887993251199", 20, 0x233395f7},
+ {__LINE__, 0x0, "58360544869206793220", 20, 0x2d167fd5},
+ {__LINE__, 0x0, "27347953487840714234", 20, 0x8b5108ba},
+ {__LINE__, 0x0, "07650690295365319082", 20, 0xc46b3cd8},
+ {__LINE__, 0x0, "42655507906821911703", 20, 0xc10b2662},
+ {__LINE__, 0x0, "29977409200786225655", 20, 0xc9a0f9d2},
+ {__LINE__, 0x0, "85181542907229116674", 20, 0x9341357b},
+ {__LINE__, 0x0, "87963594337989416799", 20, 0xf0424937},
+ {__LINE__, 0x0, "21395988329504168551", 20, 0xd7c4c31f},
+ {__LINE__, 0x0, "51991013580943379423", 20, 0xf11edcc4},
+ {__LINE__, 0x0, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x40795df4},
+ {__LINE__, 0x0, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0xdd61a631},
+ {__LINE__, 0x0, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xca907a99},
+ {__LINE__, 0x0, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0xf652deac},
+ {__LINE__, 0x0, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0xaf39a5a9},
+ {__LINE__, 0x0, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x6bebb4cf},
+ {__LINE__, 0x0, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0x76430bac},
+ {__LINE__, 0x0, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x6c80c388},
+ {__LINE__, 0x0, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xd54d977d},
+ {__LINE__, 0x0, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0xe3966ad5},
+ {__LINE__, 0x0, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xe7c71db9},
+ {__LINE__, 0x0, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xeaa52777},
+ {__LINE__, 0x0, "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%&", 100, 0xcd472048},
+ {__LINE__, 0x7a30360d, "abacus", 6, 0xf8655a84},
+ {__LINE__, 0x6fd767ee, "backlog", 7, 0x1ed834b1},
+ {__LINE__, 0xefeb7589, "campfire", 8, 0x686cfca},
+ {__LINE__, 0x61cf7e6b, "delta", 5, 0x1554e4b1},
+ {__LINE__, 0xdc712e2, "executable", 10, 0x761b4254},
+ {__LINE__, 0xad23c7fd, "file", 4, 0x7abdd09b},
+ {__LINE__, 0x85cb2317, "greatest", 8, 0x4ba91c6b},
+ {__LINE__, 0x9eed31b0, "inverter", 8, 0xd5e78ba5},
+ {__LINE__, 0xb94f34ca, "jigsaw", 6, 0x23649109},
+ {__LINE__, 0xab058a2, "karate", 6, 0xc5591f41},
+ {__LINE__, 0x5bff2b7a, "landscape", 9, 0xf10eb644},
+ {__LINE__, 0x605c9a5f, "machine", 7, 0xbaa0a636},
+ {__LINE__, 0x51bdeea5, "nanometer", 9, 0x6af89afb},
+ {__LINE__, 0x85c21c79, "oblivion", 8, 0xecae222b},
+ {__LINE__, 0x97216f56, "panama", 6, 0x47dffac4},
+ {__LINE__, 0x18444af2, "quest", 5, 0x70c2fe36},
+ {__LINE__, 0xbe6ce359, "resource", 8, 0x1471d925},
+ {__LINE__, 0x843071f1, "secret", 6, 0x50c9a0db},
+ {__LINE__, 0xf2480c60, "ultimate", 8, 0xf973daf8},
+ {__LINE__, 0x2d2feb3d, "vector", 6, 0x344ac03d},
+ {__LINE__, 0x7490310a, "walrus", 6, 0x6d1408ef},
+ {__LINE__, 0x97d247d4, "xeno", 4, 0xe62670b5},
+ {__LINE__, 0x93cf7599, "yelling", 7, 0x1b36da38},
+ {__LINE__, 0x73c84278, "zlib", 4, 0x6432d127},
+ {__LINE__, 0x228a87d1, "4BJD7PocN1VqX0jXVpWB", 20, 0x997107d0},
+ {__LINE__, 0xa7a048d0, "F1rPWI7XvDs6nAIRx41l", 20, 0xdc567274},
+ {__LINE__, 0x1f0ded40, "ldhKlsVkPFOveXgkGtC2", 20, 0xdcc63870},
+ {__LINE__, 0xa804a62f, "5KKnGOOrs8BvJ35iKTOS", 20, 0x6926cffd},
+ {__LINE__, 0x508fae6a, "0l1tw7GOcem06Ddu7yn4", 20, 0xb52b38bc},
+ {__LINE__, 0xe5adaf4f, "MCr47CjPIn9R1IvE1Tm5", 20, 0xf83b8178},
+ {__LINE__, 0x67136a40, "UcixbzPKTIv0SvILHVdO", 20, 0xc5213070},
+ {__LINE__, 0xb00c4a10, "dGnAyAhRQDsWw0ESou24", 20, 0xbc7648b0},
+ {__LINE__, 0x2e0c84b5, "di0nvmY9UYMYDh0r45XT", 20, 0xd8123a72},
+ {__LINE__, 0x81238d44, "2XKDwHfAhFsV0RhbqtvH", 20, 0xd5ac5620},
+ {__LINE__, 0xf853aa92, "ZhrANFIiIvRnqClIVyeD", 20, 0xceae099d},
+ {__LINE__, 0x5a692325, "v7Q9ehzioTOVeDIZioT1", 20, 0xb07d2b24},
+ {__LINE__, 0x3275b9f, "Yod5hEeKcYqyhfXbhxj2", 20, 0x24ce91df},
+ {__LINE__, 0x38371feb, "GehSWY2ay4uUKhehXYb0", 20, 0x707b3b30},
+ {__LINE__, 0xafc8bf62, "kwytJmq6UqpflV8Y8GoE", 20, 0x16abc6a9},
+ {__LINE__, 0x9b07db73, "70684206568419061514", 20, 0xae1fb7b7},
+ {__LINE__, 0xe75b214, "42015093765128581010", 20, 0xd4eecd2d},
+ {__LINE__, 0x72d0fe6f, "88214814356148806939", 20, 0x4660ec7},
+ {__LINE__, 0xf857a4b1, "43472694284527343838", 20, 0xfd8afdf7},
+ {__LINE__, 0x54b8e14, "49769333513942933689", 20, 0xc6d1b5f2},
+ {__LINE__, 0xd6aa5616, "54979784887993251199", 20, 0x32476461},
+ {__LINE__, 0x11e63098, "58360544869206793220", 20, 0xd917cf1a},
+ {__LINE__, 0xbe92385, "27347953487840714234", 20, 0x4ad14a12},
+ {__LINE__, 0x49511de0, "07650690295365319082", 20, 0xe37b5c6c},
+ {__LINE__, 0x3db13bc1, "42655507906821911703", 20, 0x7cc497f1},
+ {__LINE__, 0xbb899bea, "29977409200786225655", 20, 0x99781bb2},
+ {__LINE__, 0xf6cd9436, "85181542907229116674", 20, 0x132256a1},
+ {__LINE__, 0x9109e6c3, "87963594337989416799", 20, 0xbfdb2c83},
+ {__LINE__, 0x75770fc, "21395988329504168551", 20, 0x8d9d1e81},
+ {__LINE__, 0x69b1d19b, "51991013580943379423", 20, 0x7b6d4404},
+ {__LINE__, 0xc6132975, "*]+@!);({_$;}[_},?{?;(_?,=-][@", 30, 0x8619f010},
+ {__LINE__, 0xd58cb00c, "_@:_).&(#.[:[{[:)$++-($_;@[)}+", 30, 0x15746ac3},
+ {__LINE__, 0xb63b8caa, "&[!,[$_==}+.]@!;*(+},[;:)$;)-@", 30, 0xaccf812f},
+ {__LINE__, 0x8a45a2b8, "]{.[.+?+[[=;[?}_#&;[=)__$$:+=_", 30, 0x78af45de},
+ {__LINE__, 0xcbe95b78, "-%.)=/[@].:.(:,()$;=%@-$?]{%+%", 30, 0x25b06b59},
+ {__LINE__, 0x4ef8a54b, "+]#$(@&.=:,*];/.!]%/{:){:@(;)$", 30, 0x4ba0d08f},
+ {__LINE__, 0x76ad267a, ")-._.:?[&:.=+}(*$/=!.${;(=$@!}", 30, 0xe26b6aac},
+ {__LINE__, 0x569e613c, ":(_*&%/[[}+,?#$&*+#[([*-/#;%(]", 30, 0x7e2b0a66},
+ {__LINE__, 0x36aa61da, "{[#-;:$/{)(+[}#]/{&!%(@)%:@-$:", 30, 0xb3430dc7},
+ {__LINE__, 0xf67222df, "_{$*,}(&,@.)):=!/%(&(,,-?$}}}!", 30, 0x626c17a},
+ {__LINE__, 0x74b34fd3, "e$98KNzqaV)Y:2X?]77].{gKRD4G5{mHZk,Z)SpU%L3FSgv!Wb8MLAFdi{+fp)c,@8m6v)yXg@]HBDFk?.4&}g5_udE*JHCiH=aL", 100, 0xccf98060},
+ {__LINE__, 0x351fd770, "r*Fd}ef+5RJQ;+W=4jTR9)R*p!B;]Ed7tkrLi;88U7g@3v!5pk2X6D)vt,.@N8c]@yyEcKi[vwUu@.Ppm@C6%Mv*3Nw}Y,58_aH)", 100, 0xd8b95312},
+ {__LINE__, 0xc45aef77, "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%&", 100, 0xbb1c9912},
+ {__LINE__, 0xc45aef77, "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%&"
+ "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%&"
+ "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%&"
+ "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%&"
+ "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%&"
+ "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%&", 600, 0x888AFA5B}
+};
+
+static const int test_size = sizeof(tests) / sizeof(tests[0]);
+
+int main(void)
+{
+ int i;
+ for (i = 0; i < test_size; i++) {
+ test_crc32(tests[i].crc, tests[i].buf, tests[i].len,
+ tests[i].expect, tests[i].line);
+ }
+ return 0;
+}
\ No newline at end of file
--
2.19.1

View File

@ -1,4 +1,4 @@
From 2dfdc5b7d6943c0ac60eef63e361e2a50f9da610 Mon Sep 17 00:00:00 2001
From cfbf97cb54a6d06a80e86c85869331e4e2871129 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 19 Mar 2020 11:52:03 +0100
Subject: [PATCH] s390x: vectorize crc32
@ -8,15 +8,18 @@ about them. At runtime, check whether kernel supports vector
extensions (it has to be not just the CPU, but also the kernel) and
choose between the regular and the vectorized implementations.
---
Makefile.in | 9 ++
configure | 28 ++++++
contrib/s390/crc32-vx.c | 195 ++++++++++++++++++++++++++++++++++++++++
crc32.c | 55 +++++++++++-
4 files changed, 285 insertions(+), 2 deletions(-)
Makefile.in | 9 ++
configure | 28 +++++
contrib/gcc/zifunc.h | 21 +++-
contrib/s390/crc32-vx.c | 195 ++++++++++++++++++++++++++++++++
contrib/s390/crc32_z_resolver.c | 41 +++++++
crc32.c | 11 +-
6 files changed, 301 insertions(+), 4 deletions(-)
create mode 100644 contrib/s390/crc32-vx.c
create mode 100644 contrib/s390/crc32_z_resolver.c
diff --git a/Makefile.in b/Makefile.in
index 6070dcc..9e9743b 100644
index d392616..63f76da 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -29,6 +29,7 @@ LDFLAGS=
@ -27,9 +30,9 @@ index 6070dcc..9e9743b 100644
STATICLIB=libz.a
SHAREDLIB=libz.so
@@ -179,6 +180,9 @@ crc32_power8.o: $(SRCDIR)contrib/power8-crc/vec_crc32.c
crc32.o: $(SRCDIR)crc32.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c
@@ -179,6 +180,9 @@ crc32.o: $(SRCDIR)crc32.c
crc32_z_power8.o: $(SRCDIR)contrib/power/crc32_z_power8.c
$(CC) $(CFLAGS) -mcpu=power8 $(ZINC) -c -o $@ $(SRCDIR)contrib/power/crc32_z_power8.c
+crc32-vx.o: $(SRCDIR)contrib/s390/crc32-vx.c
+ $(CC) $(CFLAGS) $(VGFMAFLAG) $(ZINC) -c -o $@ $(SRCDIR)contrib/s390/crc32-vx.c
@ -37,7 +40,7 @@ index 6070dcc..9e9743b 100644
deflate.o: $(SRCDIR)deflate.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c
@@ -234,6 +238,11 @@ crc32.lo: $(SRCDIR)crc32.c
@@ -229,6 +233,11 @@ crc32.lo: $(SRCDIR)crc32.c
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c
-@mv objs/crc32.o $@
@ -46,15 +49,15 @@ index 6070dcc..9e9743b 100644
+ $(CC) $(SFLAGS) $(VGFMAFLAG) $(ZINC) -DPIC -c -o objs/crc32-vx.o $(SRCDIR)contrib/s390/crc32-vx.c
+ -@mv objs/crc32-vx.o $@
+
deflate.lo: $(SRCDIR)deflate.c
crc32_z_power8.lo: $(SRCDIR)contrib/power/crc32_z_power8.c
-@mkdir objs 2>/dev/null || test -d objs
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c
$(CC) $(SFLAGS) -mcpu=power8 $(ZINC) -DPIC -c -o objs/crc32_z_power8.o $(SRCDIR)contrib/power/crc32_z_power8.c
diff --git a/configure b/configure
index 70ed86b..7941f75 100755
index e37dac8..a4606b8 100755
--- a/configure
+++ b/configure
@@ -923,6 +923,32 @@ EOF
fi
@@ -915,6 +915,32 @@ else
echo "Checking for Power optimizations support... No." | tee -a configure.log
fi
+# check if we are compiling for s390 and binutils support vector extensions
@ -86,7 +89,7 @@ index 70ed86b..7941f75 100755
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
@@ -955,6 +981,7 @@ echo mandir = $mandir >> configure.log
@@ -947,6 +973,7 @@ echo mandir = $mandir >> configure.log
echo prefix = $prefix >> configure.log
echo sharedlibdir = $sharedlibdir >> configure.log
echo uname = $uname >> configure.log
@ -94,7 +97,7 @@ index 70ed86b..7941f75 100755
# udpate Makefile with the configure results
sed < ${SRCDIR}Makefile.in "
@@ -964,6 +991,7 @@ sed < ${SRCDIR}Makefile.in "
@@ -956,6 +983,7 @@ sed < ${SRCDIR}Makefile.in "
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
/^LDSHARED *=/s#=.*#=$LDSHARED#
/^CPP *=/s#=.*#=$CPP#
@ -102,6 +105,40 @@ index 70ed86b..7941f75 100755
/^STATICLIB *=/s#=.*#=$STATICLIB#
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
diff --git a/contrib/gcc/zifunc.h b/contrib/gcc/zifunc.h
index daf4fe4..b62379e 100644
--- a/contrib/gcc/zifunc.h
+++ b/contrib/gcc/zifunc.h
@@ -8,9 +8,28 @@
/* Helpers for arch optimizations */
+#if defined(__clang__)
+#if __has_feature(coverage_sanitizer)
+#define Z_IFUNC_NO_SANCOV __attribute__((no_sanitize("coverage")))
+#else /* __has_feature(coverage_sanitizer) */
+#define Z_IFUNC_NO_SANCOV
+#endif /* __has_feature(coverage_sanitizer) */
+#else /* __clang__ */
+#define Z_IFUNC_NO_SANCOV
+#endif /* __clang__ */
+
+#ifdef __s390__
+#define Z_IFUNC_PARAMS unsigned long hwcap
+#define Z_IFUNC_ATTRS Z_IFUNC_NO_SANCOV
+#else /* __s390__ */
+#define Z_IFUNC_PARAMS void
+#define Z_IFUNC_ATTRS
+#endif /* __s390__ */
+
#define Z_IFUNC(fname) \
typeof(fname) fname __attribute__ ((ifunc (#fname "_resolver"))); \
- local typeof(fname) *fname##_resolver(void)
+ Z_IFUNC_ATTRS \
+ local typeof(fname) *fname##_resolver(Z_IFUNC_PARAMS)
/* This is a helper macro to declare a resolver for an indirect function
* (ifunc). Let's say you have function
*
diff --git a/contrib/s390/crc32-vx.c b/contrib/s390/crc32-vx.c
new file mode 100644
index 0000000..fa5387c
@ -303,16 +340,14 @@ index 0000000..fa5387c
+
+ return ((uv4si)v2)[2];
+}
diff --git a/crc32.c b/crc32.c
index 34132ea..dfa33ef 100644
--- a/crc32.c
+++ b/crc32.c
@@ -252,12 +252,54 @@ unsigned long crc32_vpmsum(unsigned long, const unsigned char FAR *, z_size_t);
#endif
#endif
+#ifdef HAVE_S390X_VX
diff --git a/contrib/s390/crc32_z_resolver.c b/contrib/s390/crc32_z_resolver.c
new file mode 100644
index 0000000..9749cab
--- /dev/null
+++ b/contrib/s390/crc32_z_resolver.c
@@ -0,0 +1,41 @@
+#include <sys/auxv.h>
+#include "../gcc/zifunc.h"
+
+#define VX_MIN_LEN 64
+#define VX_ALIGNMENT 16L
@ -322,17 +357,17 @@ index 34132ea..dfa33ef 100644
+
+local unsigned long s390_crc32_vx(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
+{
+ uint64_t prealign, aligned, remaining;
+ uintptr_t prealign, aligned, remaining;
+
+ if (buf == Z_NULL) return 0UL;
+
+ if (len < VX_MIN_LEN + VX_ALIGN_MASK)
+ return crc32_big(crc, buf, len);
+ return crc32_z_default(crc, buf, len);
+
+ if ((uintptr_t)buf & VX_ALIGN_MASK) {
+ prealign = VX_ALIGNMENT - ((uintptr_t)buf & VX_ALIGN_MASK);
+ len -= prealign;
+ crc = crc32_big(crc, buf, prealign);
+ crc = crc32_z_default(crc, buf, prealign);
+ buf += prealign;
+ }
+ aligned = len & ~VX_ALIGN_MASK;
@ -341,53 +376,53 @@ index 34132ea..dfa33ef 100644
+ crc = crc32_le_vgfm_16(crc ^ 0xffffffff, buf, (size_t)aligned) ^ 0xffffffff;
+
+ if (remaining)
+ crc = crc32_big(crc, buf + aligned, remaining);
+ crc = crc32_z_default(crc, buf + aligned, remaining);
+
+ return crc;
+}
+#endif
+
/* due to a quirk of gnu_indirect_function - "local" (aka static) is applied to
* crc32_z which is not desired. crc32_z_ifunc is implictly "local" */
#ifndef Z_IFUNC_ASM
local
#endif
-unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *, z_size_t)
+unsigned long (*(crc32_z_ifunc(
+#ifdef __s390__
+unsigned long hwcap
+#else
+void
+#endif
+)))(unsigned long, const unsigned char FAR *, z_size_t)
{
#if _ARCH_PWR8==1
#if defined(__BUILTIN_CPU_SUPPORTS__)
@@ -269,6 +311,11 @@ unsigned long (*(crc32_z_ifunc(void)))(unsigned long, const unsigned char FAR *,
#endif
#endif /* _ARCH_PWR8 */
+#ifdef HAVE_S390X_VX
+Z_IFUNC(crc32_z)
+{
+ if (hwcap & HWCAP_S390_VX)
+ return s390_crc32_vx;
+#endif
+
/* return a function pointer for optimized arches here */
+ return crc32_z_default;
+}
diff --git a/crc32.c b/crc32.c
index b0cda20..379fac3 100644
--- a/crc32.c
+++ b/crc32.c
@@ -199,12 +199,12 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
#ifdef DYNAMIC_CRC_TABLE
@@ -301,7 +348,11 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
static unsigned long ZEXPORT (*crc32_func)(unsigned long, const unsigned char FAR *, z_size_t) = NULL;
/* ========================================================================= */
-#ifdef Z_POWER_OPT
+#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX)
/* Rename function so resolver can use its symbol. The default version will be
* returned by the resolver if the host has no support for an optimized version.
*/
#define crc32_z crc32_z_default
-#endif /* Z_POWER_OPT */
+#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */
if (!crc32_func)
- crc32_func = crc32_z_ifunc();
+ crc32_func = crc32_z_ifunc(
+#ifdef __s390__
+ getauxval(AT_HWCAP)
+#endif
+ );
return (*crc32_func)(crc, buf, len);
unsigned long ZEXPORT crc32_z(crc, buf, len)
unsigned long crc;
@@ -240,10 +240,15 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
return crc ^ 0xffffffffUL;
}
-#ifdef Z_POWER_OPT
+#if defined(Z_POWER_OPT) || defined(HAVE_S390X_VX)
#undef crc32_z
+#ifdef Z_POWER_OPT
#include "contrib/power/crc32_z_resolver.c"
#endif /* Z_POWER_OPT */
+#ifdef HAVE_S390X_VX
+#include "contrib/s390/crc32_z_resolver.c"
+#endif /* HAVE_S390X_VX */
+#endif /* defined(Z_POWER_OPT) || defined(HAVE_S390X_VX) */
/* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len)
--
2.25.1
2.39.1

View File

@ -1,54 +1,68 @@
%bcond_without minizip
# disabled, per rhbz#1609830 and rhbz#1602742
%bcond_with minizip
Name: zlib
Version: 1.2.11
Release: 34%{?dist}
Summary: Compression and decompression library
Release: 25%{?dist}
Summary: The compression and decompression library
# /contrib/dotzlib/ have Boost license
License: zlib and Boost
URL: https://www.zlib.net/
URL: http://www.zlib.net/
Source: https://www.zlib.net/zlib-%{version}.tar.xz
Source: http://www.zlib.net/zlib-%{version}.tar.xz
# https://github.com/madler/zlib/pull/210
Patch0: zlib-1.2.5-minizip-fixuncrypt.patch
# resolves: #805113
Patch1: zlib-1.2.11-optimized-s390.patch
# Backport upstream commit 2d80d3f6b52f9fa454c26c89d2d6a1790e1cecb0
# Reason: Fuzzer founds issues with unknown memory access
Patch2: zlib-1.2.11-Limit-hash-table-inserts.patch
# IBM Z optimalizations
Patch7: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-s390x.patch
# IBM CRC32 optimalization for POWER archs
Patch8: zlib-1.2.11-optimized-CRC32-framework.patch
# fixed firefox crash + added test case
Patch9: zlib-1.2.11-firefox-crash-fix.patch
# fixed covscan issues
Patch10: zlib-1.2.11-covscan-issues.patch
Patch3: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-s390x.patch
# fix for IBM Z optimalizations
Patch11: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-fix.patch
Patch6: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-fix.patch
# permit a deflateParams() parameter change
Patch12: zlib-1.2.11-permit-deflateParams-change.patch
Patch7: zlib-1.2.11-permit-deflateParams-change.patch
# fixed DFLTCC compression level switching issues
# enabled HW compression for compression levels 1 through 6
Patch13: zlib-1.2.11-IBM-DFLTCC-compression-level-switching-issues.patch
Patch8: zlib-1.2.11-IBM-DFLTCC-compression-level-switching-issues.patch
# fixed inflateSyncPoint() bad return value on z15
Patch14: zlib-1.2.11-inflateSyncPoint-return-value-fix.patch
# fixed issues found by covscan for rhel-9
# ref: https://github.com/madler/zlib/pull/554
Patch15: zlib-1.2.11-covscan-issues-rhel9.patch
Patch9: zlib-1.2.11-inflateSyncPoint-return-value-fix.patch
Patch10: zlib-1.2.11-CVE-2018-25032.patch
# Fix the compressBound() on z15
Patch11: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch
# Fix CVE-2022-37434
Patch12: zlib-1.2.11-cve-2022-37434.patch
Patch13: zlib-1.2.11-cve-2022-37434_2.patch
# Fix setting strm.adler on z15
Patch14: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-strm-adler-fix.patch
# Optimization for z15
Patch15: zlib-1.2.11-IBM-Z-hw-accelrated-inflate-small-window.patch
# Optimized crc32 for Power 8+ processors
# Source: https://github.com/madler/zlib/pull/750
Patch16: zlib-1.2.11-Preparation-for-Power-optimizations.patch
Patch17: zlib-1.2.11-Add-Power8-optimized-crc32.patch
Patch18: zlib-1.2.11-Fix-clang-s-behavior-on-versions-7.patch
# Fix for Unnecessary IFUNC resolver for crc32_z
# Fix for s390x vectorize CRC32
Patch16: zlib-1.2.11-s390x-vectorize-crc32.patch
# fix for IBM Z optimalizations
Patch17: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch
Patch18: zlib-1.2.11-CVE-2018-25032.patch
Patch19: zlib-1.2.11-s390x-vectorize-crc32.patch
# Fix for CVE-2022-37434
Patch19: zlib-1.2.11-cve-2022-37434.patch
Patch20: zlib-1.2.11-cve-2022-37434_2.patch
# Fix for python3.11 broken libxml2 and lxml on s390x
Patch20: zlib-1.2.11-Fix-broken-libxml2-for-python311.patch
# fixed covscan issues
Patch21: zlib-1.2.11-covscan-issues.patch
# Fix for Crash in zlib deflateBound() function on s390x
# Resolves: #2193045
Patch22: zlib-1.2.11-IBM-Z-hw-accelrated-deflate-fix-crash-deflateBound.patch
BuildRequires: make
BuildRequires: automake, autoconf, libtool
%global __provides_exclude_from ^%{_libdir}/pkgconfig/minizip\\.pc$
%description
Zlib is a general-purpose, patent-free, lossless data compression
library which is used by many different programs.
@ -75,21 +89,20 @@ decompression library.
%if %{with minizip}
%package -n minizip-compat
%package -n minizip
Summary: Library for manipulation with .zip archives
Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n minizip-compat
%description -n minizip
Minizip is a library for manipulation with files from .zip archives.
%package -n minizip-compat-devel
%package -n minizip-devel
Summary: Development files for the minizip library
Requires: minizip-compat%{?_isa} = %{version}-%{release}
Requires: minizip%{?_isa} = %{version}-%{release}
Requires: %{name}-devel%{?_isa} = %{version}-%{release}
Conflicts: minizip-devel
%description -n minizip-compat-devel
%description -n minizip-devel
This package contains the libraries and header files needed for
developing applications which use minizip.
%endif
@ -101,6 +114,9 @@ developing applications which use minizip.
%ifarch s390 s390x
%patch1 -p1 -b .optimized-deflate
%endif
%patch2 -p1
%patch3 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
@ -115,6 +131,8 @@ developing applications which use minizip.
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
iconv -f iso-8859-2 -t utf-8 < ChangeLog > ChangeLog.tmp
@ -123,13 +141,16 @@ mv ChangeLog.tmp ChangeLog
%build
export CFLAGS="$RPM_OPT_FLAGS"
%ifarch ppc64
CFLAGS+=" -O3"
%endif
export LDFLAGS="$LDFLAGS -Wl,-z,relro -Wl,-z,now"
# no-autotools, %%configure is not compatible
%ifarch s390 s390x
./configure --libdir=%{_libdir} --includedir=%{_includedir} --prefix=%{_prefix} --dfltcc
./configure --libdir=%{_libdir} --includedir=%{_includedir} --prefix=%{_prefix} --dfltcc
%else
./configure --libdir=%{_libdir} --includedir=%{_includedir} --prefix=%{_prefix}
./configure --libdir=%{_libdir} --includedir=%{_includedir} --prefix=%{_prefix}
%endif
%make_build
@ -178,12 +199,12 @@ find $RPM_BUILD_ROOT -name '*.la' -delete
%if %{with minizip}
%files -n minizip-compat
%files -n minizip
%doc contrib/minizip/MiniZip64_info.txt contrib/minizip/MiniZip64_Changes.txt
%{_libdir}/libminizip.so.*
%files -n minizip-compat-devel
%files -n minizip-devel
%dir %{_includedir}/minizip
%{_includedir}/minizip/*.h
%{_libdir}/libminizip.so
@ -192,93 +213,70 @@ find $RPM_BUILD_ROOT -name '*.la' -delete
%changelog
* Wed Aug 10 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-34
* Tue May 16 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-25
- Fix the Crash in zlib deflateBound() function on s390x
- Resolves: BZ#2193045
* Tue May 16 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-24
- Resolve fuzzing issue for unknown memory access
* Tue May 09 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-23
- Rebased Power 8 optimization patches
- Fix for Unnecessary IFUNC resolver for crc32_z
- Fix for python3.11 broken libxml2 and lxml on s390x
* Tue May 09 2023 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-22
- Inflate small window optimization for IBM z15 rhbz#2154775
* Wed Oct 12 2022 Ilya Leoshkevich <iii@linux.ibm.com> - 1.2.11-21
- Fix for IBM strm.adler rhbz#2134074
* Tue Aug 09 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-20
- Fix heap-based buffer over-read or buffer overflow in inflate in inflate.c
- Resolves: CVE-2022-37434
* Mon Apr 25 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-33
- Fix CVE-2018-25032
Resolves: CVE-2018-25032
* Mon May 16 2022 Lukas Javorsky <ljavorsk@redhat.com> - 1.2.11-19
- Apply IBM patch for compressBound() function
- Source from https://github.com/madler/zlib/issues/410#issuecomment-947212824
- Resolves: #2056900
* Tue Mar 01 2022 Ilya Leoshkevich <iii@linux.ibm.com> - 1.2.11-32
- Fix for IBM compressBound() rhbz#2056899
* Tue Mar 29 2022 Matej Mužila <mmuzila@redhat.com> - 1.2.11-18
- Resolves: CVE-2018-25032
* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 1.2.11-31
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Mon Jun 15 2020 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-17
- Fixed DFLTCC compression level switching issues (#1875492)
- Enabled HW compression for compression levels 1 through 6 (#1847438)
- Fixed inflateSyncPoint() bad return value on z15 (#1888930)
* Tue Jul 20 2021 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-30
- Fix for IBM CRC32 optimalization rhbz#1959423
* Mon Jun 15 2020 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-16
- Permit a deflateParams() parameter change
- Another fix for Z hardware-accelerated deflate for s390x architectures
- according to previous change by upstream
* Thu Jul 15 2021 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-29
- Missing RPM_OPT_FLAGS in CFLAGS (#1972057)
* Mon Jun 15 2020 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-15
- Another fix for Z hardware-accelerated deflate for s390x architectures
* Thu Jun 03 2021 Patrik Novotný <panovotn@redhat.com> - 1.2.11-28
- IBM CRC32 optimalization rhbz#1959423
- Enabled Z hardware-accelerated deflate for compression levels 1 through 6 (#1972057)
* Mon May 25 2020 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-14
- Fix for Z hardware-accelerated deflate for s390x architectures
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 1.2.11-27
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
* Wed Mar 31 2021 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-26
- fixed covscan issues for rhel-9
* Fri Feb 12 2021 Michal Schorm <mschorm@redhat.com> - 1.2.11-25
- Remove ancient PPC64 hack
- Remove aarch64 optimalizations (#1936823)
* Thu Jan 28 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.11-24
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Wed Nov 18 2020 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-23
- backport IBM Z updates to fedora
* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.11-22
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Fri Jan 31 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.11-21
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Tue Oct 29 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-20
* Tue Oct 29 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-13
- Added -DDFLTCC parameter to configure to enable
- Z hardware-accelerated deflate for s390x architectures (#1659433)
* Thu Sep 05 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-19
- IBM CRC32 optimalization for POWER 8+ architectures re-add
- fixed firefox crash duer to zlib (#1741266)
- added test for crc32
* Tue Oct 15 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-12
- fixed covscan issues
* Thu Aug 15 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-18
- IBM CRC32 optimalization for POWER 8+ architectures revert
* Thu Aug 01 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-17
* Mon Oct 14 2019 Ondrej Dubaj <odubaj@redhat.com> - 1.2.11-11
- IBM Z hardware-accelerated deflate for s390x architectures
- IBM CRC32 optimalization for POWER 8+ architectures
* Sat Jul 27 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.11-16
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Sun Feb 03 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.11-15
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Tue Oct 2 2018 Peter Robinson <pbrobinson@fedoraproject.org> 1.2.11-14
- Bump build
* Tue Sep 18 2018 Peter Robinson <pbrobinson@fedoraproject.org> 1.2.11-13
- Revert aarch64 neon inflate optimisation
* Wed Aug 29 2018 Patrik Novotný <panovotn@redhat.com> - 1.2.11-12
- Rename minizip and minizip-devel to minizip-compat and minizip-compat-devel respectively
* Thu Aug 23 2018 Patrik Novotný <panovotn@redhat.com> - 1.2.11-11
- Provides minizip-compat and minizip-compat-devel
- fixed firefox crash due to zlib (#1741266)
- added test for crc32
* Fri Aug 03 2018 Pavel Raiskup <praiskup@redhat.com> - 1.2.11-10
- add %%bcond for minizip
- use %%make_* macros
- sync with fedora rawhide
* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.2.11-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Fri May 25 2018 Pavel Raiskup <praiskup@redhat.com> - 1.2.11-9
- revert previous aarch64 changes (rhbz#1582444, rhbz#1578798)
* Mon Apr 30 2018 Peter Robinson <pbrobinson@fedoraproject.org> 1.2.11-8
- Optimisations for aarch64