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 extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS + 1];
16 extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS];
19 * Return the offset slot for the specified match offset.
21 * This returns the smallest i such that:
23 * offset + LZX_OFFSET_ADJUSTMENT >= lzx_offset_slot_base[i]
25 * However, the actual implementation below takes advantage of the regularity of
26 * the offset slot bases to calculate the slot directly from the adjusted offset
27 * without actually looking at the array.
29 static inline unsigned
30 lzx_get_offset_slot(u32 offset)
32 u32 adjusted_offset = offset + LZX_OFFSET_ADJUSTMENT;
33 if (adjusted_offset >= 196608) {
34 return (adjusted_offset >> 17) + 34;
36 unsigned mssb_idx = fls32(adjusted_offset);
37 return (mssb_idx << 1) |
38 ((adjusted_offset >> (mssb_idx - 1)) & 1);
42 static inline unsigned
43 lzx_main_symbol_for_literal(unsigned literal)
48 static inline unsigned
49 lzx_main_symbol_for_match(unsigned offset_slot, unsigned len_header)
51 return LZX_NUM_CHARS + (offset_slot * LZX_NUM_LEN_HEADERS) + len_header;
55 lzx_get_window_order(size_t max_bufsize);
58 lzx_get_num_offset_slots(unsigned window_order);
61 lzx_get_num_main_syms(unsigned window_order);
64 lzx_do_e8_preprocessing(u8 *data, u32 size);
67 lzx_undo_e8_preprocessing(u8 *data, u32 size);
69 #endif /* _LZX_COMMON_H */