diff options
author | Denys Vlasenko | 2018-01-31 00:01:06 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-01-31 00:01:06 +0100 |
commit | b7dfbbcdaaae5267259e2272b1cdfde6daad44a0 (patch) | |
tree | b5b5eb2808e08e4730c944e3407fb3100cae4f82 /archival/gzip.c | |
parent | d7500f856d856716fd228935bb5e84c897c9daa8 (diff) | |
download | busybox-b7dfbbcdaaae5267259e2272b1cdfde6daad44a0.zip busybox-b7dfbbcdaaae5267259e2272b1cdfde6daad44a0.tar.gz |
gzip: speed up send_bits()
Replace one RMW op with store. This speeds up gzip of a png file by ~2%.
function old new delta
send_bits 62 66 +4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/gzip.c')
-rw-r--r-- | archival/gzip.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index f253a21..08633d6 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -523,7 +523,6 @@ static unsigned file_read(void *buf, unsigned size) static void send_bits(unsigned value, unsigned length) { unsigned new_buf; - unsigned remain; #ifdef DEBUG Tracev((stderr, " l %2d v %4x ", length, value)); @@ -534,25 +533,26 @@ static void send_bits(unsigned value, unsigned length) new_buf = G1.bi_buf | (value << G1.bi_valid); /* NB: the above may sometimes do "<< 32" shift (undefined) - * if check below is changed to "length > remain" instead of >= */ - remain = BUF_SIZE - G1.bi_valid; + * if check below is changed to "length > BUF_SIZE" instead of >= */ + length += G1.bi_valid; /* If bi_buf is full */ - if (length >= remain) { + if (length >= BUF_SIZE) { /* ...use (valid) bits from bi_buf and * (BUF_SIZE - bi_valid) bits from value, * leaving (width - (BUF_SIZE-bi_valid)) unused bits in value. */ + value >>= (BUF_SIZE - G1.bi_valid); if (BUF_SIZE == 32) { put_32bit(new_buf); /* maybe unroll to 2*put_16bit()? */ } else { /* 16 */ put_16bit(new_buf); } - new_buf = value >> remain; + new_buf = value; length -= BUF_SIZE; } G1.bi_buf = new_buf; - G1.bi_valid += length; + G1.bi_valid = length; } |