|
|
254d01 |
From 772ddd6500a74220e641782cc2ee892433197192 Mon Sep 17 00:00:00 2001
|
|
|
254d01 |
From: IBM developers
|
|
|
254d01 |
Date: Mon, 25 May 2020 14:09:48 +0200
|
|
|
254d01 |
Subject: [PATCH] Fix for Z hardware-accelerated deflate for s390x
|
|
|
254d01 |
architectures
|
|
|
254d01 |
|
|
|
254d01 |
---
|
|
|
254d01 |
configure | 7 +++
|
|
|
254d01 |
contrib/s390/dfltcc.c | 94 ++++++++++++++++++++---------------
|
|
|
254d01 |
contrib/s390/dfltcc_deflate.h | 10 ++--
|
|
|
254d01 |
deflate.c | 12 +++--
|
|
|
254d01 |
4 files changed, 76 insertions(+), 47 deletions(-)
|
|
|
254d01 |
|
|
|
254d01 |
diff --git a/configure b/configure
|
|
|
254d01 |
index 66caece..bfe4386 100755
|
|
|
254d01 |
--- a/configure
|
|
|
254d01 |
+++ b/configure
|
|
|
254d01 |
@@ -114,6 +114,7 @@ case "$1" in
|
|
|
254d01 |
echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log
|
|
|
254d01 |
echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
|
|
|
254d01 |
echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
|
|
|
254d01 |
+ echo ' [--dfltcc]' | tee -a configure.log
|
|
|
254d01 |
exit 0 ;;
|
|
|
254d01 |
-p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
|
|
|
254d01 |
-e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
|
|
|
254d01 |
@@ -137,6 +138,12 @@ case "$1" in
|
|
|
254d01 |
-c* | --const) zconst=1; shift ;;
|
|
|
254d01 |
-w* | --warn) warn=1; shift ;;
|
|
|
254d01 |
-d* | --debug) debug=1; shift ;;
|
|
|
254d01 |
+ --dfltcc)
|
|
|
254d01 |
+ CFLAGS="$CFLAGS -DDFLTCC"
|
|
|
254d01 |
+ OBJC="$OBJC dfltcc.o"
|
|
|
254d01 |
+ PIC_OBJC="$PIC_OBJC dfltcc.lo"
|
|
|
254d01 |
+ shift
|
|
|
254d01 |
+ ;;
|
|
|
254d01 |
*)
|
|
|
254d01 |
echo "unknown option: $1" | tee -a configure.log
|
|
|
254d01 |
echo "$0 --help for help" | tee -a configure.log
|
|
|
254d01 |
diff --git a/contrib/s390/dfltcc.c b/contrib/s390/dfltcc.c
|
|
|
254d01 |
index d187796..face8f1 100644
|
|
|
254d01 |
--- a/contrib/s390/dfltcc.c
|
|
|
254d01 |
+++ b/contrib/s390/dfltcc.c
|
|
|
254d01 |
@@ -2,8 +2,8 @@
|
|
|
254d01 |
|
|
|
254d01 |
/*
|
|
|
254d01 |
Use the following commands to build zlib with DFLTCC support:
|
|
|
254d01 |
- $ CFLAGS=-DDFLTCC ./configure
|
|
|
254d01 |
- $ make OBJA=dfltcc.o PIC_OBJA=dfltcc.lo
|
|
|
254d01 |
+ $ ./configure --dfltcc
|
|
|
254d01 |
+ $ make
|
|
|
254d01 |
*/
|
|
|
254d01 |
|
|
|
254d01 |
#define _GNU_SOURCE
|
|
|
254d01 |
@@ -230,31 +230,28 @@ struct dfltcc_state {
|
|
|
254d01 |
/*
|
|
|
254d01 |
Compress.
|
|
|
254d01 |
*/
|
|
|
254d01 |
-local inline int dfltcc_are_params_ok(int level,
|
|
|
254d01 |
- uInt window_bits,
|
|
|
254d01 |
- int strategy,
|
|
|
254d01 |
- uLong level_mask);
|
|
|
254d01 |
-local inline int dfltcc_are_params_ok(level, window_bits, strategy, level_mask)
|
|
|
254d01 |
+local inline int dfltcc_can_deflate_with_params(z_streamp strm,
|
|
|
254d01 |
+ int level,
|
|
|
254d01 |
+ uInt window_bits,
|
|
|
254d01 |
+ int strategy);
|
|
|
254d01 |
+local inline int dfltcc_can_deflate_with_params(strm,
|
|
|
254d01 |
+ level,
|
|
|
254d01 |
+ window_bits,
|
|
|
254d01 |
+ strategy)
|
|
|
254d01 |
+ z_streamp strm;
|
|
|
254d01 |
int level;
|
|
|
254d01 |
uInt window_bits;
|
|
|
254d01 |
int strategy;
|
|
|
254d01 |
- uLong level_mask;
|
|
|
254d01 |
-{
|
|
|
254d01 |
- return (level_mask & (1 << level)) != 0 &&
|
|
|
254d01 |
- (window_bits == HB_BITS) &&
|
|
|
254d01 |
- (strategy == Z_FIXED || strategy == Z_DEFAULT_STRATEGY);
|
|
|
254d01 |
-}
|
|
|
254d01 |
-
|
|
|
254d01 |
-
|
|
|
254d01 |
-int ZLIB_INTERNAL dfltcc_can_deflate(strm)
|
|
|
254d01 |
- z_streamp strm;
|
|
|
254d01 |
{
|
|
|
254d01 |
deflate_state FAR *state = (deflate_state FAR *)strm->state;
|
|
|
254d01 |
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
|
|
|
254d01 |
|
|
|
254d01 |
/* Unsupported compression settings */
|
|
|
254d01 |
- if (!dfltcc_are_params_ok(state->level, state->w_bits, state->strategy,
|
|
|
254d01 |
- dfltcc_state->level_mask))
|
|
|
254d01 |
+ if ((dfltcc_state->level_mask & (1 << level)) == 0)
|
|
|
254d01 |
+ return 0;
|
|
|
254d01 |
+ if (window_bits != HB_BITS)
|
|
|
254d01 |
+ return 0;
|
|
|
254d01 |
+ if (strategy != Z_FIXED && strategy != Z_DEFAULT_STRATEGY)
|
|
|
254d01 |
return 0;
|
|
|
254d01 |
|
|
|
254d01 |
/* Unsupported hardware */
|
|
|
254d01 |
@@ -266,6 +263,17 @@ int ZLIB_INTERNAL dfltcc_can_deflate(strm)
|
|
|
254d01 |
return 1;
|
|
|
254d01 |
}
|
|
|
254d01 |
|
|
|
254d01 |
+int ZLIB_INTERNAL dfltcc_can_deflate(strm)
|
|
|
254d01 |
+ z_streamp strm;
|
|
|
254d01 |
+{
|
|
|
254d01 |
+ deflate_state FAR *state = (deflate_state FAR *)strm->state;
|
|
|
254d01 |
+
|
|
|
254d01 |
+ return dfltcc_can_deflate_with_params(strm,
|
|
|
254d01 |
+ state->level,
|
|
|
254d01 |
+ state->w_bits,
|
|
|
254d01 |
+ state->strategy);
|
|
|
254d01 |
+}
|
|
|
254d01 |
+
|
|
|
254d01 |
local void dfltcc_gdht OF((z_streamp strm));
|
|
|
254d01 |
local void dfltcc_gdht(strm)
|
|
|
254d01 |
z_streamp strm;
|
|
|
254d01 |
@@ -349,22 +357,24 @@ again:
|
|
|
254d01 |
soft_bcc = 0;
|
|
|
254d01 |
no_flush = flush == Z_NO_FLUSH;
|
|
|
254d01 |
|
|
|
254d01 |
- /* Trailing empty block. Switch to software, except when Continuation Flag
|
|
|
254d01 |
- * is set, which means that DFLTCC has buffered some output in the
|
|
|
254d01 |
- * parameter block and needs to be called again in order to flush it.
|
|
|
254d01 |
+ /* No input data. Return, except when Continuation Flag is set, which means
|
|
|
254d01 |
+ * that DFLTCC has buffered some output in the parameter block and needs to
|
|
|
254d01 |
+ * be called again in order to flush it.
|
|
|
254d01 |
*/
|
|
|
254d01 |
- if (flush == Z_FINISH && strm->avail_in == 0 && !param->cf) {
|
|
|
254d01 |
- if (param->bcf) {
|
|
|
254d01 |
- /* A block is still open, and the hardware does not support closing
|
|
|
254d01 |
- * blocks without adding data. Thus, close it manually.
|
|
|
254d01 |
- */
|
|
|
254d01 |
+ if (strm->avail_in == 0 && !param->cf) {
|
|
|
254d01 |
+ /* A block is still open, and the hardware does not support closing
|
|
|
254d01 |
+ * blocks without adding data. Thus, close it manually.
|
|
|
254d01 |
+ */
|
|
|
254d01 |
+ if (!no_flush && param->bcf) {
|
|
|
254d01 |
send_eobs(strm, param);
|
|
|
254d01 |
param->bcf = 0;
|
|
|
254d01 |
}
|
|
|
254d01 |
- return 0;
|
|
|
254d01 |
- }
|
|
|
254d01 |
-
|
|
|
254d01 |
- if (strm->avail_in == 0 && !param->cf) {
|
|
|
254d01 |
+ /* Let one of deflate_* functions write a trailing empty block. */
|
|
|
254d01 |
+ if (flush == Z_FINISH)
|
|
|
254d01 |
+ return 0;
|
|
|
254d01 |
+ /* Clear history. */
|
|
|
254d01 |
+ if (flush == Z_FULL_FLUSH)
|
|
|
254d01 |
+ param->hl = 0;
|
|
|
254d01 |
*result = need_more;
|
|
|
254d01 |
return 1;
|
|
|
254d01 |
}
|
|
|
254d01 |
@@ -418,7 +428,7 @@ again:
|
|
|
254d01 |
param->cvt = state->wrap == 2 ? CVT_CRC32 : CVT_ADLER32;
|
|
|
254d01 |
if (!no_flush)
|
|
|
254d01 |
/* We need to close a block. Always do this in software - when there is
|
|
|
254d01 |
- * no input data, the hardware will not nohor BCC. */
|
|
|
254d01 |
+ * no input data, the hardware will not honor BCC. */
|
|
|
254d01 |
soft_bcc = 1;
|
|
|
254d01 |
if (flush == Z_FINISH && !param->bcf)
|
|
|
254d01 |
/* We are about to open a BFINAL block, set Block Header Final bit
|
|
|
254d01 |
@@ -433,8 +443,8 @@ again:
|
|
|
254d01 |
param->sbb = (unsigned int)state->bi_valid;
|
|
|
254d01 |
if (param->sbb > 0)
|
|
|
254d01 |
*strm->next_out = (Bytef)state->bi_buf;
|
|
|
254d01 |
- if (param->hl)
|
|
|
254d01 |
- param->nt = 0; /* Honor history */
|
|
|
254d01 |
+ /* Honor history and check value */
|
|
|
254d01 |
+ param->nt = 0;
|
|
|
254d01 |
param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler;
|
|
|
254d01 |
|
|
|
254d01 |
/* When opening a block, choose a Huffman-Table Type */
|
|
|
254d01 |
@@ -792,17 +802,20 @@ void ZLIB_INTERNAL dfltcc_free_window(strm, w)
|
|
|
254d01 |
fly with deflateParams, we need to convert between hardware and software
|
|
|
254d01 |
window formats.
|
|
|
254d01 |
*/
|
|
|
254d01 |
-int ZLIB_INTERNAL dfltcc_deflate_params(strm, level, strategy)
|
|
|
254d01 |
+int ZLIB_INTERNAL dfltcc_deflate_params(strm, level, strategy, flush)
|
|
|
254d01 |
z_streamp strm;
|
|
|
254d01 |
int level;
|
|
|
254d01 |
int strategy;
|
|
|
254d01 |
+ int *flush;
|
|
|
254d01 |
{
|
|
|
254d01 |
deflate_state FAR *state = (deflate_state FAR *)strm->state;
|
|
|
254d01 |
struct dfltcc_state FAR *dfltcc_state = GET_DFLTCC_STATE(state);
|
|
|
254d01 |
struct dfltcc_param_v0 FAR *param = &dfltcc_state->param;
|
|
|
254d01 |
int could_deflate = dfltcc_can_deflate(strm);
|
|
|
254d01 |
- int can_deflate = dfltcc_are_params_ok(level, state->w_bits, strategy,
|
|
|
254d01 |
- dfltcc_state->level_mask);
|
|
|
254d01 |
+ int can_deflate = dfltcc_can_deflate_with_params(strm,
|
|
|
254d01 |
+ level,
|
|
|
254d01 |
+ state->w_bits,
|
|
|
254d01 |
+ strategy);
|
|
|
254d01 |
|
|
|
254d01 |
if (can_deflate == could_deflate)
|
|
|
254d01 |
/* We continue to work in the same mode - no changes needed */
|
|
|
254d01 |
@@ -812,8 +825,11 @@ int ZLIB_INTERNAL dfltcc_deflate_params(strm, level, strategy)
|
|
|
254d01 |
/* DFLTCC was not used yet - no changes needed */
|
|
|
254d01 |
return Z_OK;
|
|
|
254d01 |
|
|
|
254d01 |
- /* Switching between hardware and software is not implemented */
|
|
|
254d01 |
- return Z_STREAM_ERROR;
|
|
|
254d01 |
+ /* For now, do not convert between window formats - simply get rid of the
|
|
|
254d01 |
+ * old data instead.
|
|
|
254d01 |
+ */
|
|
|
254d01 |
+ *flush = Z_FULL_FLUSH;
|
|
|
254d01 |
+ return Z_OK;
|
|
|
254d01 |
}
|
|
|
254d01 |
|
|
|
254d01 |
/*
|
|
|
254d01 |
diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h
|
|
|
254d01 |
index a129a91..947b1e4 100644
|
|
|
254d01 |
--- a/contrib/s390/dfltcc_deflate.h
|
|
|
254d01 |
+++ b/contrib/s390/dfltcc_deflate.h
|
|
|
254d01 |
@@ -9,7 +9,8 @@ int ZLIB_INTERNAL dfltcc_deflate OF((z_streamp strm,
|
|
|
254d01 |
block_state *result));
|
|
|
254d01 |
int ZLIB_INTERNAL dfltcc_deflate_params OF((z_streamp strm,
|
|
|
254d01 |
int level,
|
|
|
254d01 |
- int strategy));
|
|
|
254d01 |
+ int strategy,
|
|
|
254d01 |
+ int *flush));
|
|
|
254d01 |
int ZLIB_INTERNAL dfltcc_deflate_set_dictionary OF((z_streamp strm,
|
|
|
254d01 |
const Bytef *dictionary,
|
|
|
254d01 |
uInt dict_length));
|
|
|
254d01 |
@@ -29,11 +30,14 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm,
|
|
|
254d01 |
} while (0)
|
|
|
254d01 |
#define DEFLATE_RESET_KEEP_HOOK(strm) \
|
|
|
254d01 |
dfltcc_reset((strm), sizeof(deflate_state))
|
|
|
254d01 |
-#define DEFLATE_PARAMS_HOOK(strm, level, strategy) \
|
|
|
254d01 |
+#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) \
|
|
|
254d01 |
do { \
|
|
|
254d01 |
int err; \
|
|
|
254d01 |
\
|
|
|
254d01 |
- err = dfltcc_deflate_params((strm), (level), (strategy)); \
|
|
|
254d01 |
+ err = dfltcc_deflate_params((strm), \
|
|
|
254d01 |
+ (level), \
|
|
|
254d01 |
+ (strategy), \
|
|
|
254d01 |
+ (hook_flush)); \
|
|
|
254d01 |
if (err == Z_STREAM_ERROR) \
|
|
|
254d01 |
return err; \
|
|
|
254d01 |
} while (0)
|
|
|
254d01 |
diff --git a/deflate.c b/deflate.c
|
|
|
254d01 |
index 9b09718..9284483 100644
|
|
|
254d01 |
--- a/deflate.c
|
|
|
254d01 |
+++ b/deflate.c
|
|
|
254d01 |
@@ -74,7 +74,7 @@ const char deflate_copyright[] =
|
|
|
254d01 |
#define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
|
|
|
254d01 |
#define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
|
|
|
254d01 |
#define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
|
|
|
254d01 |
-#define DEFLATE_PARAMS_HOOK(strm, level, strategy) do {} while (0)
|
|
|
254d01 |
+#define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0)
|
|
|
254d01 |
#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0)
|
|
|
254d01 |
#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0
|
|
|
254d01 |
#define DEFLATE_HOOK(strm, flush, bstate) 0
|
|
|
254d01 |
@@ -589,6 +589,7 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
|
|
254d01 |
{
|
|
|
254d01 |
deflate_state *s;
|
|
|
254d01 |
compress_func func;
|
|
|
254d01 |
+ int hook_flush = Z_NO_FLUSH;
|
|
|
254d01 |
|
|
|
254d01 |
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
|
|
|
254d01 |
s = strm->state;
|
|
|
254d01 |
@@ -601,13 +602,14 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
|
|
254d01 |
if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
|
|
|
254d01 |
return Z_STREAM_ERROR;
|
|
|
254d01 |
}
|
|
|
254d01 |
- DEFLATE_PARAMS_HOOK(strm, level, strategy);
|
|
|
254d01 |
+ DEFLATE_PARAMS_HOOK(strm, level, strategy, &hook_flush);
|
|
|
254d01 |
func = configuration_table[s->level].func;
|
|
|
254d01 |
|
|
|
254d01 |
- if ((strategy != s->strategy || func != configuration_table[level].func) &&
|
|
|
254d01 |
- s->high_water) {
|
|
|
254d01 |
+ if ((strategy != s->strategy || func != configuration_table[level].func ||
|
|
|
254d01 |
+ hook_flush != Z_NO_FLUSH) && s->last_flush != -2) {
|
|
|
254d01 |
/* Flush the last buffer: */
|
|
|
254d01 |
- int err = deflate(strm, Z_BLOCK);
|
|
|
254d01 |
+ int err = deflate(strm, RANK(hook_flush) > RANK(Z_BLOCK) ?
|
|
|
254d01 |
+ hook_flush : Z_BLOCK);
|
|
|
254d01 |
if (err == Z_STREAM_ERROR)
|
|
|
254d01 |
return err;
|
|
|
254d01 |
if (strm->avail_out == 0)
|
|
|
254d01 |
--
|
|
|
254d01 |
2.24.1
|
|
|
254d01 |
|