]> wimlib.net Git - wimlib/commitdiff
Avoid branch in 'num_bits == 0' branch when peeking bits
authorEric Biggers <ebiggers3@gmail.com>
Mon, 20 Jul 2015 04:13:53 +0000 (23:13 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Mon, 20 Jul 2015 04:20:09 +0000 (23:20 -0500)
include/wimlib/decompress_common.h
src/lzms_decompress.c

index 420f7f41e3adf8a207248241a41aee0db3ee3879..ce731dca39ba40cc4c3c92c2f5a973a6fd59084a 100644 (file)
@@ -90,9 +90,7 @@ overflow:
 static inline u32
 bitstream_peek_bits(const struct input_bitstream *is, const unsigned num_bits)
 {
 static inline u32
 bitstream_peek_bits(const struct input_bitstream *is, const unsigned num_bits)
 {
-       if (unlikely(num_bits == 0))
-               return 0;
-       return is->bitbuf >> (32 - num_bits);
+       return (is->bitbuf >> 1) >> (sizeof(is->bitbuf) * 8 - num_bits - 1);
 }
 
 /* Remove @num_bits from the bitstream.  There must be at least @num_bits
 }
 
 /* Remove @num_bits from the bitstream.  There must be at least @num_bits
index 7f82803c9339b61d06da48756b45767ae12fa30d..bd7e76e12e809dcbd222baf08557ebce51990717 100644 (file)
@@ -430,9 +430,7 @@ lzms_ensure_bits(struct lzms_input_bitstream *is, unsigned num_bits)
 static inline bitbuf_t
 lzms_peek_bits(struct lzms_input_bitstream *is, unsigned num_bits)
 {
 static inline bitbuf_t
 lzms_peek_bits(struct lzms_input_bitstream *is, unsigned num_bits)
 {
-       if (unlikely(num_bits == 0))
-               return 0;
-       return is->bitbuf >> (sizeof(is->bitbuf) * 8 - num_bits);
+       return (is->bitbuf >> 1) >> (sizeof(is->bitbuf) * 8 - num_bits - 1);
 }
 
 /* Remove @num_bits bits from the bitbuffer variable.  */
 }
 
 /* Remove @num_bits bits from the bitbuffer variable.  */