/* Number of bits in which each aligned offset codeword length is represented. */
#define LZX_ALIGNEDCODE_ELEMENT_SIZE 3
+/* The first offset slot which requires an aligned offset symbol in aligned
+ * offset blocks. */
+#define LZX_MIN_ALIGNED_OFFSET_SLOT 8
+
+/* The offset slot base for LZX_MIN_ALIGNED_OFFSET_SLOT. */
+#define LZX_MIN_ALIGNED_OFFSET 14
+
/* Maximum lengths (in bits) for length-limited Huffman code construction. */
#define LZX_MAX_MAIN_CODEWORD_LEN 16
#define LZX_MAX_LEN_CODEWORD_LEN 16
const struct lzx_codes *codes)
{
const struct lzx_sequence *seq = sequences;
- u32 ones_if_aligned = 0 - (block_type == LZX_BLOCKTYPE_ALIGNED);
+ unsigned min_aligned_offset_slot;
+
+ if (block_type == LZX_BLOCKTYPE_ALIGNED)
+ min_aligned_offset_slot = LZX_MIN_ALIGNED_OFFSET_SLOT;
+ else
+ min_aligned_offset_slot = LZX_MAX_OFFSET_SLOTS;
for (;;) {
/* Output the next sequence. */
* there are at least extra 3 offset bits required. All other
* extra offset bits are output verbatim. */
- if ((adjusted_offset & ones_if_aligned) >= 16) {
+ if (offset_slot >= min_aligned_offset_slot) {
lzx_add_bits(os, extra_bits >> LZX_NUM_ALIGNED_OFFSET_BITS,
num_extra_bits - LZX_NUM_ALIGNED_OFFSET_BITS);
/* Record a match. */
/* Tally the aligned offset symbol if needed. */
- if (adjusted_offset >= 16)
+ if (adjusted_offset >= LZX_MIN_ALIGNED_OFFSET + LZX_OFFSET_ADJUSTMENT)
c->freqs.aligned[adjusted_offset & LZX_ALIGNED_OFFSET_BITMASK]++;
/* Record the adjusted length. */
u32 cost;
#if CONSIDER_ALIGNED_COSTS
- if (offset >= 16 - LZX_OFFSET_ADJUSTMENT)
+ if (offset >= LZX_MIN_ALIGNED_OFFSET)
base_cost += c->costs.aligned[adjusted_offset &
LZX_ALIGNED_OFFSET_BITMASK];
#endif
unsigned i;
#if CONSIDER_ALIGNED_COSTS
- if (offset_slot >= 8)
+ if (offset_slot >= LZX_MIN_ALIGNED_OFFSET_SLOT)
extra_cost -= LZX_NUM_ALIGNED_OFFSET_BITS * BIT_COST;
#endif
d->alignedcode_lens,
LZX_MAX_ALIGNED_CODEWORD_LEN))
return -1;
- min_aligned_offset_slot = 8;
+ min_aligned_offset_slot = LZX_MIN_ALIGNED_OFFSET_SLOT;
memcpy(d->extra_offset_bits, d->extra_offset_bits_minus_aligned,
sizeof(lzx_extra_offset_bits));
} else {
sizeof(lzx_extra_offset_bits));
memcpy(d->extra_offset_bits_minus_aligned, lzx_extra_offset_bits,
sizeof(lzx_extra_offset_bits));
- for (unsigned offset_slot = 8; offset_slot < LZX_MAX_OFFSET_SLOTS;
- offset_slot++) {
+ for (unsigned offset_slot = LZX_MIN_ALIGNED_OFFSET_SLOT;
+ offset_slot < LZX_MAX_OFFSET_SLOTS; offset_slot++)
+ {
d->extra_offset_bits_minus_aligned[offset_slot] -=
LZX_NUM_ALIGNED_OFFSET_BITS;
}