From 31786dbc470c919893bf4fc5cc91a0f73cbee720 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 4 Jul 2014 20:53:23 -0500 Subject: [PATCH] Get rid of input_idx_t This can't simply be changed anymore, so there's not much point in having it. For now window sizes are fixed at 32 bits. --- include/wimlib/compress_common.h | 12 +++------- include/wimlib/decompress_common.h | 9 ++------ include/wimlib/lz.h | 4 ++-- include/wimlib/lz_hash.h | 4 ++-- src/compress_common.c | 4 ++-- src/lz_hash.c | 10 ++++----- src/lzx-compress.c | 36 +++++++++++++++--------------- src/xpress-compress.c | 14 ++++++------ src/xpress-decompress.c | 6 ++--- 9 files changed, 44 insertions(+), 55 deletions(-) diff --git a/include/wimlib/compress_common.h b/include/wimlib/compress_common.h index d2b6310e..9910d412 100644 --- a/include/wimlib/compress_common.h +++ b/include/wimlib/compress_common.h @@ -12,12 +12,6 @@ #include "wimlib/types.h" -/* Variable type that can represent all possible window positions. */ -#ifndef INPUT_IDX_T_DEFINED -#define INPUT_IDX_T_DEFINED -typedef u32 input_idx_t; -#endif - /* Structure to keep track of the current state sending bits and bytes to the * compressed output buffer. */ struct output_bitstream { @@ -47,7 +41,7 @@ struct output_bitstream { u8 *output; /* Number of bytes remaining in the @output buffer. */ - input_idx_t bytes_remaining; + u32 bytes_remaining; /* Set to true if the buffer has been exhausted. */ bool overrun; @@ -57,7 +51,7 @@ extern void init_output_bitstream(struct output_bitstream *ostream, void *data, unsigned num_bytes); -extern input_idx_t +extern u32 flush_output_bitstream(struct output_bitstream *ostream); extern void @@ -70,7 +64,7 @@ bitstream_put_byte(struct output_bitstream *ostream, u8 n); extern void make_canonical_huffman_code(unsigned num_syms, unsigned max_codeword_len, - const input_idx_t freq_tab[restrict], + const u32 freq_tab[restrict], u8 lens[restrict], u32 codewords[restrict]); diff --git a/include/wimlib/decompress_common.h b/include/wimlib/decompress_common.h index d6c90899..fab3c3e0 100644 --- a/include/wimlib/decompress_common.h +++ b/include/wimlib/decompress_common.h @@ -15,11 +15,6 @@ #include "wimlib/endianness.h" #include "wimlib/types.h" -#ifndef INPUT_IDX_T_DEFINED -#define INPUT_IDX_T_DEFINED -typedef u32 input_idx_t; -#endif - /* Structure to encapsulate a block of in-memory data that is being interpreted * as a stream of bits. * @@ -39,13 +34,13 @@ struct input_bitstream { const u8 *data; /* Number of bytes of data that are left. */ - input_idx_t data_bytes_left; + u32 data_bytes_left; }; /* Initializes a bitstream to receive its input from @data. */ static inline void init_input_bitstream(struct input_bitstream *istream, - const void *data, input_idx_t num_data_bytes) + const void *data, u32 num_data_bytes) { istream->bitbuf = 0; istream->bitsleft = 0; diff --git a/include/wimlib/lz.h b/include/wimlib/lz.h index dfba7c2a..7870c972 100644 --- a/include/wimlib/lz.h +++ b/include/wimlib/lz.h @@ -20,8 +20,8 @@ * This can alternatively be used to represent a literal byte if @len is less * than the minimum match length. */ struct lz_match { - input_idx_t len; - input_idx_t offset; + u32 len; + u32 offset; }; #endif /* _WIMLIB_LZ_H */ diff --git a/include/wimlib/lz_hash.h b/include/wimlib/lz_hash.h index 9d097ae6..9a856a5b 100644 --- a/include/wimlib/lz_hash.h +++ b/include/wimlib/lz_hash.h @@ -19,12 +19,12 @@ typedef void (*lz_record_literal_t)(u8 lit, void *ctx); extern void lz_analyze_block(const u8 window[restrict], - input_idx_t window_size, + u32 window_size, lz_record_match_t record_match, lz_record_literal_t record_literal, void *record_ctx, const struct lz_params *params, - input_idx_t prev_tab[restrict]); + u32 prev_tab[restrict]); #endif /* _WIMLIB_LZ_HASH_H */ diff --git a/src/compress_common.c b/src/compress_common.c index bdac4ed9..1653b04f 100644 --- a/src/compress_common.c +++ b/src/compress_common.c @@ -80,11 +80,11 @@ bitstream_put_byte(struct output_bitstream *ostream, u8 n) * * Returns -1 if the stream has overrun; otherwise returns the total number of * bytes in the output. */ -input_idx_t +u32 flush_output_bitstream(struct output_bitstream *ostream) { if (unlikely(ostream->overrun)) - return ~(input_idx_t)0; + return (u32)~0UL; *(le16*)ostream->bit_output = cpu_to_le16((u16)((u32)ostream->bitbuf << ostream->free_bits)); diff --git a/src/lz_hash.c b/src/lz_hash.c index ac469f20..af60c2ef 100644 --- a/src/lz_hash.c +++ b/src/lz_hash.c @@ -69,7 +69,7 @@ update_hash(unsigned hash, u8 c) * indicating the end of the hash chain. */ static inline unsigned -insert_string(input_idx_t hash_tab[], input_idx_t prev_tab[], +insert_string(u32 hash_tab[], u32 prev_tab[], const u8 window[], unsigned str_pos, unsigned hash) { @@ -106,7 +106,7 @@ insert_string(input_idx_t hash_tab[], input_idx_t prev_tab[], */ static unsigned longest_match(const u8 window[], unsigned bytes_remaining, - unsigned strstart, const input_idx_t prev_tab[], + unsigned strstart, const u32 prev_tab[], unsigned cur_match, unsigned prev_len, unsigned *match_start_ret, const struct lz_params *params, @@ -199,12 +199,12 @@ longest_match(const u8 window[], unsigned bytes_remaining, */ void lz_analyze_block(const u8 window[restrict], - input_idx_t window_size, + u32 window_size, lz_record_match_t record_match, lz_record_literal_t record_literal, void *record_ctx, const struct lz_params *params, - input_idx_t prev_tab[restrict]) + u32 prev_tab[restrict]) { unsigned cur_input_pos = 0; unsigned hash = 0; @@ -214,7 +214,7 @@ lz_analyze_block(const u8 window[restrict], unsigned match_len = params->min_match - 1; unsigned match_start = 0; bool match_available = false; - input_idx_t hash_tab[HASH_SIZE]; + u32 hash_tab[HASH_SIZE]; unsigned min_start_pos = 1; ZERO_ARRAY(hash_tab); diff --git a/src/lzx-compress.c b/src/lzx-compress.c index fbe25568..49e11830 100644 --- a/src/lzx-compress.c +++ b/src/lzx-compress.c @@ -294,9 +294,9 @@ struct lzx_codes { /* Tables for tallying symbol frequencies in the three LZX alphabets */ struct lzx_freqs { - input_idx_t main[LZX_MAINCODE_MAX_NUM_SYMBOLS]; - input_idx_t len[LZX_LENCODE_NUM_SYMBOLS]; - input_idx_t aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS]; + u32 main[LZX_MAINCODE_MAX_NUM_SYMBOLS]; + u32 len[LZX_LENCODE_NUM_SYMBOLS]; + u32 aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS]; }; /* LZX intermediate match/literal format */ @@ -325,16 +325,16 @@ struct lzx_block_spec { int block_type; /* 0-based position in the window at which this block starts. */ - input_idx_t window_pos; + u32 window_pos; /* The number of bytes of uncompressed data this block represents. */ - input_idx_t block_size; + u32 block_size; /* The match/literal sequence for this block. */ struct lzx_item *chosen_items; /* The length of the @chosen_items sequence. */ - input_idx_t num_chosen_items; + u32 num_chosen_items; /* Huffman codes for this block. */ struct lzx_codes codes; @@ -363,10 +363,10 @@ struct lzx_compressor { /* Number of bytes of data to be compressed, which is the number of * bytes of data in @window that are actually valid. */ - input_idx_t window_size; + u32 window_size; /* Allocated size of the @window. */ - input_idx_t max_window_size; + u32 max_window_size; /* Number of symbols in the main alphabet (depends on the * @max_window_size since it determines the maximum allowed offset). */ @@ -397,17 +397,17 @@ struct lzx_compressor { struct lzx_costs costs; /* Fast algorithm only: Array of hash table links. */ - input_idx_t *prev_tab; + u32 *prev_tab; /* Slow algorithm only: Binary tree match-finder. */ struct lz_bt mf; /* Position in window of next match to return. */ - input_idx_t match_window_pos; + u32 match_window_pos; /* The end-of-block position. We can't allow any matches to span this * position. */ - input_idx_t match_window_end; + u32 match_window_end; /* Matches found by the match-finder are cached in the following array * to achieve a slight speedup when the same matches are needed on @@ -453,22 +453,22 @@ struct lzx_mc_pos_data { /* Position of the start of the match or literal that * was taken to get to this position in the approximate * minimum-cost parse. */ - input_idx_t link; + u32 link; /* Offset (as in an LZ (length, offset) pair) of the * match or literal that was taken to get to this * position in the approximate minimum-cost parse. */ - input_idx_t match_offset; + u32 match_offset; } prev; struct { /* Position at which the match or literal starting at * this position ends in the minimum-cost parse. */ - input_idx_t link; + u32 link; /* Offset (as in an LZ (length, offset) pair) of the * match or literal starting at this position in the * approximate minimum-cost parse. */ - input_idx_t match_offset; + u32 match_offset; } next; }; @@ -643,7 +643,7 @@ static unsigned lzx_build_precode(const u8 lens[restrict], const u8 prev_lens[restrict], const unsigned num_syms, - input_idx_t precode_freqs[restrict LZX_PRECODE_NUM_SYMBOLS], + u32 precode_freqs[restrict LZX_PRECODE_NUM_SYMBOLS], u8 output_syms[restrict num_syms], u8 precode_lens[restrict LZX_PRECODE_NUM_SYMBOLS], u32 precode_codewords[restrict LZX_PRECODE_NUM_SYMBOLS], @@ -812,7 +812,7 @@ lzx_write_compressed_code(struct output_bitstream *out, const u8 prev_lens[restrict], unsigned num_syms) { - input_idx_t precode_freqs[LZX_PRECODE_NUM_SYMBOLS]; + u32 precode_freqs[LZX_PRECODE_NUM_SYMBOLS]; u8 output_syms[num_syms]; u8 precode_lens[LZX_PRECODE_NUM_SYMBOLS]; u32 precode_codewords[LZX_PRECODE_NUM_SYMBOLS]; @@ -2086,7 +2086,7 @@ lzx_compress(const void *uncompressed_data, size_t uncompressed_size, LZX_DEBUG("Flushing bitstream..."); compressed_size = flush_output_bitstream(&ostream); - if (compressed_size == ~(input_idx_t)0) { + if (compressed_size == (u32)~0UL) { LZX_DEBUG("Data did not compress to %zu bytes or less!", compressed_size_avail); return 0; diff --git a/src/xpress-compress.c b/src/xpress-compress.c index 228ac51e..e5051044 100644 --- a/src/xpress-compress.c +++ b/src/xpress-compress.c @@ -41,7 +41,7 @@ #include struct xpress_record_ctx { - input_idx_t freqs[XPRESS_NUM_SYMBOLS]; + u32 freqs[XPRESS_NUM_SYMBOLS]; struct xpress_match *matches; }; @@ -49,7 +49,7 @@ struct xpress_compressor { u8 *window; u32 max_window_size; struct xpress_match *matches; - input_idx_t *prev_tab; + u32 *prev_tab; u32 codewords[XPRESS_NUM_SYMBOLS]; u8 lens[XPRESS_NUM_SYMBOLS]; struct xpress_record_ctx record_ctx; @@ -94,11 +94,11 @@ xpress_write_match(struct xpress_match match, static void xpress_write_matches_and_literals(struct output_bitstream *ostream, const struct xpress_match matches[restrict], - input_idx_t num_matches, + u32 num_matches, const u32 codewords[restrict], const u8 lens[restrict]) { - for (input_idx_t i = 0; i < num_matches; i++) { + for (u32 i = 0; i < num_matches; i++) { if (matches[i].offset) { /* Real match */ xpress_write_match(matches[i], ostream, codewords, lens); @@ -159,8 +159,8 @@ xpress_compress(const void *uncompressed_data, size_t uncompressed_size, struct xpress_compressor *c = _c; u8 *cptr = compressed_data; struct output_bitstream ostream; - input_idx_t num_matches; - input_idx_t i; + u32 num_matches; + u32 i; size_t compressed_size; /* XPRESS requires 256 bytes of overhead for the Huffman code, so it's @@ -214,7 +214,7 @@ xpress_compress(const void *uncompressed_data, size_t uncompressed_size, /* Flush any pending data and get the length of the compressed data. */ compressed_size = flush_output_bitstream(&ostream); - if (compressed_size == ~(input_idx_t)0) + if (compressed_size == (u32)~0UL) return 0; compressed_size += XPRESS_NUM_SYMBOLS / 2; diff --git a/src/xpress-decompress.c b/src/xpress-decompress.c index 431563b6..7ad47264 100644 --- a/src/xpress-decompress.c +++ b/src/xpress-decompress.c @@ -85,8 +85,8 @@ * Returns the match length, or -1 if the data is invalid. */ static int -xpress_decode_match(unsigned sym, input_idx_t window_pos, - input_idx_t window_len, u8 window[restrict], +xpress_decode_match(unsigned sym, u32 window_pos, + u32 window_len, u8 window[restrict], struct input_bitstream * restrict istream) { unsigned len_hdr; @@ -135,7 +135,7 @@ xpress_lz_decode(struct input_bitstream * restrict istream, unsigned uncompressed_len, const u16 decode_table[restrict]) { - input_idx_t curpos; + u32 curpos; unsigned match_len; for (curpos = 0; curpos < uncompressed_len; curpos += match_len) { -- 2.43.0