4 * Declarations shared between LZX compression and decompression.
10 #include "wimlib/assert.h"
11 #include "wimlib/compiler.h"
12 #include "wimlib/lzx_constants.h"
13 #include "wimlib/util.h"
14 #include "wimlib/types.h"
16 //#define ENABLE_LZX_DEBUG
17 #ifdef ENABLE_LZX_DEBUG
18 # define LZX_ASSERT wimlib_assert
20 # define LZX_ASSERT(...)
23 extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS];
25 extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS];
27 /* Returns the LZX offset slot that corresponds to a given adjusted offset.
29 * Logically, this returns the smallest i such that
30 * adjusted_offset >= lzx_offset_slot_base[i].
32 * The actual implementation below takes advantage of the regularity of the
33 * numbers in the lzx_offset_slot_base array to calculate the slot directly from
34 * the adjusted offset without actually looking at the array.
36 static inline unsigned
37 lzx_get_offset_slot_raw(u32 adjusted_offset)
39 if (adjusted_offset >= 196608) {
40 return (adjusted_offset >> 17) + 34;
42 LZX_ASSERT(2 <= adjusted_offset && adjusted_offset < 655360);
43 unsigned mssb_idx = bsr32(adjusted_offset);
44 return (mssb_idx << 1) |
45 ((adjusted_offset >> (mssb_idx - 1)) & 1);
49 extern unsigned lzx_get_window_order(size_t max_block_size);
51 extern unsigned lzx_get_num_main_syms(unsigned window_order);
53 /* Least-recently used queue for match offsets. */
54 struct lzx_lru_queue {
55 u32 R[LZX_NUM_RECENT_OFFSETS];
56 } _aligned_attribute(sizeof(unsigned long));
58 /* Initialize the LZX least-recently-used match offset queue at the beginning of
59 * a new window for either decompression or compression. */
61 lzx_lru_queue_init(struct lzx_lru_queue *queue)
63 for (unsigned i = 0; i < LZX_NUM_RECENT_OFFSETS; i++)
68 lzx_do_e8_preprocessing(u8 *data, u32 size);
71 lzx_undo_e8_preprocessing(u8 *data, u32 size);
73 #endif /* _WIMLIB_LZX_H */