/* Codeword lengths (in bits) for the LZX Huffman codes.
* A zero length means the corresponding codeword has zero frequency. */
struct lzx_lens {
- u8 main[LZX_MAINCODE_MAX_NUM_SYMBOLS];
- u8 len[LZX_LENCODE_NUM_SYMBOLS];
+ u8 main[LZX_MAINCODE_MAX_NUM_SYMBOLS + 1];
+ u8 len[LZX_LENCODE_NUM_SYMBOLS + 1];
u8 aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS];
};
static unsigned
lzx_compute_precode_items(const u8 lens[restrict],
const u8 prev_lens[restrict],
- const unsigned num_lens,
u32 precode_freqs[restrict],
unsigned precode_items[restrict])
{
itemptr = precode_items;
run_start = 0;
- do {
- /* Find the next run of codeword lengths. */
+
+ while (!((len = lens[run_start]) & 0x80)) {
/* len = the length being repeated */
- len = lens[run_start];
+
+ /* Find the next run of codeword lengths. */
run_end = run_start + 1;
/* Fast case for a single length. */
- if (likely(run_end == num_lens || len != lens[run_end])) {
+ if (likely(len != lens[run_end])) {
delta = prev_lens[run_start] - len;
if (delta < 0)
delta += 17;
/* Extend the run. */
do {
run_end++;
- } while (run_end != num_lens && len == lens[run_end]);
+ } while (len == lens[run_end]);
if (len == 0) {
/* Run of zeroes. */
*itemptr++ = delta;
run_start++;
}
- } while (run_start != num_lens);
+ }
return itemptr - precode_items;
}
unsigned precode_item;
unsigned precode_sym;
unsigned i;
+ u8 saved = lens[num_lens];
+ *(u8 *)(lens + num_lens) = 0x80;
for (i = 0; i < LZX_PRECODE_NUM_SYMBOLS; i++)
precode_freqs[i] = 0;
* the codeword lengths in the larger code will be output. */
num_precode_items = lzx_compute_precode_items(lens,
prev_lens,
- num_lens,
precode_freqs,
precode_items);
}
}
}
+
+ *(u8 *)(lens + num_lens) = saved;
}
/* Output a match or literal. */