igzip: Merge inflate.h and igzip_lib.h and fix external naming

Merge inflate.h and igzip_lib.h and rename many defines to avoid conflicts,
along with general cleanup of the new header.

Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
Reviewed-by: Greg Tucker <greg.b.tucker@intel.com>
This commit is contained in:
Roy Oursler 2016-08-05 14:11:25 -04:00 committed by Greg Tucker
parent be8e83b633
commit 88f95d8594
31 changed files with 447 additions and 435 deletions

View File

@ -50,7 +50,7 @@ lsrc += igzip/igzip.c igzip/hufftables_c.c \
igzip/igzip_inflate_multibinary.asm
src_include += -I $(srcdir)/igzip
extern_hdrs += include/igzip_lib.h include/inflate.h
extern_hdrs += include/igzip_lib.h
pkginclude_HEADERS += include/types.h

View File

@ -31,6 +31,14 @@
#include "igzip_lib.h"
/* bit buffer types
* BITBUF8: (e) Always write 8 bytes of data
* BITBUFB: (b) Always write data
*/
#if !(defined(USE_BITBUFB) || defined(USE_BITBUF8) || defined(USE_BITBUF_ELSE))
# define USE_BITBUFB
#endif
#if defined (__unix__) || (__APPLE__)
#define _mm_stream_si64x(dst, src) *((uint64_t*)dst) = src
#else

View File

@ -85,8 +85,8 @@ FIELD _has_gzip_hdr, 4, 4
FIELD _has_eob, 4, 4
FIELD _has_eob_hdr, 4, 4
FIELD _left_over, 4, 4
FIELD _buffer, BSIZE+16, 32
FIELD _head, HASH_SIZE*2, 16
FIELD _buffer, BSIZE, 32
FIELD _head, IGZIP_HASH_SIZE*2, 16
%assign _isal_zstate_size _FIELD_OFFSET
%assign _isal_zstate_align _STRUCT_ALIGN

View File

@ -45,13 +45,13 @@
* generate_custom_hufftables are the same as the default parameters used by
* igzip.
*
* *WARNING* generate custom hufftables must be compiled with a HIST_SIZE that
* is at least as large as the HIST_SIZE used by igzip. By default HIST_SIZE is
* 8, the maximum usable HIST_SIZE is 32. The reason for this is to generate
* better compression. Igzip cannot produce look back distances with sizes
* larger than the HIST_SIZE * 1024 igzip was compiled with, so look back
* distances with sizes larger than HIST_SIZE * 1024 are not assigned a huffman
* code.
* *WARNING* generate custom hufftables must be compiled with a IGZIP_HIST_SIZE
* that is at least as large as the IGZIP_HIST_SIZE used by igzip. By default
* IGZIP_HIST_SIZE is 8K, the maximum usable IGZIP_HIST_SIZE is 32K. The reason
* for this is to generate better compression. Igzip cannot produce look back
* distances with sizes larger than the IGZIP_HIST_SIZE igzip was compiled with,
* so look back distances with sizes larger than IGZIP_HIST_SIZE are not
* assigned a huffman code.
*
* To improve compression ratio, the compile time option LIT_SUB is provided to
* allow generating custom hufftables which only use a subset of all possible
@ -86,7 +86,7 @@
#define LONG_DCODE_OFFSET 26
#define SHORT_DCODE_OFFSET 0
#define MAX_HEADER_SIZE IGZIP_MAX_DEF_HDR_SIZE
#define MAX_HEADER_SIZE ISAL_DEF_MAX_HDR_SIZE
#define GZIP_HEADER_SIZE 10
#define GZIP_TRAILER_SIZE 8

View File

