adenilson / rpms / zlib

Forked from rpms/zlib 8 months ago
Clone

Blame SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch

b8b43e
Source from https://gitlab.com/redhat/centos-stream/rpms/zlib/-/merge_requests/9
b8b43e
Author: Ilya Leoshkevich
b8b43e
b8b43e
--- a/compress.c
b8b43e
+++ b/compress.c
b8b43e
@@ -5,9 +5,15 @@
b8b43e
 
b8b43e
 /* @(#) $Id$ */
b8b43e
 
b8b43e
-#define ZLIB_INTERNAL
b8b43e
+#include "zutil.h"
b8b43e
 #include "zlib.h"
b8b43e
 
b8b43e
+#ifdef DFLTCC
b8b43e
+#  include "contrib/s390/dfltcc.h"
b8b43e
+#else
b8b43e
+#define DEFLATE_BOUND_COMPLEN(source_len) 0
b8b43e
+#endif
b8b43e
+
b8b43e
 /* ===========================================================================
b8b43e
      Compresses the source buffer into the destination buffer. The level
b8b43e
    parameter has the same meaning as in deflateInit.  sourceLen is the byte
b8b43e
@@ -81,6 +87,12 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
b8b43e
 uLong ZEXPORT compressBound (sourceLen)
b8b43e
     uLong sourceLen;
b8b43e
 {
b8b43e
+    uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen);
b8b43e
+
b8b43e
+    if (complen > 0)
b8b43e
+	/* Architecture-specific code provided an upper bound. */
b8b43e
+	return complen + ZLIB_WRAPLEN;
b8b43e
+
b8b43e
     return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
b8b43e
            (sourceLen >> 25) + 13;
b8b43e
 }
b8b43e
--- a/contrib/s390/dfltcc.h
b8b43e
+++ b/contrib/s390/dfltcc.h
b8b43e
@@ -12,6 +12,28 @@ void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size));
b8b43e
 voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items,
b8b43e
                                              uInt size));
b8b43e
 void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w));
b8b43e
+#define DFLTCC_BLOCK_HEADER_BITS 3
b8b43e
+#define DFLTCC_HLITS_COUNT_BITS 5
b8b43e
+#define DFLTCC_HDISTS_COUNT_BITS 5
b8b43e
+#define DFLTCC_HCLENS_COUNT_BITS 4
b8b43e
+#define DFLTCC_MAX_HCLENS 19
b8b43e
+#define DFLTCC_HCLEN_BITS 3
b8b43e
+#define DFLTCC_MAX_HLITS 286
b8b43e
+#define DFLTCC_MAX_HDISTS 30
b8b43e
+#define DFLTCC_MAX_HLIT_HDIST_BITS 7
b8b43e
+#define DFLTCC_MAX_SYMBOL_BITS 16
b8b43e
+#define DFLTCC_MAX_EOBS_BITS 15
b8b43e
+#define DFLTCC_MAX_PADDING_BITS 7
b8b43e
+#define DEFLATE_BOUND_COMPLEN(source_len) \
b8b43e
+    ((DFLTCC_BLOCK_HEADER_BITS + \
b8b43e
+      DFLTCC_HLITS_COUNT_BITS + \
b8b43e
+      DFLTCC_HDISTS_COUNT_BITS + \
b8b43e
+      DFLTCC_HCLENS_COUNT_BITS + \
b8b43e
+      DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \
b8b43e
+      (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \
b8b43e
+      (source_len) * DFLTCC_MAX_SYMBOL_BITS + \
b8b43e
+      DFLTCC_MAX_EOBS_BITS + \
b8b43e
+      DFLTCC_MAX_PADDING_BITS) >> 3)
b8b43e
 int ZLIB_INTERNAL dfltcc_can_inflate OF((z_streamp strm));
b8b43e
 typedef enum {
b8b43e
     DFLTCC_INFLATE_CONTINUE,
b8b43e
diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h
b8b43e
index 03f7f53..46acfc5 100644
b8b43e
--- a/contrib/s390/dfltcc_deflate.h
b8b43e
+++ b/contrib/s390/dfltcc_deflate.h
b8b43e
@@ -46,8 +46,7 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm,
b8b43e
 #define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
b8b43e
     do { \
b8b43e
         if (dfltcc_can_deflate((strm))) \
b8b43e
-            (complen) = (3 + 5 + 5 + 4 + 19 * 3 + (286 + 30) * 7 + \
b8b43e
-                         (source_len) * 16 + 15 + 7) >> 3; \
b8b43e
+            (complen) = DEFLATE_BOUND_COMPLEN(source_len); \
b8b43e
     } while (0)
b8b43e
 #define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
b8b43e
 #define DEFLATE_HOOK dfltcc_deflate
b8b43e
diff --git a/zutil.h b/zutil.h
b8b43e
index 14277bc..cf90e49 100644
b8b43e
--- a/zutil.h
b8b43e
+++ b/zutil.h
b8b43e
@@ -87,6 +87,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
b8b43e
 
b8b43e
 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
b8b43e
 
b8b43e
+#define ZLIB_WRAPLEN 6 /* zlib format overhead */
b8b43e
+
b8b43e
         /* target dependencies */
b8b43e
 
b8b43e
 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))