Skip to content

Commit

Permalink
Unroll PUT_BITS() loop and improve compile-time visibility.
Browse files Browse the repository at this point in the history
We *know* that we'll go round the loop at least once if (nr) >= 8, and
we *might* go round it one more time. There's no need for a loop.

This gives around 8% performance improvement.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 7, 2015
1 parent c7042d5 commit 69d5794
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lzs.c
Expand Up @@ -146,7 +146,13 @@ do { \
outbits <<= (nr); \
outbits |= (bits); \
nr_outbits += (nr); \
while (nr_outbits >= 8) { \
if ((nr) > 8) { \
nr_outbits -= 8; \
dst[outpos++] = outbits >> nr_outbits; \
if (outpos >= dstlen) \
return -EFBIG; \
} \
if (nr_outbits >= 8) { \
nr_outbits -= 8; \
dst[outpos++] = outbits >> nr_outbits; \
if (outpos >= dstlen) \
Expand Down

0 comments on commit 69d5794

Please sign in to comment.