From: Nathan Moinvaziri Date: Tue, 15 Jun 2021 02:55:09 +0000 (-0700) Subject: Separate slide_hash_c in the same way that insert_string_c is separated from deflate.c. X-Git-Tag: 2.1.0-beta1~531 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e52d08ea92ec33ca140cbdcd0c8e9cb639e80cfe;p=thirdparty%2Fzlib-ng.git Separate slide_hash_c in the same way that insert_string_c is separated from deflate.c. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 51b4555d0..4deef8235 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -855,6 +855,7 @@ set(ZLIB_SRCS inftrees.c insert_string.c insert_string_roll.c + slide_hash.c trees.c uncompr.c zutil.c diff --git a/Makefile.in b/Makefile.in index 379cab529..de37b1906 100644 --- a/Makefile.in +++ b/Makefile.in @@ -93,6 +93,7 @@ OBJZ = \ inftrees.o \ insert_string.o \ insert_string_roll.o \ + slide_hash.o \ trees.o \ uncompr.o \ zutil.o \ @@ -127,6 +128,7 @@ PIC_OBJZ = \ inftrees.lo \ insert_string.lo \ insert_string_roll.lo \ + slide_hash.lo \ trees.lo \ uncompr.lo \ zutil.lo \ diff --git a/deflate.c b/deflate.c index c66c1e17a..c1ee6d410 100644 --- a/deflate.c +++ b/deflate.c @@ -185,50 +185,6 @@ static const config configuration_table[10] = { memset((unsigned char *)s->head, 0, HASH_SIZE * sizeof(*s->head)); \ } while (0) -/* =========================================================================== - * Slide the hash table when sliding the window down (could be avoided with 32 - * bit values at the expense of memory usage). We slide even when level == 0 to - * keep the hash table consistent if we switch back to level > 0 later. - */ -static inline void slide_hash_c_chain(Pos *table, uint32_t entries, uint16_t wsize) { -#ifdef NOT_TWEAK_COMPILER - table += entries; - do { - unsigned m; - m = *--table; - *table = (Pos)(m >= wsize ? m-wsize : 0); - /* If entries is not on any hash chain, prev[entries] is garbage but - * its value will never be used. - */ - } while (--entries); -#else - { - /* As of I make this change, gcc (4.8.*) isn't able to vectorize - * this hot loop using saturated-subtraction on x86-64 architecture. - * To avoid this defect, we can change the loop such that - * o. the pointer advance forward, and - * o. demote the variable 'm' to be local to the loop, and - * choose type "Pos" (instead of 'unsigned int') for the - * variable to avoid unnecessary zero-extension. - */ - unsigned int i; - Pos *q = table; - for (i = 0; i < entries; i++) { - Pos m = *q; - Pos t = (Pos)wsize; - *q++ = (Pos)(m >= t ? m-t: 0); - } - } -#endif /* NOT_TWEAK_COMPILER */ -} - -Z_INTERNAL void slide_hash_c(deflate_state *s) { - unsigned int wsize = s->w_size; - - slide_hash_c_chain(s->head, HASH_SIZE, wsize); - slide_hash_c_chain(s->prev, wsize, wsize); - } - /* ========================================================================= */ int32_t Z_EXPORT PREFIX(deflateInit_)(PREFIX3(stream) *strm, int32_t level, const char *version, int32_t stream_size) { return PREFIX(deflateInit2_)(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, version, stream_size); diff --git a/slide_hash.c b/slide_hash.c new file mode 100644 index 000000000..d25e710a8 --- /dev/null +++ b/slide_hash.c @@ -0,0 +1,52 @@ +/* slide_hash.c -- slide hash table C implementation + * + * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zbuild.h" +#include "deflate.h" + +/* =========================================================================== + * Slide the hash table when sliding the window down (could be avoided with 32 + * bit values at the expense of memory usage). We slide even when level == 0 to + * keep the hash table consistent if we switch back to level > 0 later. + */ +static inline void slide_hash_c_chain(Pos *table, uint32_t entries, uint16_t wsize) { +#ifdef NOT_TWEAK_COMPILER + table += entries; + do { + unsigned m; + m = *--table; + *table = (Pos)(m >= wsize ? m-wsize : 0); + /* If entries is not on any hash chain, prev[entries] is garbage but + * its value will never be used. + */ + } while (--entries); +#else + { + /* As of I make this change, gcc (4.8.*) isn't able to vectorize + * this hot loop using saturated-subtraction on x86-64 architecture. + * To avoid this defect, we can change the loop such that + * o. the pointer advance forward, and + * o. demote the variable 'm' to be local to the loop, and + * choose type "Pos" (instead of 'unsigned int') for the + * variable to avoid unnecessary zero-extension. + */ + unsigned int i; + Pos *q = table; + for (i = 0; i < entries; i++) { + Pos m = *q; + Pos t = (Pos)wsize; + *q++ = (Pos)(m >= t ? m-t: 0); + } + } +#endif /* NOT_TWEAK_COMPILER */ +} + +Z_INTERNAL void slide_hash_c(deflate_state *s) { + unsigned int wsize = s->w_size; + + slide_hash_c_chain(s->head, HASH_SIZE, wsize); + slide_hash_c_chain(s->prev, wsize, wsize); +} diff --git a/win32/Makefile.a64 b/win32/Makefile.a64 index a272810a8..8a39249dd 100644 --- a/win32/Makefile.a64 +++ b/win32/Makefile.a64 @@ -64,6 +64,7 @@ OBJS = \ inffast.obj \ insert_string.obj \ insert_string_roll.obj \ + slide_hash.obj \ trees.obj \ uncompr.obj \ zutil.obj \ @@ -179,6 +180,7 @@ infback.obj: $(SRCDIR)/infback.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/ inffast.obj: $(SRCDIR)/inffast.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/functable.h inflate.obj: $(SRCDIR)/inflate.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/functable.h $(SRCDIR)/functable.h inftrees.obj: $(SRCDIR)/inftrees.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h +slide_hash.obj: $(SRCDIR)/slide_hash.c $(SRCDIR)/zbuild.h $(SRCDIR)/deflate.h trees.obj: $(SRCDIR)/zbuild.h $(SRCDIR)/deflate.h $(SRCDIR)/trees_tbl.h zutil.obj: $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/zutil_p.h diff --git a/win32/Makefile.arm b/win32/Makefile.arm index 23ed761a4..9897ad8e9 100644 --- a/win32/Makefile.arm +++ b/win32/Makefile.arm @@ -67,6 +67,7 @@ OBJS = \ inffast.obj \ insert_string.obj \ insert_string_roll.obj \ + slide_hash.obj \ trees.obj \ uncompr.obj \ zutil.obj \ @@ -191,6 +192,7 @@ infback.obj: $(SRCDIR)/infback.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/ inffast.obj: $(SRCDIR)/inffast.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/functable.h inflate.obj: $(SRCDIR)/inflate.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/functable.h $(SRCDIR)/functable.h inftrees.obj: $(SRCDIR)/inftrees.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h +slide_hash.obj: $(SRCDIR)/slide_hash.c $(SRCDIR)/zbuild.h $(SRCDIR)/deflate.h trees.obj: $(SRCDIR)/zbuild.h $(SRCDIR)/deflate.h $(SRCDIR)/trees_tbl.h zutil.obj: $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/zutil_p.h diff --git a/win32/Makefile.msc b/win32/Makefile.msc index 94462f596..0ff683e2f 100644 --- a/win32/Makefile.msc +++ b/win32/Makefile.msc @@ -75,6 +75,7 @@ OBJS = \ insert_string.obj \ insert_string_roll.obj \ insert_string_sse.obj \ + slide_hash.obj \ slide_avx.obj \ slide_sse.obj \ trees.obj \ @@ -185,6 +186,7 @@ infback.obj: $(SRCDIR)/infback.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/ inffast.obj: $(SRCDIR)/inffast.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/functable.h inflate.obj: $(SRCDIR)/inflate.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h $(SRCDIR)/inflate.h $(SRCDIR)/inffast.h $(SRCDIR)/functable.h $(SRCDIR)/functable.h inftrees.obj: $(SRCDIR)/inftrees.c $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/inftrees.h +slide_hash.obj: $(SRCDIR)/slide_hash.c $(SRCDIR)/zbuild.h $(SRCDIR)/deflate.h slide_sse.obj: $(SRCDIR)/arch/x86/slide_sse.c $(SRCDIR)/deflate.h trees.obj: $(SRCDIR)/zbuild.h $(SRCDIR)/deflate.h $(SRCDIR)/trees_tbl.h zutil.obj: $(SRCDIR)/zbuild.h $(SRCDIR)/zutil.h $(SRCDIR)/zutil_p.h