aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-31 00:01:06 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-31 00:01:06 +0100
commitb7dfbbcdaaae5267259e2272b1cdfde6daad44a0 (patch)
treeb5b5eb2808e08e4730c944e3407fb3100cae4f82
parentd7500f856d856716fd228935bb5e84c897c9daa8 (diff)
downloadbusybox-w32-b7dfbbcdaaae5267259e2272b1cdfde6daad44a0.tar.gz
busybox-w32-b7dfbbcdaaae5267259e2272b1cdfde6daad44a0.tar.bz2
busybox-w32-b7dfbbcdaaae5267259e2272b1cdfde6daad44a0.zip
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>
-rw-r--r--archival/gzip.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index f253a217a..08633d667 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -523,7 +523,6 @@ static unsigned file_read(void *buf, unsigned size)
523static void send_bits(unsigned value, unsigned length) 523static void send_bits(unsigned value, unsigned length)
524{ 524{
525 unsigned new_buf; 525 unsigned new_buf;
526 unsigned remain;
527 526
528#ifdef DEBUG 527#ifdef DEBUG
529 Tracev((stderr, " l %2d v %4x ", length, value)); 528 Tracev((stderr, " l %2d v %4x ", length, value));
@@ -534,25 +533,26 @@ static void send_bits(unsigned value, unsigned length)
534 533
535 new_buf = G1.bi_buf | (value << G1.bi_valid); 534 new_buf = G1.bi_buf | (value << G1.bi_valid);
536 /* NB: the above may sometimes do "<< 32" shift (undefined) 535 /* NB: the above may sometimes do "<< 32" shift (undefined)
537 * if check below is changed to "length > remain" instead of >= */ 536 * if check below is changed to "length > BUF_SIZE" instead of >= */
538 remain = BUF_SIZE - G1.bi_valid; 537 length += G1.bi_valid;
539 538
540 /* If bi_buf is full */ 539 /* If bi_buf is full */
541 if (length >= remain) { 540 if (length >= BUF_SIZE) {
542 /* ...use (valid) bits from bi_buf and 541 /* ...use (valid) bits from bi_buf and
543 * (BUF_SIZE - bi_valid) bits from value, 542 * (BUF_SIZE - bi_valid) bits from value,
544 * leaving (width - (BUF_SIZE-bi_valid)) unused bits in value. 543 * leaving (width - (BUF_SIZE-bi_valid)) unused bits in value.
545 */ 544 */
545 value >>= (BUF_SIZE - G1.bi_valid);
546 if (BUF_SIZE == 32) { 546 if (BUF_SIZE == 32) {
547 put_32bit(new_buf); /* maybe unroll to 2*put_16bit()? */ 547 put_32bit(new_buf); /* maybe unroll to 2*put_16bit()? */
548 } else { /* 16 */ 548 } else { /* 16 */
549 put_16bit(new_buf); 549 put_16bit(new_buf);
550 } 550 }
551 new_buf = value >> remain; 551 new_buf = value;
552 length -= BUF_SIZE; 552 length -= BUF_SIZE;
553 } 553 }
554 G1.bi_buf = new_buf; 554 G1.bi_buf = new_buf;
555 G1.bi_valid += length; 555 G1.bi_valid = length;
556} 556}
557 557
558 558