@ -51,6 +51,7 @@ struct slver {
/* Version info */
struct slver isal_update_histogram_slver_00010085;
struct slver isal_update_histogram_slver = { 0x0085, 0x01, 0x00 };
struct slver isal_create_hufftables_slver_00010086;
struct slver isal_create_hufftables_slver = { 0x0086, 0x01, 0x00 };
@ -158,7 +159,7 @@ void isal_update_histogram_base(uint8_t * start_stream, int length,
struct isal_huff_histogram *histogram)
{
uint32_t literal = 0, hash;
uint8_t *last_seen[HASH_SIZE];
uint8_t *last_seen[IGZIP_HASH_SIZE];
uint8_t *current, *seen, *end_stream, *next_hash, *end;
uint32_t match_length;
uint32_t dist;
@ -180,7 +181,7 @@ void isal_update_histogram_base(uint8_t * start_stream, int length,
match_length = compare258(seen, current, end_stream - current);
if (match_length >= SHORTEST_MATCH) {
next_hash = current;
#ifdef LIMIT_HASH_UPDATE
#ifdef ISAL_LIMIT_HASH_UPDATE
end = next_hash + 3;
#else
end = next_hash + match_length;
@ -848,7 +849,7 @@ int isal_create_hufftables(struct isal_hufftables *hufftables,
struct huff_tree lit_tree_array[2 * LIT_LEN - 1], dist_tree_array[2 * DIST_LEN - 1];
struct huff_code lit_huff_table[LIT_LEN], dist_huff_table[DIST_LEN];
uint64_t bit_count;
int max_dist = convert_dist_to_dist_sym(IGZIP_D);
int max_dist = convert_dist_to_dist_sym(IGZIP_HIST_SIZE);
uint32_t *dist_table = hufftables->dist_table;
uint32_t *len_table = hufftables->len_table;
@ -891,10 +892,10 @@ int isal_create_hufftables(struct isal_hufftables *hufftables,
create_code_tables(dcodes, dcodes_sizes, DIST_LEN - DCODE_OFFSET,
dist_huff_table + DCODE_OFFSET);
create_code_tables(lit_table, lit_table_sizes, LIT_TABLE_SIZE, lit_huff_table);
create_code_tables(lit_table, lit_table_sizes, IGZIP_LIT_TABLE_SIZE, lit_huff_table);
create_packed_len_table(len_table, lit_huff_table);
create_packed_dist_table(dist_table, DIST_TABLE_SIZE, dist_huff_table);
create_packed_dist_table(dist_table, IGZIP_DIST_TABLE_SIZE, dist_huff_table);
bit_count =
create_header(deflate_hdr, sizeof(deflate_hdr), lit_huff_table, dist_huff_table,
@ -913,7 +914,7 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables,
struct huff_tree lit_tree_array[2 * LIT_LEN - 1], dist_tree_array[2 * DIST_LEN - 1];
struct huff_code lit_huff_table[LIT_LEN], dist_huff_table[DIST_LEN];
uint64_t bit_count;
int j, max_dist = convert_dist_to_dist_sym(IGZIP_D);
int j, max_dist = convert_dist_to_dist_sym(IGZIP_HIST_SIZE);
uint32_t *dist_table = hufftables->dist_table;
uint32_t *len_table = hufftables->len_table;
@ -960,10 +961,10 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables,
create_code_tables(dcodes, dcodes_sizes, DIST_LEN - DCODE_OFFSET,
dist_huff_table + DCODE_OFFSET);
create_code_tables(lit_table, lit_table_sizes, LIT_TABLE_SIZE, lit_huff_table);
create_code_tables(lit_table, lit_table_sizes, IGZIP_LIT_TABLE_SIZE, lit_huff_table);
create_packed_len_table(len_table, lit_huff_table);
create_packed_dist_table(dist_table, DIST_TABLE_SIZE, dist_huff_table);
create_packed_dist_table(dist_table, IGZIP_DIST_TABLE_SIZE, dist_huff_table);
bit_count =
create_header(deflate_hdr, sizeof(deflate_hdr), lit_huff_table, dist_huff_table,

View File

@ -43,8 +43,8 @@
# include <x86intrin.h>
#endif
#define LIT_LEN IGZIP_LIT_LEN
#define DIST_LEN IGZIP_DIST_LEN
#define LIT_LEN ISAL_DEF_LIT_LEN_SYMBOLS
#define DIST_LEN ISAL_DEF_DIST_SYMBOLS
#define CODE_LEN_CODES 19
#define HUFF_LEN 19
#ifdef LONGER_HUFFTABLE
@ -55,7 +55,7 @@
#define DYN_HDR_START_LEN 17
#define MAX_HISTHEAP_SIZE LIT_LEN
#define MAX_HUFF_TREE_DEPTH 15
#define D IGZIP_D /* Amount of history */
#define D IGZIP_HIST_SIZE /* Amount of history */
#define MAX_DEFLATE_CODE_LEN 15
#define MAX_SAFE_LIT_CODE_LEN 13
@ -76,6 +76,9 @@
#define INVALID_DIST_HUFFCODE 1
#define INVALID_HUFFCODE 1
#define HASH_MASK (IGZIP_HASH_SIZE - 1)
#define SHORTEST_MATCH 4
/**
* @brief Structure used to store huffman codes
*/

View File

@ -48,7 +48,7 @@
%define LEN_TABLE_SIZE 256
%define LIT_TABLE_SIZE 257
%define DIST_TABLE_START (IGZIP_MAX_DEF_HDR_SIZE + 8)
%define DIST_TABLE_START (ISAL_DEF_MAX_HDR_SIZE + 8)
%define DIST_TABLE_OFFSET (DIST_TABLE_START + - 4 * 1)
%define LEN_TABLE_OFFSET (DIST_TABLE_START + DIST_TABLE_SIZE * 4 - 4*3)
%define LIT_TABLE_OFFSET (DIST_TABLE_START + 4 * DIST_TABLE_SIZE + 4 * LEN_TABLE_SIZE)
@ -58,7 +58,7 @@
;; /** @brief Holds the huffman tree used to huffman encode the input stream **/
;; struct isal_hufftables {
;; // deflate huffman tree header
;; uint8_t deflate_huff_hdr[IGZIP_MAX_DEF_HDR_SIZE];
;; uint8_t deflate_huff_hdr[ISAL_DEF_MAX_HDR_SIZE];
;;
;; //!< Number of whole bytes in deflate_huff_hdr
;; uint32_t deflate_huff_hdr_count;

View File

@ -75,7 +75,7 @@ static inline uint32_t tzcnt(uint64_t val)
static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist, uint64_t *p_code, uint64_t *p_len)
{
assert(dist > DIST_TABLE_SIZE);
assert(dist > IGZIP_DIST_TABLE_SIZE);
dist -= 1;
uint32_t msb;
@ -92,8 +92,8 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist,
dist >>= num_extra_bits;
sym = dist + 2 * num_extra_bits;
assert(sym < 30);
code = hufftables->dcodes[sym - DECODE_OFFSET];
len = hufftables->dcodes_sizes[sym - DECODE_OFFSET];
code = hufftables->dcodes[sym - IGZIP_DECODE_OFFSET];
len = hufftables->dcodes_sizes[sym - IGZIP_DECODE_OFFSET];
*p_code = code | (extra_bits << len);
*p_len = len + num_extra_bits;
}
@ -104,7 +104,7 @@ static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t di
dist = 0;
assert(dist >= 1);
assert(dist <= 32768);
if (dist <= DIST_TABLE_SIZE) {
if (dist <= IGZIP_DIST_TABLE_SIZE) {
uint64_t code_len;
code_len = hufftables->dist_table[dist - 1];
*code = code_len >> 5;

View File

@ -496,7 +496,7 @@ static inline void reset_match_history(struct isal_zstream *stream)
for (i = 0; i < sizeof(state->head) / 2; i++) {
head[i] =
(uint16_t) (state->b_bytes_processed + state->buffer - state->file_start -
IGZIP_D);
IGZIP_HIST_SIZE);
}
}
@ -641,7 +641,7 @@ int isal_deflate(struct isal_zstream *stream)
state->last_flush = stream->flush;
if (state->state >= TMP_OFFSET_SIZE) {
if (state->state >= ZSTATE_TMP_OFFSET) {
size = state->tmp_out_end - state->tmp_out_start;
if (size > stream->avail_out)
size = stream->avail_out;
@ -653,7 +653,7 @@ int isal_deflate(struct isal_zstream *stream)
state->tmp_out_start += size;
if (state->tmp_out_start == state->tmp_out_end)
state->state -= TMP_OFFSET_SIZE;
state->state -= ZSTATE_TMP_OFFSET;
if (stream->avail_out == 0 || state->state == ZSTATE_END)
return ret;
@ -696,7 +696,7 @@ int isal_deflate(struct isal_zstream *stream)
stream->total_out += size;
state->tmp_out_start += size;
if (state->tmp_out_start != state->tmp_out_end)
state->state += TMP_OFFSET_SIZE;
state->state += ZSTATE_TMP_OFFSET;
}
}

View File

@ -36,8 +36,8 @@ void isal_deflate_init_base(struct isal_zstream *stream)
*crc = ~0;
for (i = 0; i < HASH_SIZE; i++)
state->head[i] = (uint16_t) - (IGZIP_D + 1);
for (i = 0; i < IGZIP_HASH_SIZE; i++)
state->head[i] = (uint16_t) - (IGZIP_HIST_SIZE + 1);
return;
}
@ -82,16 +82,17 @@ void isal_deflate_body_base(struct isal_zstream *stream)
while (stream->avail_in != 0) {
bytes_to_buffer =
IGZIP_D + IGZIP_LA - (state->b_bytes_valid - state->b_bytes_processed);
IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD - (state->b_bytes_valid -
state->b_bytes_processed);
if (bytes_to_buffer > IGZIP_D)
bytes_to_buffer = IGZIP_D;
if (bytes_to_buffer > IGZIP_HIST_SIZE)
bytes_to_buffer = IGZIP_HIST_SIZE;
if (stream->avail_in < IGZIP_D)
if (stream->avail_in < IGZIP_HIST_SIZE)
bytes_to_buffer = stream->avail_in;
if (bytes_to_buffer > BSIZE - state->b_bytes_valid) {
if (state->b_bytes_valid - state->b_bytes_processed > IGZIP_LA) {
if (bytes_to_buffer > sizeof(state->buffer) - state->b_bytes_valid) {
if (state->b_bytes_valid - state->b_bytes_processed > ISAL_LOOK_AHEAD) {
/* There was an out buffer overflow last round,
* complete the processing of data */
bytes_to_buffer = 0;
@ -99,9 +100,9 @@ void isal_deflate_body_base(struct isal_zstream *stream)
} else {
/* Not enough room in the buffer, shift the
* buffer down to make space for the new data */
offset = state->b_bytes_processed - IGZIP_D; // state->b_bytes_valid - (IGZIP_D + IGZIP_LA);
offset = state->b_bytes_processed - IGZIP_HIST_SIZE; // state->b_bytes_valid - (IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD);
memmove(state->buffer, state->buffer + offset,
IGZIP_D + IGZIP_LA);
IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD);
state->b_bytes_processed -= offset;
state->b_bytes_valid -= offset;
@ -124,7 +125,7 @@ void isal_deflate_body_base(struct isal_zstream *stream)
state->b_bytes_valid += bytes_to_buffer;
end_in = state->buffer + state->b_bytes_valid - IGZIP_LA;
end_in = state->buffer + state->b_bytes_valid - ISAL_LOOK_AHEAD;
next_in = state->b_bytes_processed + state->buffer;
@ -141,7 +142,7 @@ void isal_deflate_body_base(struct isal_zstream *stream)
dist = (next_in - state->file_start - last_seen[hash]) & 0xFFFF;
last_seen[hash] = (uint64_t) (next_in - state->file_start);
if (dist - 1 < IGZIP_D - 1) { /* The -1 are to handle the case when dist = 0 */
if (dist - 1 < IGZIP_HIST_SIZE - 1) { /* The -1 are to handle the case when dist = 0 */
assert(next_in - dist >= state->buffer);
assert(dist != 0);
@ -149,7 +150,7 @@ void isal_deflate_body_base(struct isal_zstream *stream)
if (match_length >= SHORTEST_MATCH) {
next_hash = next_in;
#ifdef LIMIT_HASH_UPDATE
#ifdef ISAL_LIMIT_HASH_UPDATE
end = next_hash + 3;
#else
end = next_hash + match_length;
@ -229,13 +230,13 @@ void isal_deflate_finish_base(struct isal_zstream *stream)
dist = (next_in - state->file_start - last_seen[hash]) & 0xFFFF;
last_seen[hash] = (uint64_t) (next_in - state->file_start);
if (dist - 1 < IGZIP_D - 1) { /* The -1 are to handle the case when dist = 0 */
if (dist - 1 < IGZIP_HIST_SIZE - 1) { /* The -1 are to handle the case when dist = 0 */
assert(next_in - dist >= state->buffer);
match_length = compare258(next_in - dist, next_in, end_in - next_in);
if (match_length >= SHORTEST_MATCH) {
next_hash = next_in;
#ifdef LIMIT_HASH_UPDATE
#ifdef ISAL_LIMIT_HASH_UPDATE
end = next_hash + 3;
#else
end = next_hash + match_length;

View File

@ -32,7 +32,6 @@
#include <string.h>
#include <assert.h>
#include "igzip_lib.h"
#include "inflate.h"
#include "crc_inflate.h"
#include <math.h>
@ -383,22 +382,19 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
switch (ret) {
case 0:
break;
case END_OF_INPUT:
case ISAL_END_INPUT:
return INFLATE_END_OF_INPUT;
break;
case INVALID_BLOCK_HEADER:
case ISAL_INVALID_BLOCK:
return INFLATE_INVALID_BLOCK_HEADER;
break;
case INVALID_SYMBOL:
case ISAL_INVALID_SYMBOL:
return INFLATE_INVALID_SYMBOL;
break;
case OUT_BUFFER_OVERFLOW:
case ISAL_OUT_OVERFLOW:
return INFLATE_OUT_BUFFER_OVERFLOW;
break;
case INVALID_NON_COMPRESSED_BLOCK_LENGTH:
return INFLATE_INVALID_NON_COMPRESSED_BLOCK_LENGTH;
break;
case INVALID_LOOK_BACK_DISTANCE:
case ISAL_INVALID_LOOKBACK:
return INFLATE_INVALID_LOOK_BACK_DISTANCE;
break;
default:
@ -1165,7 +1161,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);
#endif
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
printf("Test Seed : %d\n", TEST_SEED);
printf("Randoms : %d\n", RANDOMS);
srand(TEST_SEED);

View File

@ -2,19 +2,18 @@ default rel
%include "reg_sizes.asm"
%define DECOMPRESSION_FINISHED 0
%define END_OF_INPUT 1
%define OUT_BUFFER_OVERFLOW 2
%define INVALID_BLOCK_HEADER 3
%define INVALID_SYMBOL 4
%define INVALID_NON_COMPRESSED_BLOCK_LENGTH 5
%define INVALID_LOOK_BACK_DISTANCE 6
%define DECOMP_OK 0
%define END_INPUT 1
%define OUT_OVERFLOW 2
%define INVALID_BLOCK -1
%define INVALID_SYMBOL -2
%define INVALID_LOOKBACK -3
%define DECODE_LOOKUP_SIZE_LARGE 12
%define DECODE_LOOKUP_SIZE_SMALL 10
%define ISAL_DECODE_LONG_BITS 12
%define ISAL_DECODE_SHORT_BITS 10
%define MAX_LONG_CODE_LARGE (288 + (1 << (15 - DECODE_LOOKUP_SIZE_LARGE)))
%define MAX_LONG_CODE_SMALL (32 + (1 << (15 - DECODE_LOOKUP_SIZE_SMALL)))
%define MAX_LONG_CODE_LARGE (288 + (1 << (15 - ISAL_DECODE_LONG_BITS)))
%define MAX_LONG_CODE_SMALL (32 + (1 << (15 - ISAL_DECODE_SHORT_BITS)))
%define COPY_SIZE 16
%define COPY_LEN_MAX 258
@ -377,7 +376,7 @@ decode_huffman_code_block_stateless_ %+ ARCH %+ :
skip_load:
mov tmp3, read_in
and tmp3, (1 << DECODE_LOOKUP_SIZE_LARGE) - 1
and tmp3, (1 << ISAL_DECODE_LONG_BITS) - 1
movzx next_sym, word [state + _lit_huff_code + 2 * tmp3]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -391,14 +390,14 @@ loop_block:
jg end_loop_block_pre
;; Decode next symbol and reload the read_in buffer
decode_next2 state, DECODE_LOOKUP_SIZE_LARGE, _lit_huff_code, read_in, read_in_length, next_sym, tmp1
decode_next2 state, ISAL_DECODE_LONG_BITS, _lit_huff_code, read_in, read_in_length, next_sym, tmp1
;; Save next_sym in next_sym2 so next_sym can be preloaded
mov next_sym2, next_sym
;; Find index to specutively preload next_sym from
mov tmp3, read_in
and tmp3, (1 << DECODE_LOOKUP_SIZE_LARGE) - 1
and tmp3, (1 << ISAL_DECODE_LONG_BITS) - 1
;; Start reloading read_in
mov tmp1, [next_in]
@ -426,7 +425,7 @@ loop_block:
;; Specultively load next dist code
SHRX read_in_2, read_in, rcx
mov next_bits2, read_in_2
and next_bits2, (1 << DECODE_LOOKUP_SIZE_SMALL) - 1
and next_bits2, (1 << ISAL_DECODE_SHORT_BITS) - 1
movzx next_sym3, word [state + _dist_huff_code + 2 * next_bits2]
;; Specutively write next_sym2 if it is a literal
@ -447,7 +446,7 @@ decode_len_dist:
sub read_in_length, rcx
;; Decode distance code
decode_next2 state, DECODE_LOOKUP_SIZE_SMALL, _dist_huff_code, read_in_2, read_in_length, next_sym3, tmp2
decode_next2 state, ISAL_DECODE_SHORT_BITS, _dist_huff_code, read_in_2, read_in_length, next_sym3, tmp2
movzx rcx, byte [rfc_lookup + _dist_extra_bit_count + next_sym3]
mov look_back_dist2 %+ d, [rfc_lookup + _dist_start + 4 * next_sym3]
@ -465,7 +464,7 @@ decode_len_dist:
;; Setup next_sym, read_in, and read_in_length for next loop
mov read_in, read_in_2
and read_in_2, (1 << DECODE_LOOKUP_SIZE_LARGE) - 1
and read_in_2, (1 << ISAL_DECODE_LONG_BITS) - 1
movzx next_sym, word [state + _lit_huff_code + 2 * read_in_2]
sub read_in_length, rcx
@ -532,7 +531,7 @@ end_loop_block:
mov [rsp + read_in_mem_offset], read_in
mov [rsp + read_in_length_mem_offset], read_in_length
decode_next state, DECODE_LOOKUP_SIZE_LARGE, _lit_huff_code, read_in, read_in_length, next_sym, tmp1, tmp2
decode_next state, ISAL_DECODE_LONG_BITS, _lit_huff_code, read_in, read_in_length, next_sym, tmp1, tmp2
;; Check that enough input was available to decode symbol
cmp read_in_length, 0
@ -558,7 +557,7 @@ decode_len_dist_2:
sub read_in_length, rcx
;; Decode distance code
decode_next state, DECODE_LOOKUP_SIZE_SMALL, _dist_huff_code, read_in, read_in_length, next_sym, tmp1, tmp2
decode_next state, ISAL_DECODE_SHORT_BITS, _dist_huff_code, read_in, read_in_length, next_sym, tmp1, tmp2
;; Load distance code extra bits
mov next_bits, read_in
@ -605,7 +604,7 @@ decode_literal:
end_of_input:
mov read_in, [rsp + read_in_mem_offset]
mov read_in_length, [rsp + read_in_length_mem_offset]
mov rax, END_OF_INPUT
mov rax, END_INPUT
jmp end
out_buffer_overflow_repeat:
@ -620,17 +619,17 @@ out_buffer_overflow_repeat:
mov next_out, end_out
mov rax, OUT_BUFFER_OVERFLOW
mov rax, OUT_OVERFLOW
jmp end
out_buffer_overflow_lit:
mov read_in, [rsp + read_in_mem_offset]
mov read_in_length, [rsp + read_in_length_mem_offset]
mov rax, OUT_BUFFER_OVERFLOW
mov rax, OUT_OVERFLOW
jmp end
invalid_look_back_distance:
mov rax, INVALID_LOOK_BACK_DISTANCE
mov rax, INVALID_LOOKBACK
jmp end
end_symbol_pre:

View File

@ -55,7 +55,7 @@ int main(int argc, char *argv[])
exit(0);
}
printf("igzip_example\nWindow Size: %d K\n", HIST_SIZE);
printf("igzip_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024);
fflush(0);
isal_deflate_init(&stream);

View File

@ -82,7 +82,7 @@ int main(int argc, char *argv[])
}
printf("outfile=%s\n", argv[2]);
}
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE);
printf("igzip_file_perf: \n");
fflush(0);
/* Allocate space for entire input file and output

View File

@ -33,7 +33,6 @@
#include <string.h>
#include "igzip_lib.h"
#include "test.h"
#include "inflate.h"
#define BUF_SIZE 1024
#define MIN_TEST_LOOPS 8
@ -94,7 +93,7 @@ int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *h
if (state->block_state == ISAL_BLOCK_TYPE0) {
/* If the block is uncompressed, update state data accordingly */
if (state->avail_in < 4)
return END_OF_INPUT;
return ISAL_END_INPUT;
len = *(uint16_t *) state->next_in;
state->next_in += 2;
@ -103,7 +102,7 @@ int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *h
/* Check if len and nlen match */
if (len != (~nlen & 0xffff))
return INVALID_NON_COMPRESSED_BLOCK_LENGTH;
return ISAL_INVALID_BLOCK;
if (state->avail_in < len)
len = state->avail_in;
@ -115,7 +114,7 @@ int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *h
state->avail_in -= len + 4;
if (state->avail_in == 0 && state->block_state == 0)
return END_OF_INPUT;
return ISAL_END_INPUT;
} else {
/* Else decode a huffman encoded block */
@ -127,7 +126,7 @@ int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *h
histogram->lit_len_histogram[next_lit] += 1;
if (state->read_in_length < 0)
return END_OF_INPUT;
return ISAL_END_INPUT;
if (next_lit < 256)
/* Next symbol is a literal */
@ -157,15 +156,15 @@ int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *h
[next_dist]);
if (state->read_in_length < 0)
return END_OF_INPUT;
return ISAL_END_INPUT;
if (look_back_dist > state->total_out)
return INVALID_LOOK_BACK_DISTANCE;
return ISAL_INVALID_LOOKBACK;
state->total_out += repeat_length;
} else
return INVALID_SYMBOL;
return ISAL_INVALID_SYMBOL;
}
}
@ -175,7 +174,7 @@ int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *h
state->next_in -= state->read_in_length / 8;
state->avail_in += state->read_in_length / 8;
return DECOMPRESSION_FINISHED;
return ISAL_DECOMP_OK;
}
int get_filesize(FILE * f)
@ -193,7 +192,7 @@ void print_histogram(struct isal_huff_histogram *histogram)
{
int i;
printf("Lit Len histogram");
for (i = 0; i < IGZIP_LIT_LEN; i++) {
for (i = 0; i < ISAL_DEF_LIT_LEN_SYMBOLS; i++) {
if (i % 16 == 0)
printf("\n");
else
@ -203,7 +202,7 @@ void print_histogram(struct isal_huff_histogram *histogram)
printf("\n");
printf("Dist histogram");
for (i = 0; i < IGZIP_DIST_LEN; i++) {
for (i = 0; i < ISAL_DEF_DIST_SYMBOLS; i++) {
if (i % 16 == 0)
printf("\n");
else
@ -219,7 +218,7 @@ void print_diff_histogram(struct isal_huff_histogram *histogram1,
int i;
double relative_error;
printf("Lit Len histogram relative error");
for (i = 0; i < IGZIP_LIT_LEN; i++) {
for (i = 0; i < ISAL_DEF_LIT_LEN_SYMBOLS; i++) {
if (i % 16 == 0)
printf("\n");
else
@ -239,7 +238,7 @@ void print_diff_histogram(struct isal_huff_histogram *histogram1,
printf("\n");
printf("Dist histogram relative error");
for (i = 0; i < IGZIP_DIST_LEN; i++) {
for (i = 0; i < ISAL_DEF_DIST_SYMBOLS; i++) {
if (i % 16 == 0)
printf("\n");
else

View File

@ -1,7 +1,7 @@
// <COPYRIGHT_TAG>
#include <stdint.h>
#include "inflate.h"
#include "igzip_lib.h"
#include "huff_codes.h"
extern int decode_huffman_code_block_stateless(struct inflate_state *);
@ -43,22 +43,22 @@ static struct rfc1951_tables rfc_lookup_table = {
0x0083, 0x00a3, 0x00c3, 0x00e3, 0x0102, 0x0000, 0x0000, 0x0000}
};
struct slver {
uint16_t snum;
uint8_t ver;
uint8_t core;
uint16_t snum;
uint8_t ver;
uint8_t core;
};
/* Version info */
struct slver isal_inflate_init_slver_00010088;
struct slver isal_inflate_init_slver = { 0x0088, 0x01, 0x00 };
struct slver isal_inflate_stateless_slver_00010089;
struct slver isal_inflate_stateless_slver = { 0x0089, 0x01, 0x00 };
struct slver isal_inflate_slver_0001008a;
struct slver isal_inflate_slver = { 0x008a, 0x01, 0x00 };
/*Performs a copy of length repeat_length data starting at dest -
* lookback_distance into dest. This copy copies data previously copied when the
* src buffer and the dest buffer overlap. */
@ -146,7 +146,7 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
uint16_t next_code[MAX_HUFF_TREE_DEPTH + 1];
uint16_t long_code_list[LIT_LEN];
uint32_t long_code_length = 0;
uint16_t temp_code_list[1 << (15 - DECODE_LOOKUP_SIZE_LARGE)];
uint16_t temp_code_list[1 << (15 - ISAL_DECODE_LONG_BITS)];
uint32_t temp_code_length;
uint32_t long_code_lookup_length = 0;
uint32_t max_length;
@ -186,7 +186,7 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
for (k = 0; k < code_list_len; k++) {
i = code_list[k];
if (huff_code_table[i].length > DECODE_LOOKUP_SIZE_LARGE)
if (huff_code_table[i].length > ISAL_DECODE_LONG_BITS)
break;
while (huff_code_table[i].length > last_length) {
@ -212,7 +212,7 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
}
while (DECODE_LOOKUP_SIZE_LARGE > last_length) {
while (ISAL_DECODE_LONG_BITS > last_length) {
memcpy(short_code_lookup + copy_size, short_code_lookup,
sizeof(*short_code_lookup) * copy_size);
last_length++;
@ -243,14 +243,14 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
max_length = huff_code_table[long_code_list[i]].length;
first_bits =
huff_code_table[long_code_list[i]].code
& ((1 << DECODE_LOOKUP_SIZE_LARGE) - 1);
& ((1 << ISAL_DECODE_LONG_BITS) - 1);
temp_code_list[0] = long_code_list[i];
temp_code_length = 1;
for (j = i + 1; j < long_code_length; j++) {
if ((huff_code_table[long_code_list[j]].code &
((1 << DECODE_LOOKUP_SIZE_LARGE) - 1)) == first_bits) {
((1 << ISAL_DECODE_LONG_BITS) - 1)) == first_bits) {
if (max_length < huff_code_table[long_code_list[j]].length)
max_length = huff_code_table[long_code_list[j]].length;
temp_code_list[temp_code_length] = long_code_list[j];
@ -261,10 +261,9 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
for (j = 0; j < temp_code_length; j++) {
code_length = huff_code_table[temp_code_list[j]].length;
long_bits =
huff_code_table[temp_code_list[j]].code >>
DECODE_LOOKUP_SIZE_LARGE;
min_increment = 1 << (code_length - DECODE_LOOKUP_SIZE_LARGE);
for (; long_bits < (1 << (max_length - DECODE_LOOKUP_SIZE_LARGE));
huff_code_table[temp_code_list[j]].code >> ISAL_DECODE_LONG_BITS;
min_increment = 1 << (code_length - ISAL_DECODE_LONG_BITS);
for (; long_bits < (1 << (max_length - ISAL_DECODE_LONG_BITS));
long_bits += min_increment) {
result->long_code_lookup[long_code_lookup_length + long_bits] =
temp_code_list[j] | (code_length << 9);
@ -273,7 +272,7 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
}
result->short_code_lookup[first_bits] =
long_code_lookup_length | (max_length << 9) | 0x8000;
long_code_lookup_length += 1 << (max_length - DECODE_LOOKUP_SIZE_LARGE);
long_code_lookup_length += 1 << (max_length - ISAL_DECODE_LONG_BITS);
}
}
@ -287,7 +286,7 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
uint16_t next_code[MAX_HUFF_TREE_DEPTH + 1];
uint16_t long_code_list[LIT_LEN];
uint32_t long_code_length = 0;
uint16_t temp_code_list[1 << (15 - DECODE_LOOKUP_SIZE_SMALL)];
uint16_t temp_code_list[1 << (15 - ISAL_DECODE_SHORT_BITS)];
uint32_t temp_code_length;
uint32_t long_code_lookup_length = 0;
uint32_t max_length;
@ -327,7 +326,7 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
for (k = 0; k < code_list_len; k++) {
i = code_list[k];
if (huff_code_table[i].length > DECODE_LOOKUP_SIZE_SMALL)
if (huff_code_table[i].length > ISAL_DECODE_SHORT_BITS)
break;
while (huff_code_table[i].length > last_length) {
@ -353,7 +352,7 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
}
while (DECODE_LOOKUP_SIZE_SMALL > last_length) {
while (ISAL_DECODE_SHORT_BITS > last_length) {
memcpy(short_code_lookup + copy_size, short_code_lookup,
sizeof(*short_code_lookup) * copy_size);
last_length++;
@ -384,14 +383,14 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
max_length = huff_code_table[long_code_list[i]].length;
first_bits =
huff_code_table[long_code_list[i]].code
& ((1 << DECODE_LOOKUP_SIZE_SMALL) - 1);
& ((1 << ISAL_DECODE_SHORT_BITS) - 1);
temp_code_list[0] = long_code_list[i];
temp_code_length = 1;
for (j = i + 1; j < long_code_length; j++) {
if ((huff_code_table[long_code_list[j]].code &
((1 << DECODE_LOOKUP_SIZE_SMALL) - 1)) == first_bits) {
((1 << ISAL_DECODE_SHORT_BITS) - 1)) == first_bits) {
if (max_length < huff_code_table[long_code_list[j]].length)
max_length = huff_code_table[long_code_list[j]].length;
temp_code_list[temp_code_length] = long_code_list[j];
@ -402,10 +401,9 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
for (j = 0; j < temp_code_length; j++) {
code_length = huff_code_table[temp_code_list[j]].length;
long_bits =
huff_code_table[temp_code_list[j]].code >>
DECODE_LOOKUP_SIZE_SMALL;
min_increment = 1 << (code_length - DECODE_LOOKUP_SIZE_SMALL);
for (; long_bits < (1 << (max_length - DECODE_LOOKUP_SIZE_SMALL));
huff_code_table[temp_code_list[j]].code >> ISAL_DECODE_SHORT_BITS;
min_increment = 1 << (code_length - ISAL_DECODE_SHORT_BITS);
for (; long_bits < (1 << (max_length - ISAL_DECODE_SHORT_BITS));
long_bits += min_increment) {
result->long_code_lookup[long_code_lookup_length + long_bits] =
temp_code_list[j] | (code_length << 9);
@ -414,7 +412,7 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
}
result->short_code_lookup[first_bits] =
long_code_lookup_length | (max_length << 9) | 0x8000;
long_code_lookup_length += 1 << (max_length - DECODE_LOOKUP_SIZE_SMALL);
long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS);
}
}
@ -478,10 +476,10 @@ uint16_t inline decode_next_large(struct inflate_state *state,
uint32_t bit_count;
uint32_t bit_mask;
if (state->read_in_length <= DEFLATE_CODE_MAX_LENGTH)
if (state->read_in_length <= ISAL_DEF_MAX_CODE_LEN)
inflate_in_load(state, 0);
next_bits = state->read_in & ((1 << DECODE_LOOKUP_SIZE_LARGE) - 1);
next_bits = state->read_in & ((1 << ISAL_DECODE_LONG_BITS) - 1);
/* next_sym is a possible symbol decoded from next_bits. If bit 15 is 0,
* next_code is a symbol. Bits 9:0 represent the symbol, and bits 14:10
@ -508,7 +506,7 @@ uint16_t inline decode_next_large(struct inflate_state *state,
next_bits = state->read_in & bit_mask;
next_sym =
huff_code->long_code_lookup[(next_sym & 0x1FF) +
(next_bits >> DECODE_LOOKUP_SIZE_LARGE)];
(next_bits >> ISAL_DECODE_LONG_BITS)];
bit_count = next_sym >> 9;
state->read_in >>= bit_count;
state->read_in_length -= bit_count;
@ -527,10 +525,10 @@ uint16_t inline decode_next_small(struct inflate_state *state,
uint32_t bit_count;
uint32_t bit_mask;
if (state->read_in_length <= DEFLATE_CODE_MAX_LENGTH)
if (state->read_in_length <= ISAL_DEF_MAX_CODE_LEN)
inflate_in_load(state, 0);
next_bits = state->read_in & ((1 << DECODE_LOOKUP_SIZE_SMALL) - 1);
next_bits = state->read_in & ((1 << ISAL_DECODE_SHORT_BITS) - 1);
/* next_sym is a possible symbol decoded from next_bits. If bit 15 is 0,
* next_code is a symbol. Bits 9:0 represent the symbol, and bits 14:10
@ -557,7 +555,7 @@ uint16_t inline decode_next_small(struct inflate_state *state,
next_bits = state->read_in & bit_mask;
next_sym =
huff_code->long_code_lookup[(next_sym & 0x1FF) +
(next_bits >> DECODE_LOOKUP_SIZE_SMALL)];
(next_bits >> ISAL_DECODE_SHORT_BITS)];
bit_count = next_sym >> 9;
state->read_in >>= bit_count;
state->read_in_length -= bit_count;
@ -606,7 +604,7 @@ int inline setup_dynamic_header(struct inflate_state *state)
}
if (state->read_in_length < 0)
return END_OF_INPUT;
return ISAL_END_INPUT;
make_inflate_huff_code_small(&inflate_code_huff, code_huff, CODE_LEN_CODES,
code_count);
@ -629,7 +627,7 @@ int inline setup_dynamic_header(struct inflate_state *state)
symbol = decode_next_small(state, &inflate_code_huff);
if (state->read_in_length < 0)
return END_OF_INPUT;
return ISAL_END_INPUT;
if (symbol < 16) {
/* If a length is found, update the current lit/len/dist
@ -644,7 +642,7 @@ int inline setup_dynamic_header(struct inflate_state *state)
* length lit/len/dist elements to have the value of the
* repeated length */
if (previous == NULL) /* No elements available to be repeated */
return INVALID_BLOCK_HEADER;
return ISAL_INVALID_BLOCK;
i = 3 + inflate_in_read_bits(state, 2);
for (j = 0; j < i; j++) {
@ -694,12 +692,12 @@ int inline setup_dynamic_header(struct inflate_state *state)
current++;
}
} else
return INVALID_BLOCK_HEADER;
return ISAL_INVALID_BLOCK;
}
if (state->read_in_length < 0)
return END_OF_INPUT;
return ISAL_END_INPUT;
make_inflate_huff_code_large(&state->lit_huff_code, lit_and_dist_huff, LIT_LEN,
lit_count);
@ -728,14 +726,14 @@ int read_header(struct inflate_state *state)
btype = inflate_in_read_bits(state, 2);
if (state->read_in_length < 0)
ret = END_OF_INPUT;
ret = ISAL_END_INPUT;
else if (btype == 0) {
inflate_in_load(state, 40);
bytes = state->read_in_length / 8;
if (bytes < 4)
return END_OF_INPUT;
return ISAL_END_INPUT;
state->read_in >>= state->read_in_length % 8;
state->read_in_length = bytes * 8;
@ -755,7 +753,7 @@ int read_header(struct inflate_state *state)
/* Check if len and nlen match */
if (len != (~nlen & 0xffff))
return INVALID_NON_COMPRESSED_BLOCK_LENGTH;
return ISAL_INVALID_BLOCK;
state->type0_block_len = len;
state->block_state = ISAL_BLOCK_TYPE0;
@ -769,7 +767,7 @@ int read_header(struct inflate_state *state)
ret = setup_dynamic_header(state);
else
ret = INVALID_BLOCK_HEADER;
ret = ISAL_INVALID_BLOCK;
return ret;
}
@ -789,7 +787,7 @@ int read_header_stateful(struct inflate_state *state)
if (block_state_start == ISAL_BLOCK_HDR) {
/* Setup so read_header decodes data in tmp_in_buffer */
copy_size = ISAL_INFLATE_MAX_HDR_SIZE - state->tmp_in_size;
copy_size = ISAL_DEF_MAX_HDR_SIZE - state->tmp_in_size;
if (copy_size > state->avail_in)
copy_size = state->avail_in;
@ -809,7 +807,7 @@ int read_header_stateful(struct inflate_state *state)
state->avail_in = avail_in_start - bytes_read;
}
if (ret == END_OF_INPUT) {
if (ret == ISAL_END_INPUT) {
/* Save off data so header can be decoded again with more data */
state->read_in = read_in_start;
state->read_in_length = read_in_length_start;
@ -854,10 +852,10 @@ int inline decode_literal_block(struct inflate_state *state)
state->type0_block_len -= len;
if (state->avail_in == 0 && state->block_state != ISAL_BLOCK_NEW_HDR)
return END_OF_INPUT;
return ISAL_END_INPUT;
if (state->avail_out == 0 && state->type0_block_len > 0)
return OUT_BUFFER_OVERFLOW;
return ISAL_OUT_OVERFLOW;
return 0;
@ -895,7 +893,7 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state)
state->read_in_length = read_in_length_tmp;
state->next_in = next_in_tmp;
state->avail_in = avail_in_tmp;
return END_OF_INPUT;
return ISAL_END_INPUT;
}
if (next_lit < 256) {
@ -907,7 +905,7 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state)
state->read_in_length = read_in_length_tmp;
state->next_in = next_in_tmp;
state->avail_in = avail_in_tmp;
return OUT_BUFFER_OVERFLOW;
return ISAL_OUT_OVERFLOW;
}
*state->next_out = next_lit;
@ -945,11 +943,11 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state)
state->read_in_length = read_in_length_tmp;
state->next_in = next_in_tmp;
state->avail_in = avail_in_tmp;
return END_OF_INPUT;
return ISAL_END_INPUT;
}
if (look_back_dist > state->total_out)
return INVALID_LOOK_BACK_DISTANCE;
return ISAL_INVALID_LOOKBACK;
if (state->avail_out < repeat_length) {
state->copy_overflow_length = repeat_length - state->avail_out;
@ -968,11 +966,11 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state)
state->total_out += repeat_length;
if (state->copy_overflow_length > 0)
return OUT_BUFFER_OVERFLOW;
return ISAL_OUT_OVERFLOW;
} else
/* Else the read in bits do not
* correspond to any valid symbol */
return INVALID_SYMBOL;
return ISAL_INVALID_SYMBOL;
}
return 0;
}
@ -1044,11 +1042,11 @@ int isal_inflate(struct inflate_state *state)
if (state->block_state != ISAL_BLOCK_FINISH) {
/* If space in tmp_out buffer, decompress into the tmp_out_buffer */
if (state->tmp_out_valid < 2 * ISAL_INFLATE_HIST_SIZE) {
if (state->tmp_out_valid < 2 * ISAL_DEF_HIST_SIZE) {
/* Setup to start decoding into temp buffer */
state->next_out = &state->tmp_out_buffer[state->tmp_out_valid];
state->avail_out =
sizeof(state->tmp_out_buffer) - ISAL_INFLATE_SLOP -
sizeof(state->tmp_out_buffer) - ISAL_LOOK_AHEAD -
state->tmp_out_valid;
if ((int32_t) state->avail_out < 0)
@ -1106,8 +1104,7 @@ int isal_inflate(struct inflate_state *state)
state->avail_out -= copy_size;
state->next_out += copy_size;
if (ret == INVALID_LOOK_BACK_DISTANCE || ret == INVALID_BLOCK_HEADER
|| ret == INVALID_NON_COMPRESSED_BLOCK_LENGTH) {
if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK) {
/* Set total_out to not count data in tmp_out_buffer */
state->total_out -= state->tmp_out_valid - state->tmp_out_processed;
return ret;
@ -1139,15 +1136,15 @@ int isal_inflate(struct inflate_state *state)
if (state->block_state != ISAL_BLOCK_INPUT_DONE) {
/* Save decompression history in tmp_out buffer */
if (state->tmp_out_valid == state->tmp_out_processed
&& avail_out - state->avail_out >= ISAL_INFLATE_HIST_SIZE) {
&& avail_out - state->avail_out >= ISAL_DEF_HIST_SIZE) {
memcpy(state->tmp_out_buffer,
state->next_out - ISAL_INFLATE_HIST_SIZE,
ISAL_INFLATE_HIST_SIZE);
state->tmp_out_valid = ISAL_INFLATE_HIST_SIZE;
state->tmp_out_processed = ISAL_INFLATE_HIST_SIZE;
state->next_out - ISAL_DEF_HIST_SIZE,
ISAL_DEF_HIST_SIZE);
state->tmp_out_valid = ISAL_DEF_HIST_SIZE;
state->tmp_out_processed = ISAL_DEF_HIST_SIZE;
} else if (state->tmp_out_processed >= ISAL_INFLATE_HIST_SIZE) {
shift_size = state->tmp_out_valid - ISAL_INFLATE_HIST_SIZE;
} else if (state->tmp_out_processed >= ISAL_DEF_HIST_SIZE) {
shift_size = state->tmp_out_valid - ISAL_DEF_HIST_SIZE;
if (shift_size > state->tmp_out_processed)
shift_size = state->tmp_out_processed;
@ -1169,14 +1166,12 @@ int isal_inflate(struct inflate_state *state)
state->copy_overflow_length = 0;
}
if (ret == INVALID_LOOK_BACK_DISTANCE
|| ret == INVALID_BLOCK_HEADER
|| ret == INVALID_NON_COMPRESSED_BLOCK_LENGTH)
if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK)
return ret;
} else if (state->tmp_out_valid == state->tmp_out_processed)
state->block_state = ISAL_BLOCK_FINISH;
}
return DECOMPRESSION_FINISHED;
return ISAL_DECOMP_OK;
}

View File

@ -30,7 +30,7 @@
#include <stdio.h>
#include <assert.h>
#include "huff_codes.h"
#include "inflate.h"
#include "igzip_lib.h"
#include "test.h"
#if defined(ZLIB_9) || defined(ZLIB_1) || defined(ZLIB_COMPARE)

View File

@ -30,7 +30,7 @@
#include <stdint.h>
#include <stdio.h>
#include <zlib.h>
#include "inflate.h"
#include "igzip_lib.h"
#include "huff_codes.h"
/*Don't use file larger memory can support because compression and decompression
@ -163,29 +163,25 @@ int test(uint8_t * compressed_stream,
switch (ret) {
case 0:
break;
case END_OF_INPUT:
case ISAL_END_INPUT:
printf(" did not decompress all input\n");
return END_OF_INPUT;
return ISAL_END_INPUT;
break;
case INVALID_BLOCK_HEADER:
case ISAL_INVALID_BLOCK:
printf(" invalid header\n");
return INVALID_BLOCK_HEADER;
return ISAL_INVALID_BLOCK;
break;
case INVALID_SYMBOL:
case ISAL_INVALID_SYMBOL:
printf(" invalid symbol\n");
return INVALID_SYMBOL;
return ISAL_INVALID_SYMBOL;
break;
case OUT_BUFFER_OVERFLOW:
case ISAL_OUT_OVERFLOW:
printf(" out buffer overflow\n");
return OUT_BUFFER_OVERFLOW;
return ISAL_OUT_OVERFLOW;
break;
case INVALID_NON_COMPRESSED_BLOCK_LENGTH:
printf("Invalid length bits in non-compressed block\n");
return INVALID_NON_COMPRESSED_BLOCK_LENGTH;
break;
case INVALID_LOOK_BACK_DISTANCE:
case ISAL_INVALID_LOOKBACK:
printf("Invalid lookback distance");
return INVALID_LOOK_BACK_DISTANCE;
return ISAL_INVALID_LOOKBACK;
break;
default:
printf(" error\n");

View File

@ -54,7 +54,7 @@ int main(int argc, char *argv[])
struct isal_zstream stream;
unsigned char inbuf[IBUF_SIZE], zbuf[OBUF_SIZE];
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
printf("igzip_perf: \n");
fflush(0);
create_data(inbuf, TEST_LEN);

View File

@ -32,7 +32,6 @@
#include <string.h>
#include <assert.h>
#include "igzip_lib.h"
#include "inflate.h"
#include "crc_inflate.h"
#include <math.h>
@ -79,7 +78,6 @@ enum IGZIP_TEST_ERROR_CODES {
INFLATE_INVALID_BLOCK_HEADER,
INFLATE_INVALID_SYMBOL,
INFLATE_OUT_BUFFER_OVERFLOW,
INFLATE_INVALID_NON_COMPRESSED_BLOCK_LENGTH,
INFLATE_LEFTOVER_INPUT,
INFLATE_INCORRECT_OUTPUT_SIZE,
INFLATE_INVALID_LOOK_BACK_DISTANCE,
@ -223,9 +221,6 @@ void print_error(int error_code)
case INFLATE_OUT_BUFFER_OVERFLOW:
printf("error: output buffer overflow while decompressing data\n");
break;
case INFLATE_INVALID_NON_COMPRESSED_BLOCK_LENGTH:
printf("error: invalid length bits in non-compressed block\n");
break;
case INFLATE_GENERAL_ERROR:
printf("error: decompression failed\n");
break;
@ -544,22 +539,19 @@ int inflate_check(uint8_t * z_buf, int z_size, uint8_t * in_buf, int in_size)
switch (ret) {
case 0:
break;
case END_OF_INPUT:
case ISAL_END_INPUT:
return INFLATE_END_OF_INPUT;
break;
case INVALID_BLOCK_HEADER:
case ISAL_INVALID_BLOCK:
return INFLATE_INVALID_BLOCK_HEADER;
break;
case INVALID_SYMBOL:
case ISAL_INVALID_SYMBOL:
return INFLATE_INVALID_SYMBOL;
break;
case OUT_BUFFER_OVERFLOW:
case ISAL_OUT_OVERFLOW:
return INFLATE_OUT_BUFFER_OVERFLOW;
break;
case INVALID_NON_COMPRESSED_BLOCK_LENGTH:
return INFLATE_INVALID_NON_COMPRESSED_BLOCK_LENGTH;
break;
case INVALID_LOOK_BACK_DISTANCE:
case ISAL_INVALID_LOOKBACK:
return INFLATE_INVALID_LOOK_BACK_DISTANCE;
break;
case INFLATE_LEFTOVER_INPUT:
@ -1725,7 +1717,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);
#endif
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
printf("Test Seed : %d\n", TEST_SEED);
printf("Randoms : %d\n", RANDOMS);
srand(TEST_SEED);

View File

@ -45,14 +45,14 @@ void isal_deflate_body_stateless_base(struct isal_zstream *stream)
dist = (uint64_t) (stream->next_in - last_seen[hash]) & 0xFFFF;
last_seen[hash] = (uint64_t) stream->next_in;
if (dist - 1 < IGZIP_D - 1 && stream->next_in - dist >= start_in) { /* The -1 are to handle the case when dist = 0 */
if (dist - 1 < IGZIP_HIST_SIZE - 1 && stream->next_in - dist >= start_in) { /* The -1 are to handle the case when dist = 0 */
match_length =
compare258(stream->next_in - dist, stream->next_in,
end_in - stream->next_in);
if (match_length >= SHORTEST_MATCH) {
next_hash = stream->next_in;
#ifdef LIMIT_HASH_UPDATE
#ifdef ISAL_LIMIT_HASH_UPDATE
end = next_hash + 3;
#else
end = next_hash + match_length;
@ -99,7 +99,7 @@ void isal_deflate_body_stateless_base(struct isal_zstream *stream)
hash = compute_hash(literal) & HASH_MASK;
dist = (uint64_t) (stream->next_in - last_seen[hash]) & 0xFFFF;
if (dist - 1 < IGZIP_D - 1 && stream->next_in - dist >= start_in) {
if (dist - 1 < IGZIP_HIST_SIZE - 1 && stream->next_in - dist >= start_in) {
match_length =
compare258(stream->next_in - dist, stream->next_in,
end_in - stream->next_in);

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
}
printf("outfile=%s\n", argv[2]);
}
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
printf("igzip_file_perf: \n");
fflush(0);
/* Allocate space for entire input file and output

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
exit(0);
}
printf("igzip_sync_flush_example\nWindow Size: %d K\n", HIST_SIZE);
printf("igzip_sync_flush_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024);
fflush(0);
isal_deflate_init(&stream);

View File

@ -76,7 +76,7 @@ int main(int argc, char *argv[])
}
printf("outfile=%s\n", argv[2]);
}
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
printf("igzip_sync_flush_file_perf: \n");
fflush(0);
/* Allocate space for entire input file and

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
struct perf start, stop;
create_data(inbuf, TEST_LEN);
printf("Window Size: %d K\n", HIST_SIZE);
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
printf("igzip_sync_flush_perf: \n");
fflush(0);

View File

@ -252,7 +252,7 @@ skip1:
;; Init hash_table
PXOR vtmp0, vtmp0, vtmp0
mov rcx, (HASH_SIZE - V_LENGTH)
mov rcx, (IGZIP_HASH_SIZE - V_LENGTH)
init_hash_table:
MOVDQU [histogram + _hash_offset + 2 * rcx], vtmp0
MOVDQU [histogram + _hash_offset + 2 * (rcx + V_LENGTH / 2)], vtmp0

View File

@ -27,7 +27,7 @@
START_FIELDS ;; inflate huff code
;; name size align
FIELD _small_code_lookup_large, 2 * (1 << (DECODE_LOOKUP_SIZE_LARGE)), 2
FIELD _short_code_lookup_large, 2 * (1 << (ISAL_DECODE_LONG_BITS)), 2
FIELD _long_code_lookup_large, 2 * MAX_LONG_CODE_LARGE, 2
%assign _inflate_huff_code_large_size _FIELD_OFFSET
@ -40,7 +40,7 @@ FIELD _long_code_lookup_large, 2 * MAX_LONG_CODE_LARGE, 2
START_FIELDS ;; inflate huff code
;; name size align
FIELD _small_code_lookup_small, 2 * (1 << (DECODE_LOOKUP_SIZE_SMALL)), 2
FIELD _short_code_lookup_small, 2 * (1 << (ISAL_DECODE_SHORT_BITS)), 2
FIELD _long_code_lookup_small, 2 * MAX_LONG_CODE_SMALL, 2
%assign _inflate_huff_code_small_size _FIELD_OFFSET
@ -70,10 +70,10 @@ FIELD _copy_overflow_dist, 4, 4
%assign _inflate_state_size _FIELD_OFFSET
%assign _inflate_state_align _STRUCT_ALIGN
_lit_huff_code_small_code_lookup equ _lit_huff_code+_small_code_lookup_large
_lit_huff_code_short_code_lookup equ _lit_huff_code+_short_code_lookup_large
_lit_huff_code_long_code_lookup equ _lit_huff_code+_long_code_lookup_large
_dist_huff_code_small_code_lookup equ _dist_huff_code+_small_code_lookup_small
_dist_huff_code_short_code_lookup equ _dist_huff_code+_short_code_lookup_small
_dist_huff_code_long_code_lookup equ _dist_huff_code+_long_code_lookup_small
ISAL_BLOCK_NEW_HDR equ 0

View File

@ -28,19 +28,19 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%assign K 1024
%assign D HIST_SIZE * K ;; Amount of history
%assign D IGZIP_HIST_SIZE ;; Amount of history
%assign LA 18 * 16 ;; Max look-ahead, rounded up to 32 byte boundary
%assign BSIZE 2*HIST_SIZE*K + LA ;; Nominal buffer size
%assign BSIZE 2*IGZIP_HIST_SIZE + LA ;; Nominal buffer size
;; Constants for stateless compression
%define LAST_BYTES_COUNT 3 ;; Bytes to prevent reading out of array bounds
%define LA_STATELESS 258 ;; No round up since no data is copied to a buffer
%ifndef HASH_SIZE
%assign HASH_SIZE (8 * K)
%ifndef IGZIP_HASH_SIZE
%assign IGZIP_HASH_SIZE (8 * K)
%endif
%assign HASH_MASK (HASH_SIZE - 1)
%assign HASH_MASK (IGZIP_HASH_SIZE - 1)
%assign SHORTEST_MATCH 4

View File

@ -44,19 +44,19 @@ default rel
; l - use longer huffman table
; f - fix cache read
%ifndef HIST_SIZE
%define HIST_SIZE 32
%ifndef IGZIP_HIST_SIZE
%define IGZIP_HIST_SIZE (32 * 1024)
%endif
%if (HIST_SIZE > 32)
%undef HIST_SIZE
%define HIST_SIZE 32
%if (IGZIP_HIST_SIZE > (32 * 1024))
%undef IGZIP_HIST_SIZE
%define IGZIP_HIST_SIZE (32 * 1024)
%endif
%ifdef LONGER_HUFFTABLE
%if (HIST_SIZE > 8)
%undef HIST_SIZE
%define HIST_SIZE 8
%if (IGZIP_HIST_SIZE > 8 * 1024)
%undef IGZIP_HIST_SIZE
%define IGZIP_HIST_SIZE (8 * 1024)
%endif
%endif
@ -75,7 +75,7 @@ default rel
; (f) fix cache read problem
%define FIX_CACHE_READ
%define IGZIP_MAX_DEF_HDR_SIZE 328
%define ISAL_DEF_MAX_HDR_SIZE 328
%ifidn __OUTPUT_FORMAT__, elf64
%ifndef __NASM_VER__

View File

@ -33,8 +33,8 @@
/**
* @file igzip_lib.h
*
* @brief This file defines the igzip compression interface, a high performance
* deflate compression interface for storage applications.
* @brief This file defines the igzip compression and decompression interface, a
* high performance deflate compression interface for storage applications.
*
* Deflate is a widely used compression standard that can be used standalone, it
* also forms the basis of gzip and zlib compression formats. Igzip supports the
@ -53,22 +53,24 @@
* Igzip contians some behaviour configurable at compile time. These
* configureable options are:
*
* - HIST_SIZE - Defines the window size in 1K increments. The default value is
* 32, but 8 is also supported. Powers of 2 which are at most 32 may also work.
* - IGZIP_HIST_SIZE - Defines the window size. The default value is 32K (note K
* represents 1024), but 8K is also supported. Powers of 2 which are at most
* 32K may also work.
*
* - LONGER_HUFFTABLES - Defines whether to use a larger hufftables structure
* which may increase performance with smaller HIST_SIZE values. By default
* this optoin is not defined. This define sets HIST_SIZE to be 8 if HIST_SIZE
* > 8.
* which may increase performance with smaller IGZIP_HIST_SIZE values. By
* default this optoin is not defined. This define sets IGZIP_HIST_SIZE to be
* 8 if IGZIP_HIST_SIZE > 8K.
*
* - IGZIP_USE_GZIP_FORMAT - Defines whether the compression should add gzip
* header and trailer to compressed data. By default this option is not
* defined
*
* As an example, to compile gzip with an 8K window size and add the gzip
* header and trailer, in a terminal run @verbatim gmake D="-D HIST_SIZE=8 -D
* IGZIP_USE_GZIP_FORMAT" @endverbatim on Linux and FreeBSD, or with @verbatim
* nmake -f Makefile.nmake D="-D HIST_SIZE=8" @endverbatim on Windows.
* header and trailer, in a terminal run @verbatim gmake D="-D
* IGZIP_HIST_SIZE=8*1024 -D IGZIP_USE_GZIP_FORMAT" @endverbatim on Linux and
* FreeBSD, or with @verbatim nmake -f Makefile.nmake D="-D
* IGZIP_HIST_SIZE=8*1024" @endverbatim on Windows.
*
*/
#include <stdint.h>
@ -78,82 +80,59 @@
extern "C" {
#endif
// Options:dir
// m - reschedule mem reads
// e b - bitbuff style
// t s x - compare style
// h - limit hash updates
// l - use longer huffman table
// f - fix cache read
#ifndef HIST_SIZE
#define HIST_SIZE 32
#endif
#if (HIST_SIZE > 32)
#undef HIST_SIZE
#define HIST_SIZE 32
#endif
#ifdef LONGER_HUFFTABLE
#if (HIST_SIZE > 8)
#undef HIST_SIZE
#define HIST_SIZE 8
#endif
#endif
/* bit buffer types
* BITBUF8: (e) Always write 8 bytes of data
* BITBUFB: (b) Always write data
*/
#if !(defined(USE_BITBUFB) || defined(USE_BITBUF8) || defined(USE_BITBUF_ELSE))
# define USE_BITBUFB
#endif
/* compare types
* 1: ( ) original
* 2: (t) with CMOV
* 3: (s) with sttni
* 4: (x) with xmm / pmovbmsk
* 5: (y) with ymm / pmovbmsk (32-bytes at a time)
*/
# define LIMIT_HASH_UPDATE
/* (f) fix cache read problem */
#define FIX_CACHE_READ
/******************************************************************************/
/* Deflate Compression Standard Defines */
/******************************************************************************/
#define IGZIP_K 1024
#define IGZIP_D (HIST_SIZE * IGZIP_K) /* Amount of history */
#define IGZIP_LA (18 * 16) /* Max look-ahead, rounded up to 32 byte boundary */
#define BSIZE (2*IGZIP_D + IGZIP_LA) /* Nominal buffer size */
#define ISAL_DEF_MAX_HDR_SIZE 328
#define ISAL_DEF_MAX_CODE_LEN 15
#define ISAL_DEF_HIST_SIZE (32*IGZIP_K)
#ifndef HASH_SIZE
#define HASH_SIZE (8 * IGZIP_K)
#define ISAL_DEF_LIT_SYMBOLS 257
#define ISAL_DEF_LEN_SYMBOLS 29
#define ISAL_DEF_DIST_SYMBOLS 30
#define ISAL_DEF_LIT_LEN_SYMBOLS (ISAL_DEF_LIT_SYMBOLS + ISAL_DEF_LEN_SYMBOLS)
#define ISAL_LOOK_AHEAD (18 * 16) /* Max repeat length, rounded up to 32 byte boundary */
/******************************************************************************/
/* Deflate Implemenation Specific Defines */
/******************************************************************************/
/* Note IGZIP_HIST_SIZE must be a power of two */
#ifndef IGZIP_HIST_SIZE
#define IGZIP_HIST_SIZE ISAL_DEF_HIST_SIZE
#endif
#define HASH_MASK (HASH_SIZE - 1)
#define SHORTEST_MATCH 4
#define IGZIP_MAX_DEF_HDR_SIZE 328
#if (IGZIP_HIST_SIZE > ISAL_DEF_HIST_SIZE)
#undef IGZIP_HIST_SIZE
#define IGZIP_HIST_SIZE ISAL_DEF_HIST_SIZE
#endif
#ifdef LONGER_HUFFTABLE
enum {DIST_TABLE_SIZE = 8*1024};
/* DECODE_OFFSET is dist code index corresponding to DIST_TABLE_SIZE + 1 */
enum { DECODE_OFFSET = 26 };
#else
enum {DIST_TABLE_SIZE = 2};
/* DECODE_OFFSET is dist code index corresponding to DIST_TABLE_SIZE + 1 */
enum { DECODE_OFFSET = 0 };
#if (IGZIP_HIST_SIZE > 8 * IGZIP_K)
#undef IGZIP_HIST_SIZE
#define IGZIP_HIST_SIZE (8 * IGZIP_K)
#endif
#endif
enum {LEN_TABLE_SIZE = 256};
enum {LIT_TABLE_SIZE = 257};
#define IGZIP_LIT_LEN 286
#define IGZIP_DIST_LEN 30
#define ISAL_LIMIT_HASH_UPDATE
#ifndef IGZIP_HASH_SIZE
#define IGZIP_HASH_SIZE (8 * IGZIP_K)
#endif
#ifdef LONGER_HUFFTABLE
enum {IGZIP_DIST_TABLE_SIZE = 8*1024};
/* DECODE_OFFSET is dist code index corresponding to DIST_TABLE_SIZE + 1 */
enum { IGZIP_DECODE_OFFSET = 26 };
#else
enum {IGZIP_DIST_TABLE_SIZE = 2};
/* DECODE_OFFSET is dist code index corresponding to DIST_TABLE_SIZE + 1 */
enum { IGZIP_DECODE_OFFSET = 0 };
#endif
enum {IGZIP_LEN_TABLE_SIZE = 256};
enum {IGZIP_LIT_TABLE_SIZE = ISAL_DEF_LIT_SYMBOLS};
/* Flush Flags */
#define NO_FLUSH 0 /* Default */
@ -161,12 +140,12 @@ enum {LIT_TABLE_SIZE = 257};
#define FULL_FLUSH 2
#define FINISH_FLUSH 0 /* Deprecated */
/* Return values */
/* Compression Return values */
#define COMP_OK 0
#define INVALID_FLUSH -7
#define INVALID_PARAM -8
#define STATELESS_OVERFLOW -1
#define DEFLATE_HDR_LEN 3
/**
* @enum isal_zstate
* @brief Compression State please note ZSTATE_TRL only applies for GZIP compression
@ -196,12 +175,41 @@ enum isal_zstate_state {
};
/* Offset used to switch between TMP states and non-tmp states */
#define TMP_OFFSET_SIZE ZSTATE_TMP_HDR - ZSTATE_HDR
#define ZSTATE_TMP_OFFSET ZSTATE_TMP_HDR - ZSTATE_HDR
/******************************************************************************/
/* Inflate Implementation Specific Defines */
/******************************************************************************/
#define ISAL_DECODE_LONG_BITS 12
#define ISAL_DECODE_SHORT_BITS 10
/* Current state of decompression */
enum isal_block_state {
ISAL_BLOCK_NEW_HDR, /* Just starting a new block */
ISAL_BLOCK_HDR, /* In the middle of reading in a block header */
ISAL_BLOCK_TYPE0, /* Decoding a type 0 block */
ISAL_BLOCK_CODED, /* Decoding a huffman coded block */
ISAL_BLOCK_INPUT_DONE, /* Decompression of input is completed */
ISAL_BLOCK_FINISH /* Decompression of input is completed and all data has been flushed to output */
};
/* Inflate Return values */
#define ISAL_DECOMP_OK 0 /* No errors encountered while decompressing */
#define ISAL_END_INPUT 1 /* End of input reached */
#define ISAL_OUT_OVERFLOW 2 /* End of output reached */
#define ISAL_INVALID_BLOCK -1 /* Invalid deflate block found */
#define ISAL_INVALID_SYMBOL -2 /* Invalid deflate symbol found */
#define ISAL_INVALID_LOOKBACK -3 /* Invalid lookback distance found */
/******************************************************************************/
/* Compression structures */
/******************************************************************************/
/** @brief Holds histogram of deflate symbols*/
struct isal_huff_histogram {
uint64_t lit_len_histogram[IGZIP_LIT_LEN];
uint64_t dist_histogram[IGZIP_DIST_LEN];
uint16_t hash_table[HASH_SIZE];
uint64_t lit_len_histogram[ISAL_DEF_LIT_LEN_SYMBOLS]; //!< Histogram of Literal/Len symbols seen
uint64_t dist_histogram[ISAL_DEF_DIST_SYMBOLS]; //!< Histogram of Distance Symbols seen
uint16_t hash_table[IGZIP_HASH_SIZE]; //!< Tmp space used as a hash table
};
/** @brief Holds Bit Buffer information*/
@ -236,26 +244,23 @@ struct isal_zstate {
uint32_t has_eob_hdr; //!< keeps track of eob hdr (with BFINAL set)
uint32_t left_over; //!< keeps track of overflow bytes
DECLARE_ALIGNED(uint8_t buffer[BSIZE + 16], 32); //!< Internal buffer
DECLARE_ALIGNED(uint16_t head[HASH_SIZE], 16); //!< Hash array
DECLARE_ALIGNED(uint8_t buffer[2 * IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD], 32); //!< Internal buffer
DECLARE_ALIGNED(uint16_t head[IGZIP_HASH_SIZE], 16); //!< Hash array
};
/** @brief Holds the huffman tree used to huffman encode the input stream **/
struct isal_hufftables {
uint8_t deflate_hdr[IGZIP_MAX_DEF_HDR_SIZE]; //!< deflate huffman tree header
uint8_t deflate_hdr[ISAL_DEF_MAX_HDR_SIZE]; //!< deflate huffman tree header
uint32_t deflate_hdr_count; //!< Number of whole bytes in deflate_huff_hdr
uint32_t deflate_hdr_extra_bits; //!< Number of bits in the partial byte in header
uint32_t dist_table[DIST_TABLE_SIZE]; //!< bits 4:0 are the code length, bits 31:5 are the code
uint32_t len_table[LEN_TABLE_SIZE]; //!< bits 4:0 are the code length, bits 31:5 are the code
uint16_t lit_table[LIT_TABLE_SIZE]; //!< literal code
uint8_t lit_table_sizes[LIT_TABLE_SIZE]; //!< literal code length
uint16_t dcodes[30 - DECODE_OFFSET]; //!< distance code
uint8_t dcodes_sizes[30 - DECODE_OFFSET]; //!< distance code length
uint32_t dist_table[IGZIP_DIST_TABLE_SIZE]; //!< bits 4:0 are the code length, bits 31:5 are the code
uint32_t len_table[IGZIP_LEN_TABLE_SIZE]; //!< bits 4:0 are the code length, bits 31:5 are the code
uint16_t lit_table[IGZIP_LIT_TABLE_SIZE]; //!< literal code
uint8_t lit_table_sizes[IGZIP_LIT_TABLE_SIZE]; //!< literal code length
uint16_t dcodes[30 - IGZIP_DECODE_OFFSET]; //!< distance code
uint8_t dcodes_sizes[30 - IGZIP_DECODE_OFFSET]; //!< distance code length
};
@ -276,7 +281,93 @@ struct isal_zstream {
struct isal_zstate internal_state; //!< Internal state for this stream
};
/******************************************************************************/
/* Inflate structures */
/******************************************************************************/
/*
* Inflate_huff_code data structures are used to store a Huffman code for fast
* lookup. It works by performing a lookup in small_code_lookup that hopefully
* yields the correct symbol. Otherwise a lookup into long_code_lookup is
* performed to find the correct symbol. The details of how this works follows:
*
* Let i be some index into small_code_lookup and let e be the associated
* element. Bit 15 in e is a flag. If bit 15 is not set, then index i contains
* a Huffman code for a symbol which has length at most DECODE_LOOKUP_SIZE. Bits
* 0 through 8 are the symbol associated with that code and bits 9 through 12 of
* e represent the number of bits in the code. If bit 15 is set, the i
* corresponds to the first DECODE_LOOKUP_SIZE bits of a Huffman code which has
* length longer than DECODE_LOOKUP_SIZE. In this case, bits 0 through 8
* represent an offset into long_code_lookup table and bits 9 through 12
* represent the maximum length of a Huffman code starting with the bits in the
* index i. The offset into long_code_lookup is for an array associated with all
* codes which start with the bits in i.
*
* The elements of long_code_lookup are in the same format as small_code_lookup,
* except bit 15 is never set. Let i be a number made up of DECODE_LOOKUP_SIZE
* bits. Then all Huffman codes which start with DECODE_LOOKUP_SIZE bits are
* stored in an array starting at index h in long_code_lookup. This index h is
* stored in bits 0 through 9 at index i in small_code_lookup. The index j is an
* index of this array if the number of bits contained in j and i is the number
* of bits in the longest huff_code starting with the bits of i. The symbol
* stored at index j is the symbol whose huffcode can be found in (j <<
* DECODE_LOOKUP_SIZE) | i. Note these arrays will be stored sorted in order of
* maximum Huffman code length.
*
* The following are explanations for sizes of the tables:
*
* Since small_code_lookup is a lookup on DECODE_LOOKUP_SIZE bits, it must have
* size 2^DECODE_LOOKUP_SIZE.
*
* Since deflate Huffman are stored such that the code size and the code value
* form an increasing function, At most 2^(15 - DECODE_LOOKUP_SIZE) - 1 elements
* of long_code_lookup duplicate an existing symbol. Since there are at most 285
* - DECODE_LOOKUP_SIZE possible symbols contained in long_code lookup. Rounding
* this to the nearest 16 byte boundary yields the size of long_code_lookup of
* 288 + 2^(15 - DECODE_LOOKUP_SIZE).
*
* Note that DECODE_LOOKUP_SIZE can be any length even though the offset in
* small_lookup_code is 9 bits long because the increasing relationship between
* code length and code value forces the maximum offset to be less than 288.
*/
/* Large lookup table for decoding huffman codes */
struct inflate_huff_code_large {
uint16_t short_code_lookup[1 << (ISAL_DECODE_LONG_BITS)];
uint16_t long_code_lookup[288 + (1 << (15 - ISAL_DECODE_LONG_BITS))];
};
/* Small lookup table for decoding huffman codes */
struct inflate_huff_code_small {
uint16_t short_code_lookup[1 << (ISAL_DECODE_SHORT_BITS)];
uint16_t long_code_lookup[32 + (1 << (15 - ISAL_DECODE_SHORT_BITS))];
};
/** @brief Holds decompression state information*/
struct inflate_state {
uint8_t *next_out; //!< Next output Byte
uint32_t avail_out; //!< Number of bytes available at next_out
uint32_t total_out; //!< Total bytes written out so far
uint8_t *next_in; //!< Next input byte
uint64_t read_in; //!< Bits buffered to handle unaligned streams
uint32_t avail_in; //!< Number of bytes available at next_in
int32_t read_in_length; //!< Bits in read_in
struct inflate_huff_code_large lit_huff_code; //!< Structure for decoding lit/len symbols
struct inflate_huff_code_small dist_huff_code; //!< Structure for decoding dist symbols
enum isal_block_state block_state; //!< Current decompression state
uint32_t bfinal; //!< Flag identifying final block
int32_t type0_block_len; //!< Length left to read of type 0 block when outbuffer overflow occured
int32_t copy_overflow_length; //!< Length left to copy when outbuffer overflow occured
int32_t copy_overflow_distance; //!< Lookback distance when outbuffer overlow occured
int32_t tmp_in_size; //!< Number of bytes in tmp_in_buffer
int32_t tmp_out_valid; //!< Number of bytes in tmp_out_buffer
int32_t tmp_out_processed; //!< Number of bytes processed in tmp_out_buffer
uint8_t tmp_in_buffer[ISAL_DEF_MAX_HDR_SIZE]; //!< Temporary buffer containing data from the input stream
uint8_t tmp_out_buffer[2 * ISAL_DEF_HIST_SIZE + ISAL_LOOK_AHEAD]; //!< Temporary buffer containing data from the output stream
};
/******************************************************************************/
/* Compression functions */
/******************************************************************************/
/**
* @brief Updates histograms to include the symbols found in the input
* stream. Since this function only updates the histograms, it can be called on
@ -386,6 +477,58 @@ int isal_deflate(struct isal_zstream *stream);
int isal_deflate_stateless(struct isal_zstream *stream);
/******************************************************************************/
/* Inflate functions */
/******************************************************************************/
/**
* @brief Initialize decompression state data structure
*
* @param state Structure holding state information on the compression streams.
* @returns none
*/
void isal_inflate_init(struct inflate_state *state);
/**
* @brief Fast data (deflate) decompression for storage applications.
*
* On entry to isal_inflate(), next_in points to an input buffer and avail_in
* indicates the length of that buffer. Similarly next_out points to an empty
* output buffer and avail_out indicates the size of that buffer.
*
* The fields total_in and total_out start at 0 and are updated by
* isal_inflate(). These reflect the total number of bytes read or written so far.
*
* The call to isal_inflate() will take data from the input buffer (updating
* next_in, avail_in and write a decompressed stream to the output buffer
* (updating next_out and avail_out). The function returns when the input buffer
* is empty, the output buffer is full or invalid data is found. The current
* state of the decompression on exit can be read from state->block-state.
*
* @param state Structure holding state information on the compression streams.
* @return DECOMP_OK (if everything is ok),
* INVALID_BLOCK,
* INVALID_SYMBOL,
* INVALID_LOOKBACK.
*/
int isal_inflate(struct inflate_state *state);
/**
* @brief Fast data (deflate) stateless decompression for storage applications.
*
* Stateless (one shot) compression routine with a similar interface to
* isal_inflate() but operates on entire input buffer at one time. Parameter
* avail_out must be large enough to fit the entire decompressed output.
*
* @param state Structure holding state information on the compression streams.
* @return ISAL_DECOMP_OK (if everything is ok),
* ISAL_END_INPUT (if all input was decompressed),
* ISAL_OUT_OVERFLOW (if output buffer ran out of space),
* ISAL_INVALID_BLOCK,
* ISAL_INVALID_SYMBOL,
* ISAL_INVALID_LOOKBACK.
*/
int isal_inflate_stateless(struct inflate_state *state);
#ifdef __cplusplus
}
#endif

View File

@ -1,121 +0,0 @@
#ifndef INFLATE_H
#define INFLATE_H
#include <stdint.h>
#define DECOMPRESSION_FINISHED 0
#define END_OF_INPUT 1
#define OUT_BUFFER_OVERFLOW 2
#define INVALID_BLOCK_HEADER 3
#define INVALID_SYMBOL 4
#define INVALID_NON_COMPRESSED_BLOCK_LENGTH 5
#define INVALID_LOOK_BACK_DISTANCE 6
#define DEFLATE_CODE_MAX_LENGTH 15
#define DECODE_LOOKUP_SIZE_LARGE 12
#define DECODE_LOOKUP_SIZE_SMALL 10
#define ISAL_INFLATE_HIST_SIZE (32*1024)
#define ISAL_INFLATE_SLOP 17*16
#define ISAL_INFLATE_MAX_HDR_SIZE 360
enum isal_block_state {
ISAL_BLOCK_NEW_HDR, /* Just starting a new block */
ISAL_BLOCK_HDR, /* In the middle of reading in a block header */
ISAL_BLOCK_TYPE0, /* Decoding a type 0 block */
ISAL_BLOCK_CODED, /* Decoding a huffman coded block */
ISAL_BLOCK_INPUT_DONE, /* Decompression of input is completed */
ISAL_BLOCK_FINISH /* Decompression of input is completed and all data has been flushed to output */
};
/*
* Data structure used to store a Huffman code for fast lookup. It works by
* performing a lookup in small_code_lookup that hopefully yields the correct
* symbol. Otherwise a lookup into long_code_lookup is performed to find the
* correct symbol. The details of how this works follows:
*
* Let i be some index into small_code_lookup and let e be the associated
* element. Bit 15 in e is a flag. If bit 15 is not set, then index i contains
* a Huffman code for a symbol which has length at most DECODE_LOOKUP_SIZE. Bits
* 0 through 8 are the symbol associated with that code and bits 9 through 12 of
* e represent the number of bits in the code. If bit 15 is set, the i
* corresponds to the first DECODE_LOOKUP_SIZE bits of a Huffman code which has
* length longer than DECODE_LOOKUP_SIZE. In this case, bits 0 through 8
* represent an offset into long_code_lookup table and bits 9 through 12
* represent the maximum length of a Huffman code starting with the bits in the
* index i. The offset into long_code_lookup is for an array associated with all
* codes which start with the bits in i.
*
* The elements of long_code_lookup are in the same format as small_code_lookup,
* except bit 15 is never set. Let i be a number made up of DECODE_LOOKUP_SIZE
* bits. Then all Huffman codes which start with DECODE_LOOKUP_SIZE bits are
* stored in an array starting at index h in long_code_lookup. This index h is
* stored in bits 0 through 9 at index i in small_code_lookup. The index j is an
* index of this array if the number of bits contained in j and i is the number
* of bits in the longest huff_code starting with the bits of i. The symbol
* stored at index j is the symbol whose huffcode can be found in (j <<
* DECODE_LOOKUP_SIZE) | i. Note these arrays will be stored sorted in order of
* maximum Huffman code length.
*
* The following are explanations for sizes of the tables:
*
* Since small_code_lookup is a lookup on DECODE_LOOKUP_SIZE bits, it must have
* size 2^DECODE_LOOKUP_SIZE.
*
* Since deflate Huffman are stored such that the code size and the code value
* form an increasing function, At most 2^(15 - DECODE_LOOKUP_SIZE) - 1 elements
* of long_code_lookup duplicate an existing symbol. Since there are at most 285
* - DECODE_LOOKUP_SIZE possible symbols contained in long_code lookup. Rounding
* this to the nearest 16 byte boundary yields the size of long_code_lookup of
* 288 + 2^(15 - DECODE_LOOKUP_SIZE).
*
* Note that DECODE_LOOKUP_SIZE can be any length even though the offset in
* small_lookup_code is 9 bits long because the increasing relationship between
* code length and code value forces the maximum offset to be less than 288.
*/
struct inflate_huff_code_large {
uint16_t short_code_lookup[1 << (DECODE_LOOKUP_SIZE_LARGE)];
uint16_t long_code_lookup[288 + (1 << (15 - DECODE_LOOKUP_SIZE_LARGE))];
};
struct inflate_huff_code_small {
uint16_t short_code_lookup[1 << (DECODE_LOOKUP_SIZE_SMALL)];
uint16_t long_code_lookup[32 + (1 << (15 - DECODE_LOOKUP_SIZE_SMALL))];
};
/* Structure contained current state of decompression of data */
struct inflate_state {
uint8_t *next_out;
uint32_t avail_out;
uint32_t total_out;
uint8_t *next_in;
uint64_t read_in;
uint32_t avail_in;
int32_t read_in_length;
struct inflate_huff_code_large lit_huff_code;
struct inflate_huff_code_small dist_huff_code;
enum isal_block_state block_state;
uint32_t bfinal;
int32_t type0_block_len;
int32_t copy_overflow_length;
int32_t copy_overflow_distance;
int32_t tmp_in_size;
int32_t tmp_out_valid;
int32_t tmp_out_processed;
uint8_t tmp_in_buffer[ISAL_INFLATE_MAX_HDR_SIZE];
uint8_t tmp_out_buffer[2 * ISAL_INFLATE_HIST_SIZE + ISAL_INFLATE_SLOP];
};
/* Initialize a struct inflate_state for deflate compressed input data at in_stream and to output
* data into out_stream */
void isal_inflate_init(struct inflate_state *state);
/* Decompress a deflate data. This function assumes a call to igzip_inflate_init
* has been made to set up the state structure to allow for decompression.*/
int isal_inflate_stateless(struct inflate_state *state);
/* Decompress a deflate data. This function assumes a call to igzip_inflate_init
* has been made to set up the state structure to allow for decompression.*/
int isal_inflate(struct inflate_state *state);
#endif