]> wimlib.net Git - wimlib/blobdiff - src/xpress-decompress.c
make_huffman_decode_table(): Add SSE2 entry filling (with aliasing handled correctly)
[wimlib] / src / xpress-decompress.c
index 6570e725baeb0554ce299139717eb19674c62d0d..5586c15ce006118a2dade85c0a4f7d45a5d6176c 100644 (file)
  * extra symbol is there or not.
  */
 
-#include "util.h"
-#include "xpress.h"
-#include "wimlib.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
 
+#include "wimlib.h"
+#include "wimlib/assert.h"
 #define XPRESS_DECOMP
-#include "decompress.h"
+#include "wimlib/decompress.h"
+#include "wimlib/util.h"
+#include "wimlib/xpress.h"
 
 /*
  * Decodes a symbol @huffsym that begins an XPRESS match.
  *
  * Returns the match length, or -1 on error.
  */
-static int xpress_decode_match(unsigned huffsym, unsigned window_pos,
-                              unsigned window_len, u8 window[],
-                              struct input_bitstream *istream)
+static int
+xpress_decode_match(unsigned huffsym, unsigned window_pos,
+                   unsigned window_len, u8 window[restrict],
+                   struct input_bitstream * restrict istream)
 {
        unsigned match_len;
        unsigned match_offset;
@@ -106,7 +111,7 @@ static int xpress_decode_match(unsigned huffsym, unsigned window_pos,
        unsigned i;
 
        ret = bitstream_read_bits(istream, offset_bsr, &match_offset);
-       if (ret != 0)
+       if (ret)
                return ret;
        match_offset |= (1 << offset_bsr);
 
@@ -162,11 +167,12 @@ static int xpress_decode_match(unsigned huffsym, unsigned window_pos,
 
 /* Decodes the Huffman-encoded matches and literal bytes in a block of
  * XPRESS-encoded data. */
-static int xpress_decompress_block(struct input_bitstream *istream,
-                                  u8 uncompressed_data[],
-                                  unsigned uncompressed_len,
-                                  const u8 lens[],
-                                  const u16 decode_table[])
+static int
+xpress_decompress_block(struct input_bitstream * restrict istream,
+                       u8 uncompressed_data[restrict],
+                       unsigned uncompressed_len,
+                       const u8 lens[restrict],
+                       const u16 decode_table[restrict])
 {
        unsigned curpos;
        unsigned huffsym;
@@ -178,7 +184,7 @@ static int xpress_decompress_block(struct input_bitstream *istream,
                ret = read_huffsym(istream, decode_table, lens,
                                   XPRESS_NUM_SYMBOLS, XPRESS_TABLEBITS,
                                   &huffsym, XPRESS_MAX_CODEWORD_LEN);
-               if (ret != 0)
+               if (ret)
                        return ret;
 
                if (huffsym < XPRESS_NUM_CHARS) {
@@ -198,18 +204,21 @@ static int xpress_decompress_block(struct input_bitstream *istream,
 }
 
 
-int xpress_decompress(const void *__compressed_data, unsigned compressed_len,
-                     void *uncompressed_data, unsigned uncompressed_len)
+/* Documented in wimlib.h */
+WIMLIBAPI int
+wimlib_xpress_decompress(const void * restrict _compressed_data, unsigned compressed_len,
+                        void * restrict uncompressed_data, unsigned uncompressed_len)
 {
        u8 lens[XPRESS_NUM_SYMBOLS];
-       u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS];
+       u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS]
+                       _aligned_attribute(DECODE_TABLE_ALIGNMENT);
        struct input_bitstream istream;
        u8 *lens_p;
        const u8 *compressed_data;
        unsigned i;
        int ret;
 
-       compressed_data = __compressed_data;
+       compressed_data = _compressed_data;
        lens_p = lens;
 
        DEBUG2("compressed_len = %d, uncompressed_len = %d",
@@ -219,8 +228,10 @@ int xpress_decompress(const void *__compressed_data, unsigned compressed_len,
         * code lengths of these symbols are given literally as 4-bit integers
         * in the first 256 bytes of the compressed data.
         */
-       if (compressed_len < XPRESS_NUM_SYMBOLS / 2)
+       if (compressed_len < XPRESS_NUM_SYMBOLS / 2) {
+               ERROR("xpress_decompress(): Compressed length too short!");
                return -1;
+       }
 
        for (i = 0; i < XPRESS_NUM_SYMBOLS / 2; i++) {
                *lens_p++ = compressed_data[i] & 0xf;
@@ -230,7 +241,7 @@ int xpress_decompress(const void *__compressed_data, unsigned compressed_len,
        ret = make_huffman_decode_table(decode_table, XPRESS_NUM_SYMBOLS,
                                        XPRESS_TABLEBITS, lens,
                                        XPRESS_MAX_CODEWORD_LEN);
-       if (ret != 0)
+       if (ret)
                return ret;
 
        init_input_bitstream(&istream, compressed_data + XPRESS_NUM_SYMBOLS / 2,