]> wimlib.net Git - wimlib/commitdiff
lzx_decompress: redeclare input_bitstream above main loop
authorEric Biggers <ebiggers3@gmail.com>
Sun, 16 Jul 2017 06:26:33 +0000 (23:26 -0700)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 16 Jul 2017 07:09:12 +0000 (00:09 -0700)
src/lzx_decompress.c

index 299b5409c1a92385fb7352452d8b29f4fe0ebfa0..5747d327270717ae6892c257374088e4dfec789d 100644 (file)
@@ -332,10 +332,19 @@ lzx_read_block_header(struct lzx_decompressor *d, struct input_bitstream *is,
 
 /* Decompress a block of LZX-compressed data. */
 static int
-lzx_decompress_block(struct lzx_decompressor *d, struct input_bitstream *is,
+lzx_decompress_block(struct lzx_decompressor *d, struct input_bitstream *_is,
                     int block_type, u32 block_size,
                     u8 * const out_begin, u8 *out_next, u32 recent_offsets[])
 {
+       /*
+        * Redeclare the input bitstream on the stack.  This shouldn't be
+        * needed, but it can improve the main loop's performance significantly
+        * with both gcc and clang, apparently because the compiler otherwise
+        * gets confused and doesn't properly allocate registers for
+        * 'is->bitbuf' et al. and/or thinks 'is->next' may point into 'is'.
+        */
+       struct input_bitstream is_onstack = *_is;
+       struct input_bitstream *is = &is_onstack;
        u8 * const block_end = out_next + block_size;
        unsigned min_aligned_offset_slot;
 
@@ -435,6 +444,7 @@ lzx_decompress_block(struct lzx_decompressor *d, struct input_bitstream *is,
                out_next += length;
        } while (out_next != block_end);
 
+       *_is = is_onstack;
        return 0;
 }