Skip to content

Commit

Permalink
split the hash slide out of fill window
Browse files Browse the repository at this point in the history
as a preparation to optimize it.

"Sliding" happens when the compression window/2 gets moved.
In this case the hash values are adapted, which means
basically an unsigned subtration with saturation (no wrap
at zero).

Many processor have an instruction for this, but the
compiler, trapped in the C-type systems, is seldomly
capable to exploit this.
  • Loading branch information
kaffeemonster committed Sep 12, 2011
1 parent 906fb03 commit aa30d20
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions INDEX
Expand Up @@ -59,6 +59,7 @@ inflate.c
inflate.h
inftrees.c
inftrees.h
slhash.c
trees.c
trees.h
uncompr.c
Expand Down
6 changes: 4 additions & 2 deletions Makefile.in
Expand Up @@ -53,10 +53,10 @@ mandir = ${prefix}/share/man
man3dir = ${mandir}/man3
pkgconfigdir = ${libdir}/pkgconfig

OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
OBJC = adler32.o compress.o crc32.o deflate.o slhash.o gzclose.o gzlib.o gzread.o \
gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o

PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo \
PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo slhash.lo gzclose.lo gzlib.lo gzread.lo \
gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo

# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
Expand Down Expand Up @@ -244,6 +244,7 @@ gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h
compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h
crc32.o: zutil.h zlib.h zconf.h crc32.h
deflate.o: deflate.h zutil.h zlib.h zconf.h
slhash.o: deflate.h zutil.h zlib.h zconf.h
infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
Expand All @@ -255,6 +256,7 @@ gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h
compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h
crc32.lo: zutil.h zlib.h zconf.h crc32.h
deflate.lo: deflate.h zutil.h zlib.h zconf.h
slhash.lo: deflate.h zutil.h zlib.h zconf.h
infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inftrees.lo: zutil.h zlib.h zconf.h inftrees.h
Expand Down
22 changes: 2 additions & 20 deletions deflate.c
Expand Up @@ -1317,8 +1317,7 @@ local void check_match(s, start, match, length)
local void fill_window(s)
deflate_state *s;
{
register unsigned n, m;
register Posf *p;
register unsigned n;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;

Expand Down Expand Up @@ -1354,24 +1353,7 @@ local void fill_window(s)
later. (Using level 0 permanently is not an optimal usage of
zlib, so we don't care about this pathological case.)
*/
n = s->hash_size;
p = &s->head[n];
do {
m = *--p;
*p = (Pos)(m >= wsize ? m-wsize : NIL);
} while (--n);

n = wsize;
#ifndef FASTEST
p = &s->prev[n];
do {
m = *--p;
*p = (Pos)(m >= wsize ? m-wsize : NIL);
/* If n is not on any hash chain, prev[n] is garbage but
* its value will never be used.
*/
} while (--n);
#endif
_sh_slide(s->head, s->prev, wsize, s->hash_size);
more += wsize;
}
if (s->strm->avail_in == 0) return;
Expand Down
2 changes: 2 additions & 0 deletions deflate.h
Expand Up @@ -297,6 +297,8 @@ void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));
/* in slhash.c */
void ZLIB_INTERNAL _sh_slide OF((Posf *p, Posf *q, uInt wsize, unsigned n));

#define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
Expand Down
30 changes: 30 additions & 0 deletions slhash.c
@@ -0,0 +1,30 @@
/* slhash.c -- slide the hash table during fill_window()
* Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "deflate.h"
#define NIL 0

local void update_hoffset(Posf *p, uInt wsize, unsigned n)
{
register unsigned m;
do {
m = *p;
*p++ = (Pos)(m >= wsize ? m-wsize : NIL);
} while (--n);
}

void ZLIB_INTERNAL _sh_slide (p, q, wsize, n)
Posf *p;
Posf *q;
uInt wsize;
unsigned n;
{
update_hoffset(p, wsize, n);
#ifndef FASTEST
/* If n is not on any hash chain, prev[n] is garbage but
* its value will never be used.
*/
update_hoffset(q, wsize, wsize);
#endif
}

0 comments on commit aa30d20

Please sign in to comment.