From: Hans Kristian Rosbach Date: Mon, 24 Apr 2017 10:47:24 +0000 (+0200) Subject: - Add adler32 to functable X-Git-Tag: 1.9.9-b1~660^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7c7119009a65f2bf554faab19583650bf5fa0f7;p=thirdparty%2Fzlib-ng.git - Add adler32 to functable - Add missing call to functableinit from inflateinit - Fix external direct calls to adler32 functions without calling functableinit --- diff --git a/Makefile.in b/Makefile.in index 8dd749ff1..07dc4ac2f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -310,7 +310,7 @@ depend: # DO NOT DELETE THIS LINE -- make depend depends on it. -adler32.o: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h +adler32.o: $(SRCDIR)/functable.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h functable.o: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable.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 @@ -321,7 +321,7 @@ deflate_medium.o: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable. deflate_slow.o: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable.h $(SRCDIR)/match.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h infback.o: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/inffixed.h inffast.o: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/memcopy.h -inflate.o: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/inffixed.h $(SRCDIR)/memcopy.h +inflate.o: $(SRCDIR)/functable.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/inffixed.h $(SRCDIR)/memcopy.h 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 zutil.o: $(SRCDIR)/zutil.h $(SRCDIR)/gzguts.h $(SRCDIR)/zlib.h zconf.h @@ -339,7 +339,7 @@ arch/x86/deflate_quick.o: $(SRCDIR)/deflate.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h arch/x86/fill_window_sse.o: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h arch/x86/x86.o: $(SRCDIR)/arch/x86/x86.h -adler32.lo: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h +adler32.lo: $(SRCDIR)/functable.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h functable.lo: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable.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 @@ -350,7 +350,7 @@ deflate_medium.lo: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable deflate_slow.lo: $(SRCDIR)/deflate.h $(SRCDIR)/deflate_p.h $(SRCDIR)/functable.h $(SRCDIR)/match.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h infback.lo: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/inffixed.h inffast.lo: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/memcopy.h -inflate.lo: $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/inffixed.h $(SRCDIR)/memcopy.h +inflate.lo: $(SRCDIR)/functable.h $(SRCDIR)/zutil.h $(SRCDIR)/zlib.h zconf.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/inffixed.h $(SRCDIR)/memcopy.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 zutil.lo: $(SRCDIR)/zutil.h $(SRCDIR)/gzguts.h $(SRCDIR)/zlib.h zconf.h diff --git a/adler32.c b/adler32.c index 7a022b9e1..dcfeecdf2 100644 --- a/adler32.c +++ b/adler32.c @@ -6,12 +6,9 @@ /* @(#) $Id$ */ #include "zutil.h" +#include "functable.h" uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t len); -#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) -extern uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len); -#endif - static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2); #define BASE 65521U /* largest prime smaller than 65536 */ @@ -148,16 +145,16 @@ uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t len) { } uint32_t ZEXPORT adler32_z(uint32_t adler, const unsigned char *buf, size_t len) { -#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) - return adler32_neon(adler, buf, len); -#else - return adler32_c(adler, buf, len); -#endif + if (functable.adler32 == NULL) + functableInit(); + return functable.adler32(adler, buf, len); } /* ========================================================================= */ uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uint32_t len) { - return adler32_z(adler, buf, len); + if (functable.adler32 == NULL) + functableInit(); + return functable.adler32(adler, buf, len); } /* ========================================================================= */ diff --git a/deflate.c b/deflate.c index 6ec9f1ead..7de68bbde 100644 --- a/deflate.c +++ b/deflate.c @@ -382,7 +382,7 @@ int ZEXPORT deflateSetDictionary(z_stream *strm, const unsigned char *dictionary /* when using zlib wrappers, compute Adler-32 for provided dictionary */ if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); + strm->adler = functable.adler32(strm->adler, dictionary, dictLength); s->wrap = 0; /* avoid computing Adler-32 in read_buf */ /* if dictionary would fill window, just replace the history */ @@ -471,7 +471,7 @@ int ZEXPORT deflateResetKeep(z_stream *strm) { crc_reset(s); else #endif - strm->adler = adler32(0L, NULL, 0); + strm->adler = functable.adler32(0L, NULL, 0); s->last_flush = Z_NO_FLUSH; _tr_init(s); @@ -782,7 +782,7 @@ int ZEXPORT deflate(z_stream *strm, int flush) { putShortMSB(s, (uint16_t)(strm->adler >> 16)); putShortMSB(s, (uint16_t)(strm->adler)); } - strm->adler = adler32(0L, NULL, 0); + strm->adler = functable.adler32(0L, NULL, 0); s->status = BUSY_STATE; /* Compression must start with an empty pending buffer */ @@ -1120,7 +1120,7 @@ ZLIB_INTERNAL unsigned read_buf(z_stream *strm, unsigned char *buf, unsigned siz { memcpy(buf, strm->next_in, len); if (strm->state->wrap == 1) - strm->adler = adler32(strm->adler, buf, len); + strm->adler = functable.adler32(strm->adler, buf, len); } strm->next_in += len; strm->total_in += len; diff --git a/functable.c b/functable.c index 9887b99bc..7d34fad74 100644 --- a/functable.c +++ b/functable.c @@ -11,6 +11,7 @@ # include "arch/x86/x86.h" #endif + #ifdef X86_SSE4_2_CRC_HASH extern Pos insert_string_sse(deflate_state *const s, const Pos str, unsigned int count); #elif defined(ARM_ACLE_CRC_HASH) @@ -23,13 +24,23 @@ extern void fill_window_sse(deflate_state *s); extern void fill_window_arm(deflate_state *s); #endif +#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) +extern uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len); +#endif + + /* ========================================================================= * Initialize functable */ + +struct functable_s functable = {NULL,NULL,NULL}; + + ZLIB_INTERNAL void functableInit() { // Initialize defaults functable.insert_string=&insert_string_c; functable.fill_window=&fill_window_c; + functable.adler32=&adler32_c; // insert_string #ifdef X86_SSE4_2_CRC_HASH @@ -48,4 +59,9 @@ ZLIB_INTERNAL void functableInit() { #elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) functable.fill_window=&fill_window_arm; #endif + + // adler32 + #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) + functable.adler32=&adler32_neon; + #endif } diff --git a/functable.h b/functable.h index a867fa27e..b7d026e56 100644 --- a/functable.h +++ b/functable.h @@ -8,11 +8,17 @@ #include "deflate.h" +uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t len); + void functableInit(); struct functable_s { void (* fill_window) (deflate_state *s); Pos (* insert_string) (deflate_state *const s, const Pos str, unsigned int count); -} functable; + uint32_t (* adler32) (uint32_t adler, const unsigned char *buf, size_t len); +}; + +extern struct functable_s functable; + #endif diff --git a/inflate.c b/inflate.c index cf0942c6f..68a41acf4 100644 --- a/inflate.c +++ b/inflate.c @@ -85,6 +85,7 @@ #include "inflate.h" #include "inffast.h" #include "memcopy.h" +#include "functable.h" #ifdef MAKEFIXED # ifndef BUILDFIXED @@ -186,6 +187,8 @@ int ZEXPORT inflateInit2_(z_stream *strm, int windowBits, const char *version, i int ret; struct inflate_state *state; + functableInit(); + if (version == NULL || version[0] != ZLIB_VERSION[0] || stream_size != (int)(sizeof(z_stream))) return Z_VERSION_ERROR; if (strm == NULL) @@ -423,9 +426,9 @@ static int updatewindow(z_stream *strm, const unsigned char *end, uint32_t copy) /* check function to use adler32() for zlib or crc32() for gzip */ #ifdef GUNZIP # define UPDATE(check, buf, len) \ - (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) + (state->flags ? crc32(check, buf, len) : functable.adler32(check, buf, len)) #else -# define UPDATE(check, buf, len) adler32(check, buf, len) +# define UPDATE(check, buf, len) functable.adler32(check, buf, len) #endif /* check macros for header crc */ @@ -671,7 +674,7 @@ int ZEXPORT inflate(z_stream *strm, int flush) { } state->dmax = 1U << len; Tracev((stderr, "inflate: zlib header ok\n")); - strm->adler = state->check = adler32(0L, NULL, 0); + strm->adler = state->check = functable.adler32(0L, NULL, 0); state->mode = hold & 0x200 ? DICTID : TYPE; INITBITS(); break; @@ -818,7 +821,7 @@ int ZEXPORT inflate(z_stream *strm, int flush) { RESTORE(); return Z_NEED_DICT; } - strm->adler = state->check = adler32(0L, NULL, 0); + strm->adler = state->check = functable.adler32(0L, NULL, 0); state->mode = TYPE; case TYPE: if (flush == Z_BLOCK || flush == Z_TREES) @@ -1303,8 +1306,8 @@ int ZEXPORT inflateSetDictionary(z_stream *strm, const unsigned char *dictionary /* check for correct dictionary identifier */ if (state->mode == DICT) { - dictid = adler32(0L, NULL, 0); - dictid = adler32(dictid, dictionary, dictLength); + dictid = functable.adler32(0L, NULL, 0); + dictid = functable.adler32(dictid, dictionary, dictLength); if (dictid != state->check) return Z_DATA_ERROR; }