[Zlib-devel] [PING] Improve longest_match performance
Andreas Krebbel
krebbel at linux.vnet.ibm.com
Tue Aug 28 06:53:57 EDT 2012
On 24/07/12 16:56, John Reiser wrote:
> On 07/24/2012, Andreas Krebbel wrote:
>
>> any comments regarding this one?
>>
>> http://mail.madler.net/pipermail/zlib-devel_madler.net/2012-June/002907.html
>
> These changes in the width of variables which contribute to indexing
> of arrays:
> -----
> + uLong cur_match = pcur_match; /* extend to pointer width */
>
> + uLong wmask = s->w_mask;
> -----
> should use 'ptrdiff_t' instead.
Right. I've verified that the same code is generated as before. Also it does not seem to
be necessary to promote wmask. So here is an updated version:
What do you think?
Bye,
-Andreas-
---
deflate.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
Index: zlib/deflate.c
===================================================================
--- zlib.orig/deflate.c
+++ zlib/deflate.c
@@ -1143,15 +1143,16 @@ local void lm_init (s)
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
* match.S. The code will be functionally equivalent.
*/
-local uInt longest_match(s, cur_match)
+local uInt longest_match(s, pcur_match)
deflate_state *s;
- IPos cur_match; /* current match */
+ IPos pcur_match; /* current match */
{
+ ptrdiff_t cur_match = pcur_match; /* extend to pointer width */
unsigned chain_length = s->max_chain_length;/* max hash chain length */
register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */
register int len; /* length of current match */
- int best_len = s->prev_length; /* best match length so far */
+ ptrdiff_t best_len = s->prev_length; /* best match length so far */
int nice_match = s->nice_match; /* stop if match long enough */
IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
s->strstart - (IPos)MAX_DIST(s) : NIL;
@@ -1166,12 +1167,12 @@ local uInt longest_match(s, cur_match)
* Try with and without -DUNALIGNED_OK to check.
*/
register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
- register ush scan_start = *(ushf*)scan;
- register ush scan_end = *(ushf*)(scan+best_len-1);
+ register uInt scan_start = *(ushf*)scan;
+ register uInt scan_end = *(ushf*)(scan+best_len-1);
#else
register Bytef *strend = s->window + s->strstart + MAX_MATCH;
- register Byte scan_end1 = scan[best_len-1];
- register Byte scan_end = scan[best_len];
+ register uInt scan_end1 = scan[best_len-1];
+ register uInt scan_end = scan[best_len];
#endif
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
More information about the Zlib-devel
mailing list