summaryrefslogtreecommitdiff
path: root/inffast.c
diff options
context:
space:
mode:
authorSebastian Pop <s.pop@samsung.com>2017-02-27 11:21:59 -0600
committerHans Kristian Rosbach <hk-git@circlestorm.org>2017-03-24 21:55:17 +0100
commitfe8b3cf0a69f2eb4d6933fec9741457bd3394bf8 (patch)
treed39f43aec71285b5cf3787b84dab14935803bcb7 /inffast.c
parent4b5ba1abdafc4b614542b1318672cc0f7996f318 (diff)
call memset for read after write dependences at distance 1
On a benchmark using zlib to decompress a PNG image this change shows a 20% speedup. It makes sense to special case distance = 1 of read after write dependences because it is possible to replace the loop kernel with a memset which is usually implemented in assembly in the libc, and because of the frequency at which distance = 1 appears during the PNG decompression: Distance Frequency 1 1009001 6 64500 9 29000 3 25500 144 14500 12 10000 15 3500 7 2000 24 1000 21 1000 18 1000 87 500 22 500 192 500
Diffstat (limited to 'inffast.c')
-rw-r--r--inffast.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/inffast.c b/inffast.c
index 2e51080..1d4048d 100644
--- a/inffast.c
+++ b/inffast.c
@@ -244,16 +244,21 @@ void ZLIB_INTERNAL inflate_fast(z_stream *strm, unsigned long start) {
}
} else {
from = out - dist; /* copy direct from output */
- do { /* minimum length is three */
- *out++ = *from++;
- *out++ = *from++;
- *out++ = *from++;
- len -= 3;
- } while (len > 2);
- if (len) {
- *out++ = *from++;
- if (len > 1)
+ if (dist == 1) {
+ memset (out, *from, len);
+ out += len;
+ } else {
+ do { /* minimum length is three */
+ *out++ = *from++;
+ *out++ = *from++;
*out++ = *from++;
+ len -= 3;
+ } while (len > 2);
+ if (len) {
+ *out++ = *from++;
+ if (len > 1)
+ *out++ = *from++;
+ }
}
}
} else if ((op & 64) == 0) { /* 2nd level distance code */