]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
- Add adler32 to functable
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 24 Apr 2017 10:47:24 +0000 (12:47 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 24 Apr 2017 10:47:24 +0000 (12:47 +0200)
- Add missing call to functableinit from inflateinit
- Fix external direct calls to adler32 functions without calling functableinit

Makefile.in
adler32.c
deflate.c
functable.c
functable.h
inflate.c

index 8dd749ff19ed2229d73bf4f569676c6e643193f6..07dc4ac2f0876c59aa4431b54356e058211a8ac1 100644 (file)
@@ -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
index 7a022b9e15ebc94502b0658c2da6c630e253df7b..dcfeecdf29fbdaba6d4566165cf0ded641b45c40 100644 (file)
--- 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);
 }
 
 /* ========================================================================= */
index 6ec9f1eade0341abf31d7aec711bc254cd6069a9..7de68bbde0ede9b88037eb41f42f7ca0608fd5fe 100644 (file)
--- 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;
index 9887b99bc10873a27b65257433924d939a313834..7d34fad74fbf779e67441053896da0787526a9e9 100644 (file)
@@ -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
 }
index a867fa27edecbcd04ba07ddac5a0e2e7843749e2..b7d026e5671c0888f86cf99b5dbfedaa71fa477f 100644 (file)
@@ -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
index cf0942c6f7a53535a5ffc5fe153ccd456757282c..68a41acf460a1455e5fab92587a6d75252f4a274 100644 (file)
--- 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;
     }