Skip to content

Commit

Permalink
Disable zlib-ng if zlib is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
data-man committed Dec 21, 2021
1 parent e9ec44f commit 6176c99
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 42 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ ifeq "$(DONT_BUILD_ZLIB)" "1"
DEFINES += -DBENCH_REMOVE_ZLIB
DONT_BUILD_SLZ = 1
else
DONT_BUILD_ZLIB_NG = 1
ZLIB_FILES = zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzclose.o zlib/gzlib.o zlib/gzread.o
ZLIB_FILES += zlib/gzwrite.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o
ZLIB_FILES += zlib/uncompr.o zlib/zutil.o
Expand Down
2 changes: 1 addition & 1 deletion zlib-ng/arch/x86/crc32_fold_pclmulqdq.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifdef X86_PCLMULQDQ_CRC
#include "../../zutil.h"

#include <inttypes.h>
#include <stdint.h>
#include <immintrin.h>
#include <wmmintrin.h>

Expand Down
9 changes: 5 additions & 4 deletions zlib-ng/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ z_size_t Z_EXPORT PREFIX(compressBound)(z_size_t sourceLen) {
return complen + ZLIB_WRAPLEN;

#ifndef NO_QUICK_STRATEGY
/* Quick deflate strategy worse case is 9 bits per literal, rounded to nearest byte,
plus the size of block & gzip headers and footers */
return sourceLen + ((sourceLen + 13 + 7) >> 3) + 18;
return sourceLen /* The source size itself */
+ DEFLATE_QUICK_OVERHEAD(sourceLen) /* Source encoding overhead, padded to next full byte */
+ DEFLATE_BLOCK_OVERHEAD /* Deflate block overhead bytes */
+ ZLIB_WRAPLEN; /* zlib wrapper */
#else
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13;
return sourceLen + (sourceLen >> 4) + 7 + ZLIB_WRAPLEN;
#endif
}
2 changes: 1 addition & 1 deletion zlib-ng/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "zbuild.h"
#include "zendian.h"
#include <inttypes.h>
#include <stdint.h>
#include "deflate.h"
#include "functable.h"
#include "crc32_tbl.h"
Expand Down
13 changes: 8 additions & 5 deletions zlib-ng/crc32_comb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
*/

#include "zbuild.h"
#include <inttypes.h>
#include <stdint.h>
#include "deflate.h"
#include "crc32_p.h"
#include "crc32_comb_tbl.h"


/* Local functions for crc concatenation */
static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2);
static void crc32_combine_gen_(uint32_t *op, z_off64_t len2);
static void crc32_combine_gen_(uint32_t op[GF2_DIM], z_off64_t len2);

