+ /* Was this the last literal run? */
+ if (seq->adjusted_offset_and_match_hdr & 0x80000000)
+ return;
+
+ /* Nope; output the match. */
+
+ match_hdr = seq->adjusted_offset_and_match_hdr & 0x1FF;
+ main_symbol = LZX_NUM_CHARS + match_hdr;
+ adjusted_length = seq->adjusted_length;
+
+ block_data += adjusted_length + LZX_MIN_MATCH_LEN;
+
+ offset_slot = match_hdr / LZX_NUM_LEN_HEADERS;
+ adjusted_offset = seq->adjusted_offset_and_match_hdr >> 9;
+
+ num_extra_bits = lzx_extra_offset_bits[offset_slot];
+ extra_bits = adjusted_offset - lzx_offset_slot_base[offset_slot];
+
+ #define MAX_MATCH_BITS (MAIN_CODEWORD_LIMIT + LENGTH_CODEWORD_LIMIT + \
+ 14 + ALIGNED_CODEWORD_LIMIT)
+
+ /* Verify optimization is enabled on 64-bit */
+ STATIC_ASSERT(sizeof(machine_word_t) < 8 || CAN_BUFFER(MAX_MATCH_BITS));
+
+ /* Output the main symbol for the match. */
+
+ lzx_add_bits(os, codes->codewords.main[main_symbol],
+ codes->lens.main[main_symbol]);
+ if (!CAN_BUFFER(MAX_MATCH_BITS))
+ lzx_flush_bits(os, MAIN_CODEWORD_LIMIT);
+
+ /* If needed, output the length symbol for the match. */
+
+ if (adjusted_length >= LZX_NUM_PRIMARY_LENS) {
+ lzx_add_bits(os, codes->codewords.len[adjusted_length -
+ LZX_NUM_PRIMARY_LENS],
+ codes->lens.len[adjusted_length -
+ LZX_NUM_PRIMARY_LENS]);
+ if (!CAN_BUFFER(MAX_MATCH_BITS))
+ lzx_flush_bits(os, LENGTH_CODEWORD_LIMIT);
+ }
+
+ /* Output the extra offset bits for the match. In aligned
+ * offset blocks, the lowest 3 bits of the adjusted offset are
+ * Huffman-encoded using the aligned offset code, provided that
+ * there are at least extra 3 offset bits required. All other
+ * extra offset bits are output verbatim. */
+
+ if ((adjusted_offset & ones_if_aligned) >= 16) {
+
+ lzx_add_bits(os, extra_bits >> LZX_NUM_ALIGNED_OFFSET_BITS,
+ num_extra_bits - LZX_NUM_ALIGNED_OFFSET_BITS);
+ if (!CAN_BUFFER(MAX_MATCH_BITS))
+ lzx_flush_bits(os, 14);
+
+ lzx_add_bits(os, codes->codewords.aligned[adjusted_offset &
+ LZX_ALIGNED_OFFSET_BITMASK],
+ codes->lens.aligned[adjusted_offset &
+ LZX_ALIGNED_OFFSET_BITMASK]);
+ if (!CAN_BUFFER(MAX_MATCH_BITS))
+ lzx_flush_bits(os, ALIGNED_CODEWORD_LIMIT);
+ } else {
+ STATIC_ASSERT(CAN_BUFFER(17));
+
+ lzx_add_bits(os, extra_bits, num_extra_bits);
+ if (!CAN_BUFFER(MAX_MATCH_BITS))
+ lzx_flush_bits(os, 17);
+ }
+
+ if (CAN_BUFFER(MAX_MATCH_BITS))
+ lzx_flush_bits(os, MAX_MATCH_BITS);
+
+ /* Advance to the next sequence. */
+ seq++;
+ }