Skip to content

Commit

Permalink
Optimise lzs_decompress() for literal bytes
Browse files Browse the repository at this point in the history
By adding the loop, we get about 7% performance improvement. For some
reason this *isn't* achieved by using __builtin_expect(). In fact, nowhere
that's seemed tempting to use __builtin_expect() so far has actually
turned out to give useful results.

This (and previous testing) is with
gcc version 4.9.2 20141101 (Red Hat 4.9.2-1) (GCC)

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 8, 2015
1 parent eb79b63 commit 513298f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lzs.c
Expand Up @@ -69,12 +69,13 @@ int lzs_decompress(unsigned char *dst, int dstlen, const unsigned char *src, int
/* Get 9 bits, which is the minimum and a common case */
GET_BITS(9);

/* 0bbbbbbbb is a literal byte */
if (data < 0x100) {
/* 0bbbbbbbb is a literal byte. The loop gives a hint to
* the compiler that we expect to see a few of these. */
while (data < 0x100) {
if (outlen == dstlen)
return -EFBIG;
dst[outlen++] = data;
continue;
GET_BITS(9);
}

/* 110000000 is the end marker */
Expand Down

0 comments on commit 513298f

Please sign in to comment.