Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ crc32.o: $(SRCDIR)crc32.c
crc32_vx.o: $(SRCDIR)contrib/crc32vx/crc32_vx.c
$(CC) $(CFLAGS) $(VGFMAFLAG) $(ZINC) -c -o $@ $(SRCDIR)contrib/crc32vx/crc32_vx.c

dfltcc.o: $(SRCDIR)contrib/dfltcc/dfltcc.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)contrib/dfltcc/dfltcc.c

deflate.o: $(SRCDIR)deflate.c
$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c

Expand Down Expand Up @@ -223,6 +226,11 @@ crc32_vx.lo: $(SRCDIR)contrib/crc32vx/crc32_vx.c
$(CC) $(SFLAGS) $(VGFMAFLAG) $(ZINC) -DPIC -c -o objs/crc32_vx.o $(SRCDIR)contrib/crc32vx/crc32_vx.c
-@mv objs/crc32_vx.o $@

dfltcc.lo: $(SRCDIR)contrib/dfltcc/dfltcc.c
-@mkdir objs 2>/dev/null || test -d objs
$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/dfltcc/dfltcc.c
-@mv objs/dfltcc.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
Expand Down Expand Up @@ -296,6 +304,9 @@ 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_LIBS)

example$(EXE): example.o $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TEST_LIBS)

Expand All @@ -308,6 +319,9 @@ examplesh$(EXE): example.o $(SHAREDLIBV)
minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV)

crc32_test64$(EXE): crc32_test64.o $(STATICLIB)
$(CC) $(CFLAGS) -o $@ crc32_test64.o $(TEST_LIBS)

example64$(EXE): example64.o $(STATICLIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS)

Expand Down Expand Up @@ -416,6 +430,7 @@ inffast.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR
inftrees.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
crc32_vx.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)contrib/crc32vx/crc32_vx_hooks.h
dfltcc.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)contrib/dfltcc/dfltcc_hooks.h $(SRCDIR)contrib/dfltcc/dfltcc.h

adler32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
Expand All @@ -427,4 +442,5 @@ infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftree
inffast.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
inftrees.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
trees.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
crc32_vx.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)contrib/crc32vx/crc32_vx_hooks.h
crc32_vx.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)contrib/crc32vx/crc32_vx_hooks.h
dfltcc.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)contrib/dfltcc/dfltcc_hooks.h $(SRCDIR)contrib/dfltcc/dfltcc.h
13 changes: 11 additions & 2 deletions compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#define ZLIB_INTERNAL
#include "zlib.h"
#include "contrib/dfltcc/dfltcc_hooks.h"

#define ZLIB_WRAPLEN 6 /* zlib format overhead */

/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
Expand Down Expand Up @@ -90,6 +93,12 @@ z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) {
return bound < sourceLen ? (z_size_t)-1 : bound;
}
uLong ZEXPORT compressBound(uLong sourceLen) {
z_size_t bound = compressBound_z(sourceLen);
return (uLong)bound != bound ? (uLong)-1 : (uLong)bound;
uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen);

if (complen > 0)
/* Architecture-specific code provided an upper bound. */
return complen + ZLIB_WRAPLEN;

return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13;
}
20 changes: 19 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ undefined=0
insecure=0
unknown=0
enable_crcvx=1
enable_dfltcc=0
old_cc="$CC"
old_cflags="$CFLAGS"
OBJC='$(OBJZ) $(OBJG)'
Expand Down Expand Up @@ -123,7 +124,7 @@ case "$1" in
echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log
echo ' [--insecure] [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
echo ' [--disable-crcvx]' | tee -a configure.log
echo ' [--disable-crcvx] [--dfltcc] [--dfltcc-level-mask=MASK]' | tee -a configure.log
exit 0 ;;
-p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
-e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
Expand Down Expand Up @@ -153,6 +154,10 @@ case "$1" in
--undefined) undefined=1; shift ;;
--insecure) insecure=1; shift ;;
--disable-crcvx) enable_crcvx=0; shift ;;
--dfltcc)enable_dfltcc=1; shift ;;
--dfltcc-level-mask=*)
CFLAGS="$CFLAGS -DDFLTCC_LEVEL_MASK=`echo $1 | sed 's/.*=//'`"
shift ;;
*) unknown=1; echo "unknown option ignored: $1" | tee -a configure.log; shift;;
esac
done
Expand Down Expand Up @@ -955,6 +960,17 @@ EOF
fi
fi

# enable ibm s390x dfltcc extension
HAVE_S390X_DFLTCC=0
if test $HAVE_S390X -eq 1 && test $enable_dfltcc -eq 1; then
HAVE_S390X_DFLTCC=1
echo "Enabeling s390x dfltcc extension ... Yes." | tee -a configure.log
CFLAGS="$CFLAGS -DHAVE_S390X_DFLTCC"
SFLAGS="$SFLAGS -DHAVE_S390X_DFLTCC"
OBJC="$OBJC dfltcc.o"
PIC_OBJC="$PIC_OBJC dfltcc.lo"
fi

# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
Expand Down Expand Up @@ -988,6 +1004,7 @@ echo sharedlibdir = $sharedlibdir >> configure.log
echo uname = $uname >> configure.log
echo HAVE_S390X = $HAVE_S390X >> configure.log
echo HAVE_S390X_VX = $HAVE_S390X_VX >> configure.log
echo HAVE_S390X_DFLTCC = $HAVE_S390X_DFLTCC >> configure.log
echo VGFMAFLAG = $VGFMAFLAG >> configure.log

# update Makefile with the configure results
Expand All @@ -1000,6 +1017,7 @@ sed < ${SRCDIR}Makefile.in "
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
/^LDSHARED *=/s#=.*#=$LDSHARED#
/^CPP *=/s#=.*#=$CPP#
/^VGFMAFLAG *=/s#=.*#=$VGFMAFLAG#
/^STATICLIB *=/s#=.*#=$STATICLIB#
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
Expand Down
1 change: 1 addition & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ zlib_add_contrib_feature("GVMAT64"

zlib_add_contrib_feature(INFBACK9 "with support for method 9 deflate" infback9)
zlib_add_contrib_feature(CRC32VX "with S390X-CRC32VX implementation" crc32vx On)
zlib_add_contrib_feature(DFLTCC "with S390X-DFLTCC deflate acceleration" dfltcc)
zlib_add_contrib_lib(ADA "Ada bindings" ada)
zlib_add_contrib_lib(BLAST "blast binary" blast)
zlib_add_contrib_lib(IOSTREAM3 "IOStream C++ bindings V3" iostream3)
Expand Down
4 changes: 4 additions & 0 deletions contrib/README.contrib
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ puff/ by Mark Adler <[email protected]>
crc32vx/ by Ilya Leoshkevich <[email protected]>
Hardware-accelerated CRC32 on IBM Z with Z13 VX extension.

dfltcc/ by Ilya Leoshkevich <[email protected]>
Hardware-accelerated deflate on IBM Z with Z15 DEFLATE CONVERSION CALL
instruction.

testzlib/ by Gilles Vollant <[email protected]>
Example of the use of zlib

Expand Down
61 changes: 61 additions & 0 deletions contrib/dfltcc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# check if we compile for IBM s390x
#
CHECK_C_SOURCE_COMPILES("
#ifndef __s390x__
#error
#endif
int main() {return 0;}
" HAS_S390X_SUPPORT)

#
# Check for IBM S390X - DFLTCC extensions
#
if(ZLIB_WITH_DFLTCC AND HAS_S390X_SUPPORT)
# check if we have static_assert
check_c_source_compiles("
#include <assert.h>
static_assert(1==1,\"true\");
" HAS_STATIC_ASSERT)

# check if we have secure_getenv
set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE=1)
check_c_source_compiles("
#include <stdlib.h>
int main() { char* _foo = secure_getenv(\"PWD\");return 0; }
" HAS_SECURE_GETENV)
unset(CMAKE_REQUIRED_FLAGS)

# check for specific headers
check_include_file(sys/sdt.h HAS_SYS_SDT_H)

set(definitions "-DHAVE_S390X_DFLTCC=1")
if(HAS_STATIC_ASSERT)
list(APPEND definitions "-DHAVE_STATIC_ASSERT=1")
endif()
if(HAS_SECURE_GETENV)
list(APPEND definitions "-DHAVE_SECURE_GETENV=1")
list(APPEND definitions "-D_GNU_SOURCE=1")
endif()
if(HAS_SYS_SDT_H)
list(APPEND definitions "-DHAVE_SYS_SDT_H=1")
endif()

# prepare compiling for s390x
if(ZLIB_BUILD_SHARED)
target_sources(zlib
PRIVATE
dfltcc.c
dfltcc_hooks.h
dfltcc_common.h)
target_compile_definitions(zlib PUBLIC ${definitions})
endif(ZLIB_BUILD_SHARED)
if(ZLIB_BUILD_STATIC)
target_sources(zlibstatic
PRIVATE
dfltcc.c
dfltcc_hooks.h
dfltcc_common.h)
target_compile_definitions(zlibstatic PUBLIC ${definitions})
endif(ZLIB_BUILD_STATIC)

endif(ZLIB_WITH_DFLTCC AND HAS_S390X_SUPPORT)
28 changes: 28 additions & 0 deletions contrib/dfltcc/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
IBM Z mainframes starting from version z13 provide vector instructions, which
allows vectorization of crc32. This extension is build by default when targeting
ibm s390x. However this extension can disabled if desired:

# for configure build
$ ./configure --disable-crcvx

# for cmake build
$ cmake .. -DZLIB_CRC32VX=off


IBM Z mainframes starting from version z15 provide DFLTCC instruction,
which implements deflate algorithm in hardware with estimated
compression and decompression performance orders of magnitude faster
than the current zlib and ratio comparable with that of level 1.

This directory adds DFLTCC support. In order to enable it, the following
build commands should be used:

$ ./configure --dfltcc
$ make

When built like this, zlib would compress in hardware on level 1, and in
software on all other levels. Decompression will always happen in
hardware. In order to enable DFLTCC compression for levels 1-6 (i.e. to
make it used by default) one could either configure with
--dfltcc-level-mask=0x7e or set the environment variable
DFLTCC_LEVEL_MASK to 0x7e at run time.
Loading