]> wimlib.net Git - wimlib/commitdiff
lzx_common: add constants for minimum aligned offset slot
authorEric Biggers <ebiggers3@gmail.com>
Sat, 9 Jul 2016 15:01:19 +0000 (10:01 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 9 Jul 2016 15:01:19 +0000 (10:01 -0500)
include/wimlib/lzx_constants.h
src/lzx_compress.c
src/lzx_decompress.c

index beeff4362a456fb2a52042569bf679d5cd46ed96..788eded8cd03376a7cc2e239601f860362808c49 100644 (file)
 /* 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
index fdbce434cf794d7ccd3881b39c70bcb61c6d454b..8aff56f4ba3340eadbf32efdff5593dd49ceef0a 100644 (file)
@@ -889,7 +889,12 @@ lzx_write_sequences(struct lzx_output_bitstream *os, int block_type,
                    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.  */
@@ -1001,7 +1006,7 @@ lzx_write_sequences(struct lzx_output_bitstream *os, int block_type,
                 * 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);
@@ -1422,7 +1427,7 @@ lzx_walk_item_list(struct lzx_compressor *c, u32 block_size, bool is_16_bit,
                /* 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. */
@@ -1704,7 +1709,7 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c,
                                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
@@ -1845,7 +1850,7 @@ lzx_compute_match_costs(struct lzx_compressor *c)
                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
 
index e109d3adc9e263d66980fb04ec42a13ca406ca71..0907fd8718bf0696d8d4adb0ddfdda6517f38ce2 100644 (file)
@@ -355,7 +355,7 @@ lzx_decompress_block(struct lzx_decompressor *d, struct input_bitstream *is,
                                              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 {
@@ -522,8 +522,9 @@ lzx_create_decompressor(size_t max_block_size, void **d_ret)
                      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;
        }