4 * Declarations shared between LZX compression and decompression.
10 #include "wimlib/bitops.h"
11 #include "wimlib/lzx_constants.h"
12 #include "wimlib/types.h"
14 //#define ENABLE_LZX_DEBUG
15 #ifdef ENABLE_LZX_DEBUG
16 # include "wimlib/assert.h"
17 # define LZX_ASSERT wimlib_assert
19 # define LZX_ASSERT(...)
22 extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS + 1];
24 extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS + 1];
27 * Return the offset slot for the specified match offset.
29 * This returns the smallest i such that:
31 * offset + LZX_OFFSET_ADJUSTMENT >= lzx_offset_slot_base[i]
33 * However, the actual implementation below takes advantage of the regularity of
34 * the offset slot bases to calculate the slot directly from the adjusted offset
35 * without actually looking at the array.
37 static inline unsigned
38 lzx_get_offset_slot(u32 offset)
40 u32 adjusted_offset = offset + LZX_OFFSET_ADJUSTMENT;
41 if (adjusted_offset >= 196608) {
42 return (adjusted_offset >> 17) + 34;
44 unsigned mssb_idx = fls32(adjusted_offset);
45 return (mssb_idx << 1) |
46 ((adjusted_offset >> (mssb_idx - 1)) & 1);
50 static inline unsigned
51 lzx_main_symbol_for_literal(unsigned literal)
56 static inline unsigned
57 lzx_main_symbol_for_match(unsigned offset_slot, unsigned len_header)
59 return LZX_NUM_CHARS + (offset_slot * LZX_NUM_LEN_HEADERS) + len_header;
63 lzx_get_window_order(size_t max_bufsize);
66 lzx_get_num_offset_slots(unsigned window_order);
69 lzx_get_num_main_syms(unsigned window_order);
72 lzx_do_e8_preprocessing(u8 *data, u32 size);
75 lzx_undo_e8_preprocessing(u8 *data, u32 size);
77 #endif /* _LZX_COMMON_H */