/* ========================================================================= */
static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
Expand Down Expand Up @@ -49,7 +49,7 @@ uint32_t Z_EXPORT PREFIX4(crc32_combine)(uint32_t crc1, uint32_t crc2, z_off64_t

/* ========================================================================= */

static void crc32_combine_gen_(uint32_t *op, z_off64_t len2) {
static void crc32_combine_gen_(uint32_t op[GF2_DIM], z_off64_t len2) {
uint32_t row;
int j;
unsigned i;
Expand Down Expand Up @@ -96,11 +96,14 @@ static void crc32_combine_gen_(uint32_t *op, z_off64_t len2) {
void Z_EXPORT PREFIX(crc32_combine_gen)(uint32_t *op, z_off_t len2) {
crc32_combine_gen_(op, len2);
}
#endif

void Z_EXPORT PREFIX4(crc32_combine_gen)(uint32_t *op, z_off64_t len2) {
crc32_combine_gen_(op, len2);
}
#else
void Z_EXPORT PREFIX4(crc32_combine_gen)(uint32_t op[GF2_DIM], z_off64_t len2) {
crc32_combine_gen_(op, len2);
}
#endif

/* ========================================================================= */
uint32_t Z_EXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t *op) {
Expand Down
16 changes: 11 additions & 5 deletions zlib-ng/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
wraplen = 0;
break;
case 1: /* zlib wrapper */
wraplen = 6 + (s->strstart ? 4 : 0);
wraplen = ZLIB_WRAPLEN + (s->strstart ? 4 : 0);
break;
#ifdef GZIP
case 2: /* gzip wrapper */
wraplen = 18;
wraplen = GZIP_WRAPLEN;
if (s->gzhead != NULL) { /* user-supplied gzip header */
unsigned char *str;
if (s->gzhead->extra != NULL) {
Expand All @@ -639,16 +639,22 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
break;
#endif
default: /* for compiler happiness */
wraplen = 6;
wraplen = ZLIB_WRAPLEN;
}

/* if not default parameters, return conservative bound */
if (DEFLATE_NEED_CONSERVATIVE_BOUND(strm) || /* hook for IBM Z DFLTCC */
s->w_bits != 15 || HASH_BITS < 15)
return complen + wraplen;

/* default settings: return tight bound for that case */
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13 - 6 + wraplen;
#ifndef NO_QUICK_STRATEGY
return sourceLen /* The source size itself */
+ DEFLATE_QUICK_OVERHEAD(sourceLen) /* Source encoding overhead, padded to next full byte */
+ DEFLATE_BLOCK_OVERHEAD /* Deflate block overhead bytes */
+ wraplen; /* none, zlib or gzip wrapper */
#else
return sourceLen + (sourceLen >> 4) + 7 + wraplen;
#endif
}

/* =========================================================================
Expand Down
7 changes: 1 addition & 6 deletions zlib-ng/gzguts.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ void Z_INTERNAL gz_error(gz_state *, int, const char *);
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
value -- needed when comparing unsigned to z_off64_t, which is signed
(possible z_off64_t types off_t, off64_t, and long are all signed) */
#ifdef INT_MAX
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
#else
unsigned Z_INTERNAL gz_intmax(void);
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)

#endif /* GZGUTS_H_ */
18 changes: 0 additions & 18 deletions zlib-ng/gzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,3 @@ void Z_INTERNAL gz_error(gz_state *state, int err, const char *msg) {
}
(void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, "%s%s%s", state->path, ": ", msg);
}

#ifndef INT_MAX
/* portably return maximum value for an int (when limits.h presumed not
available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */
unsigned Z_INTERNAL gz_intmax() {
unsigned p, q;

p = 1;
do {
q = p;
p <<= 1;
p++;
} while (p > q);
return q >> 1;
}
#endif
1 change: 0 additions & 1 deletion zlib-ng/trees_emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifdef ZLIB_DEBUG
# include <ctype.h>
# include <inttypes.h>
# include <stdint.h>
#endif


Expand Down
14 changes: 13 additions & 1 deletion zlib-ng/zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
#define ADLER32_INITIAL_VALUE 1 /* initial adler-32 hash value */
#define CRC32_INITIAL_VALUE 0 /* initial crc-32 hash value */

#define ZLIB_WRAPLEN 6 /* zlib format overhead */
#define ZLIB_WRAPLEN 6 /* zlib format overhead */
#define GZIP_WRAPLEN 18 /* gzip format overhead */

#define DEFLATE_HEADER_BITS 3
#define DEFLATE_EOBS_BITS 15
#define DEFLATE_PAD_BITS 6
#define DEFLATE_BLOCK_OVERHEAD ((DEFLATE_HEADER_BITS + DEFLATE_EOBS_BITS + DEFLATE_PAD_BITS) >> 3)
/* deflate block overhead: 3 bits for block start + 15 bits for block end + padding to nearest byte */

#define DEFLATE_QUICK_LIT_MAX_BITS 9
#define DEFLATE_QUICK_OVERHEAD(x) ((x * (DEFLATE_QUICK_LIT_MAX_BITS - 8) + 7) >> 3)
/* deflate_quick worst-case overhead: 9 bits per literal, round up to next byte (+7) */


/* target dependencies */

Expand Down

0 comments on commit 6176c99

Please sign in to comment.