From bc2c937b20d2eb3bff2ee3f8c8269a2ea37bdca4 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 19 Sep 2015 14:53:43 -0500 Subject: [PATCH] lzx_common: get rid of unnecessary functions --- include/wimlib/lzx_common.h | 40 ------------------------------------- src/lzx_common.c | 20 +++++++++---------- src/lzx_compress.c | 7 +++---- 3 files changed, 12 insertions(+), 55 deletions(-) diff --git a/include/wimlib/lzx_common.h b/include/wimlib/lzx_common.h index 4d758758..92e0b75b 100644 --- a/include/wimlib/lzx_common.h +++ b/include/wimlib/lzx_common.h @@ -7,7 +7,6 @@ #ifndef _LZX_COMMON_H #define _LZX_COMMON_H -#include "wimlib/bitops.h" #include "wimlib/lzx_constants.h" #include "wimlib/types.h" @@ -15,48 +14,9 @@ extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS + 1]; extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS]; -/* - * Return the offset slot for the specified match offset. - * - * This returns the smallest i such that: - * - * offset + LZX_OFFSET_ADJUSTMENT >= lzx_offset_slot_base[i] - * - * However, the actual implementation below takes advantage of the regularity of - * the offset slot bases to calculate the slot directly from the adjusted offset - * without actually looking at the array. - */ -static inline unsigned -lzx_get_offset_slot(u32 offset) -{ - u32 adjusted_offset = offset + LZX_OFFSET_ADJUSTMENT; - if (adjusted_offset >= 196608) { - return (adjusted_offset >> 17) + 34; - } else { - unsigned mssb_idx = fls32(adjusted_offset); - return (mssb_idx << 1) | - ((adjusted_offset >> (mssb_idx - 1)) & 1); - } -} - -static inline unsigned -lzx_main_symbol_for_literal(unsigned literal) -{ - return literal; -} - -static inline unsigned -lzx_main_symbol_for_match(unsigned offset_slot, unsigned len_header) -{ - return LZX_NUM_CHARS + (offset_slot * LZX_NUM_LEN_HEADERS) + len_header; -} - extern unsigned lzx_get_window_order(size_t max_bufsize); -extern unsigned -lzx_get_num_offset_slots(unsigned window_order); - extern unsigned lzx_get_num_main_syms(unsigned window_order); diff --git a/src/lzx_common.c b/src/lzx_common.c index 1baeebe7..6eab2031 100644 --- a/src/lzx_common.c +++ b/src/lzx_common.c @@ -89,8 +89,10 @@ lzx_get_window_order(size_t max_bufsize) return max(order, LZX_MIN_WINDOW_ORDER); } +/* Given a valid LZX window order, return the number of symbols that will exist + * in the main Huffman code. */ unsigned -lzx_get_num_offset_slots(unsigned window_order) +lzx_get_num_main_syms(unsigned window_order) { /* Note: one would expect that the maximum match offset would be * 'window_size - LZX_MIN_MATCH_LEN', which would occur if the first two @@ -98,17 +100,13 @@ lzx_get_num_offset_slots(unsigned window_order) * disallows this case. This reduces the number of needed offset slots * by 1. */ u32 window_size = (u32)1 << window_order; - u32 max_offset = window_size - LZX_MIN_MATCH_LEN - 1; - return 1 + lzx_get_offset_slot(max_offset); -} + u32 max_adjusted_offset = (window_size - LZX_MIN_MATCH_LEN - 1) + + LZX_OFFSET_ADJUSTMENT; + unsigned num_offset_slots = 30; + while (max_adjusted_offset >= lzx_offset_slot_base[num_offset_slots]) + num_offset_slots++; -/* Given a valid LZX window order, return the number of symbols that will exist - * in the main Huffman code. */ -unsigned -lzx_get_num_main_syms(unsigned window_order) -{ - return LZX_NUM_CHARS + (lzx_get_num_offset_slots(window_order) * - LZX_NUM_LEN_HEADERS); + return LZX_NUM_CHARS + (num_offset_slots * LZX_NUM_LEN_HEADERS); } static void diff --git a/src/lzx_compress.c b/src/lzx_compress.c index 36e27dbe..de89f596 100644 --- a/src/lzx_compress.c +++ b/src/lzx_compress.c @@ -1585,8 +1585,7 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c, * of coding the literal is integrated into the queue update * code below. */ literal = *in_next++; - cost = cur_node->cost + - c->costs.main[lzx_main_symbol_for_literal(literal)]; + cost = cur_node->cost + c->costs.main[literal]; /* Advance to the next position. */ cur_node++; @@ -1626,13 +1625,13 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c, static void lzx_compute_match_costs(struct lzx_compressor *c) { - unsigned num_offset_slots = lzx_get_num_offset_slots(c->window_order); + unsigned num_offset_slots = (c->num_main_syms - LZX_NUM_CHARS) / LZX_NUM_LEN_HEADERS; struct lzx_costs *costs = &c->costs; for (unsigned offset_slot = 0; offset_slot < num_offset_slots; offset_slot++) { u32 extra_cost = (u32)lzx_extra_offset_bits[offset_slot] * LZX_BIT_COST; - unsigned main_symbol = lzx_main_symbol_for_match(offset_slot, 0); + unsigned main_symbol = LZX_NUM_CHARS + (offset_slot * LZX_NUM_LEN_HEADERS); unsigned i; #if LZX_CONSIDER_ALIGNED_COSTS -- 2.43.0