>From 04b2be78c8637c6b60417f7b6d58a348e4d29f7c Mon Sep 17 00:00:00 2001 From: John Reiser Date: Mon, 23 Jul 2012 16:58:46 -0700 Subject: [PATCH 1/1] slide_Pos(): identify for future optimization --- deflate.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/deflate.c b/deflate.c index 9e4c2cb..d1c2fb1 100644 --- a/deflate.c +++ b/deflate.c @@ -1375,6 +1375,22 @@ local void check_match(s, start, match, length) # define check_match(s, start, match, length) #endif /* DEBUG */ +/* Adjust an array of Pos when the window slides. + * The operation corresponds to saturating subtract (subtract, but + * do not allow the answer to go below zero.) This is supported + * by vectorized "multimedia" instructions of various machines + * such as x86 MMX and SSE2, PowerPC altivec, ARM neon. + */ +local void slide_Pos(ptr, n, slide) + Pos *const ptr; unsigned const n; Pos const slide; +{ + unsigned j; + for (j = 0; j < n; j++) { + Pos const m = ptr[j]; + ptr[j] = (Pos)(m >= slide ? m-slide : NIL); + } +} + /* =========================================================================== * Fill the window when the lookahead becomes insufficient. * Updates strstart and lookahead. @@ -1427,23 +1443,12 @@ 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; + slide_Pos(s->head, s->hash_size, 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); + slide_Pos(s->prev, wsize, wsize); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ #endif more += wsize; } -- 1.7.10.4