unsigned char *sym_buf = s->sym_buf;
#endif
+ /* Keep bi_buf and bi_valid in registers across the entire loop */
+ uint64_t bi_buf = s->bi_buf;
+ uint32_t bi_valid = s->bi_valid;
+
if (sym_next != 0) {
do {
#ifdef LIT_MEM
sx += 3;
#endif
if (dist == 0) {
- zng_emit_lit(s, ltree, lc);
+ zng_emit_lit(s, ltree, lc, &bi_buf, &bi_valid);
} else {
- zng_emit_dist(s, ltree, dtree, lc, dist);
+ zng_emit_dist(s, ltree, dtree, lc, dist, &bi_buf, &bi_valid);
} /* literal or match pair ? */
/* Check for no overlay of pending_buf on needed symbols */
} while (sx < sym_next);
}
- zng_emit_end_block(s, ltree, 0);
+ zng_emit_end_block(s, ltree, 0, &bi_buf, &bi_valid);
+
+ /* Write back to state */
+ s->bi_buf = bi_buf;
+ s->bi_valid = bi_valid;
}
/* ===========================================================================
/* ===========================================================================
* Emit literal code
*/
-static inline uint32_t zng_emit_lit(deflate_state *s, const ct_data *ltree, unsigned c) {
- uint32_t bi_valid = s->bi_valid;
- uint64_t bi_buf = s->bi_buf;
-
- send_code(s, c, ltree, bi_buf, bi_valid);
-
- s->bi_valid = bi_valid;
- s->bi_buf = bi_buf;
-
+static inline void zng_emit_lit(deflate_state *s, const ct_data *ltree, unsigned c,
+ uint64_t *bi_buf, uint32_t *bi_valid) {
+ send_code(s, c, ltree, *bi_buf, *bi_valid);
Tracecv(isgraph(c & 0xff), (stderr, " '%c' ", c));
-
- return ltree[c].Len;
}
/* ===========================================================================
* Emit match distance/length code
*/
-static uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, const ct_data *dtree,
- uint32_t lc, uint32_t dist) {
+static inline uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, const ct_data *dtree,
+ uint32_t lc, uint32_t dist, uint64_t *bi_buf, uint32_t *bi_valid) {
uint32_t c, extra;
uint8_t code;
uint64_t match_bits;
uint32_t match_bits_len;
- uint32_t bi_valid = s->bi_valid;
- uint64_t bi_buf = s->bi_buf;
/* Send the length code, len is the match length - STD_MIN_MATCH */
code = zng_length_code[lc];
match_bits_len += extra;
}
- send_bits(s, match_bits, match_bits_len, bi_buf, bi_valid);
-
- s->bi_valid = bi_valid;
- s->bi_buf = bi_buf;
+ send_bits(s, match_bits, match_bits_len, *bi_buf, *bi_valid);
return match_bits_len;
}
/* ===========================================================================
* Emit end block
*/
-static inline void zng_emit_end_block(deflate_state *s, const ct_data *ltree, const int last) {
- uint32_t bi_valid = s->bi_valid;
- uint64_t bi_buf = s->bi_buf;
- send_code(s, END_BLOCK, ltree, bi_buf, bi_valid);
- s->bi_valid = bi_valid;
- s->bi_buf = bi_buf;
+static inline void zng_emit_end_block(deflate_state *s, const ct_data *ltree, const int last,
+ uint64_t *bi_buf, uint32_t *bi_valid) {
+ send_code(s, END_BLOCK, ltree, *bi_buf, *bi_valid);
Tracev((stderr, "\n+++ Emit End Block: Last: %u Pending: %u Total Out: %" PRIu64 "\n",
last, s->pending, (uint64_t)s->strm->total_out));
Z_UNUSED(last);
* Emit literal and count bits
*/
static inline void zng_tr_emit_lit(deflate_state *s, const ct_data *ltree, unsigned c) {
- cmpr_bits_add(s, zng_emit_lit(s, ltree, c));
+ uint64_t bi_buf = s->bi_buf;
+ uint32_t bi_valid = s->bi_valid;
+ zng_emit_lit(s, ltree, c, &bi_buf, &bi_valid);
+ s->bi_buf = bi_buf;
+ s->bi_valid = bi_valid;
+ cmpr_bits_add(s, ltree[c].Len);
}
/* ===========================================================================
*/
static inline void zng_tr_emit_dist(deflate_state *s, const ct_data *ltree, const ct_data *dtree,
uint32_t lc, uint32_t dist) {
- cmpr_bits_add(s, zng_emit_dist(s, ltree, dtree, lc, dist));
+ uint64_t bi_buf = s->bi_buf;
+ uint32_t bi_valid = s->bi_valid;
+ uint32_t bits = zng_emit_dist(s, ltree, dtree, lc, dist, &bi_buf, &bi_valid);
+ s->bi_buf = bi_buf;
+ s->bi_valid = bi_valid;
+ cmpr_bits_add(s, bits);
}
/* ===========================================================================
* Emit an end block and align bit buffer if last block
*/
static inline void zng_tr_emit_end_block(deflate_state *s, const ct_data *ltree, const int last) {
- zng_emit_end_block(s, ltree, last);
+ uint64_t bi_buf = s->bi_buf;
+ uint32_t bi_valid = s->bi_valid;
+ zng_emit_end_block(s, ltree, last, &bi_buf, &bi_valid);
+ s->bi_buf = bi_buf;
+ s->bi_valid = bi_valid;
cmpr_bits_add(s, 7);
if (last)
zng_tr_emit_align(s);