-/* LZX uses what it calls 'position slots' to represent match offsets.
- * What this means is that a small 'position slot' number and a small
- * offset from that slot are encoded instead of one large offset for
- * every match.
- * - lzx_position_base is an index to the position slot bases
- * - lzx_extra_bits states how many bits of offset-from-base data is needed.
+/* Mapping: position slot => first match offset that uses that position slot.
const u32 lzx_position_base[LZX_MAX_POSITION_SLOTS] = {
0 , 1 , 2 , 3 , 4 , /* 0 --- 4 */
6 , 8 , 12 , 16 , 24 , /* 5 --- 9 */
const u32 lzx_position_base[LZX_MAX_POSITION_SLOTS] = {
0 , 1 , 2 , 3 , 4 , /* 0 --- 4 */
6 , 8 , 12 , 16 , 24 , /* 5 --- 9 */
-/* LZX window size must be a power of 2 between 2^15 and 2^21, inclusively. */
-bool
-lzx_window_size_valid(size_t window_size)
+/* Round the specified compression block size (not LZX block size) up to the
+ * next valid LZX window size, and return its order (log2). Or, if the block
+ * size is 0 or greater than the largest valid LZX window size, return 0. */
+unsigned
+lzx_get_window_order(size_t max_block_size)
- if (window_size == 0 || (u32)window_size != window_size)
- return false;
- u32 order = bsr32(window_size);
- if (window_size != 1U << order)
- return false;
- return (order >= LZX_MIN_WINDOW_ORDER && order <= LZX_MAX_WINDOW_ORDER);
+ unsigned order;
+
+ if (max_block_size == 0 || max_block_size > (1 << LZX_MAX_WINDOW_ORDER))
+ return 0;
+
+ order = bsr32(max_block_size);
+
+ if ((1 << order) != max_block_size)
+ order++;
+
+ return max(order, LZX_MIN_WINDOW_ORDER);
-lzx_e8_filter(u8 *data, s32 size, void (*process_target)(s32 *, s32))
+lzx_e8_filter(u8 *data, u32 size, void (*process_target)(sle32 *, s32))