#ifndef _WIMLIB_DECOMPRESS_COMMON_H
#define _WIMLIB_DECOMPRESS_COMMON_H
-#include "wimlib/assert.h"
#include "wimlib/compiler.h"
-#include "wimlib/endianness.h"
#include "wimlib/types.h"
#include "wimlib/unaligned.h"
bitstream_ensure_bits(struct input_bitstream *is, const unsigned num_bits)
{
/* This currently works for at most 17 bits. */
- wimlib_assert2(num_bits <= 17);
if (is->bitsleft >= num_bits)
return;
* input data is exhausted, the Huffman symbol is decoded as if the missing bits
* are all zeroes.
*
- * XXX: This is mostly duplicated in lzms_huffman_decode_symbol() in
- * lzms-decompress.c. */
+ * XXX: This is mostly duplicated in lzms_decode_huffman_symbol() in
+ * lzms_decompress.c. */
static inline u16
read_huffsym(struct input_bitstream *istream, const u16 decode_table[],
unsigned table_bits, unsigned max_codeword_len)
unsigned num_bits, const u8 lens[],
unsigned max_codeword_len);
+static inline void
+copy_word_unaligned(const void *src, void *dst)
+{
+ store_word_unaligned(load_word_unaligned(src), dst);
+}
+
+static inline machine_word_t
+repeat_byte(u8 b)
+{
+ machine_word_t v;
+
+ BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+
+ v = b;
+ v |= v << 8;
+ v |= v << 16;
+ v |= v << ((WORDSIZE == 8) ? 32 : 0);
+ return v;
+}
/*
* Copy an LZ77 match at (dst - offset) to dst.