>From 4939c190a79ea001c87aac736934268c077997ce Mon Sep 17 00:00:00 2001 From: John Reiser Date: Mon, 23 Jul 2012 10:25:52 -0700 Subject: [PATCH 2/2] slide_Pos(): identify for future optimization --- deflate.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/deflate.c b/deflate.c index 5405f10..d553f83 100644 --- a/deflate.c +++ b/deflate.c @@ -519,6 +519,22 @@ local void check_match(start, match, length) # define check_match(start, match, length) #endif +/* 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, and sets eofile if end of input file. @@ -553,17 +569,11 @@ local void fill_window() block_start -= (long) WSIZE; - for (n = 0; n < HASH_SIZE; n++) { - m = head[n]; - head[n] = (Pos)(m >= WSIZE ? m-WSIZE : NIL); - } - for (n = 0; n < WSIZE; n++) { - m = prev[n]; - prev[n] = (Pos)(m >= WSIZE ? m-WSIZE : NIL); + slide_Pos(head, HASH_SIZE, WSIZE); + slide_Pos(prev, WSIZE, WSIZE); /* If n is not on any hash chain, prev[n] is garbage but * its value will never be used. */ - } more += WSIZE; } /* At this point, more >= 2 */ -- 1.7.10.4