X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=include%2Fwimlib%2Flzx_common.h;fp=include%2Fwimlib%2Flzx_common.h;h=78c92ec18bf58c91cda6d21770d6b7dc2100e819;hb=3e8aa757aaa63297f0d54007adf46411778fb6a8;hp=b3ae85a72b88971889d4501553ef7afd5c141425;hpb=94f8de6d411d58a0eb2e472cc1b984f195eb2447;p=wimlib diff --git a/include/wimlib/lzx_common.h b/include/wimlib/lzx_common.h index b3ae85a7..78c92ec1 100644 --- a/include/wimlib/lzx_common.h +++ b/include/wimlib/lzx_common.h @@ -7,64 +7,67 @@ #ifndef _LZX_COMMON_H #define _LZX_COMMON_H -#include "wimlib/assert.h" #include "wimlib/bitops.h" -#include "wimlib/compiler.h" #include "wimlib/lzx_constants.h" -#include "wimlib/util.h" #include "wimlib/types.h" //#define ENABLE_LZX_DEBUG #ifdef ENABLE_LZX_DEBUG -# define LZX_ASSERT wimlib_assert +# include "wimlib/assert.h" +# define LZX_ASSERT wimlib_assert #else -# define LZX_ASSERT(...) +# define LZX_ASSERT(...) #endif -extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS]; +extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS + 1]; -extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS]; +extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS + 1]; -/* Returns the LZX offset slot that corresponds to a given adjusted offset. +/* + * Return the offset slot for the specified match offset. + * + * This returns the smallest i such that: * - * Logically, this returns the smallest i such that - * adjusted_offset >= lzx_offset_slot_base[i]. + * offset + LZX_OFFSET_ADJUSTMENT >= lzx_offset_slot_base[i] * - * The actual implementation below takes advantage of the regularity of the - * numbers in the lzx_offset_slot_base array to calculate the slot directly from - * the adjusted offset without actually looking at the array. + * 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_raw(u32 adjusted_offset) +lzx_get_offset_slot(u32 offset) { + u32 adjusted_offset = offset + LZX_OFFSET_ADJUSTMENT; if (adjusted_offset >= 196608) { return (adjusted_offset >> 17) + 34; } else { - LZX_ASSERT(2 <= adjusted_offset && adjusted_offset < 655360); unsigned mssb_idx = fls32(adjusted_offset); return (mssb_idx << 1) | ((adjusted_offset >> (mssb_idx - 1)) & 1); } } -extern unsigned lzx_get_window_order(size_t max_block_size); - -extern unsigned lzx_get_num_main_syms(unsigned window_order); - -/* Least-recently used queue for match offsets. */ -struct lzx_lru_queue { - u32 R[LZX_NUM_RECENT_OFFSETS]; -} _aligned_attribute(sizeof(unsigned long)); +static inline unsigned +lzx_main_symbol_for_literal(unsigned literal) +{ + return literal; +} -/* Initialize the LZX least-recently-used match offset queue at the beginning of - * a new window for either decompression or compression. */ -static inline void -lzx_lru_queue_init(struct lzx_lru_queue *queue) +static inline unsigned +lzx_main_symbol_for_match(unsigned offset_slot, unsigned len_header) { - for (unsigned i = 0; i < LZX_NUM_RECENT_OFFSETS; i++) - queue->R[i] = 1; + 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); + extern void lzx_do_e8_preprocessing(u8 *data, u32 size);