igzip: Make inline functions in igzip_inflate.c static
Make inline functions in igzip_inflate.c static to fix compiling issue on Mac. Change-Id: Id4fdc0b8fe9ea9655bc3368bade579aebc8c2a72 Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
parent
88f95d8594
commit
e2b0640fd9
@ -40,143 +40,6 @@
|
||||
# define RUN_MEM_SIZE 2000000000
|
||||
#endif
|
||||
|
||||
extern uint64_t inflate_in_read_bits(struct inflate_state *, uint8_t);
|
||||
extern int read_header(struct inflate_state *);
|
||||
extern uint16_t decode_next_large(struct inflate_state *, struct inflate_huff_code_large *);
|
||||
extern uint16_t decode_next_small(struct inflate_state *, struct inflate_huff_code_small *);
|
||||
|
||||
/* Inflates and fills a histogram of lit, len, and dist codes seen in non-type 0 blocks.*/
|
||||
int isal_inflate_hist(struct inflate_state *state, struct isal_huff_histogram *histogram)
|
||||
{
|
||||
/* The following tables are based on the tables in the deflate standard,
|
||||
* RFC 1951 page 11. */
|
||||
const uint16_t len_start[29] = {
|
||||
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
|
||||
0x0b, 0x0d, 0x0f, 0x11, 0x13, 0x17, 0x1b, 0x1f,
|
||||
0x23, 0x2b, 0x33, 0x3b, 0x43, 0x53, 0x63, 0x73,
|
||||
0x83, 0xa3, 0xc3, 0xe3, 0x102
|
||||
};
|
||||
const uint8_t len_extra_bit_count[29] = {
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x1, 0x1, 0x1, 0x1, 0x2, 0x2, 0x2, 0x2,
|
||||
0x3, 0x3, 0x3, 0x3, 0x4, 0x4, 0x4, 0x4,
|
||||
0x5, 0x5, 0x5, 0x5, 0x0
|
||||
};
|
||||
const uint32_t dist_start[30] = {
|
||||
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
|
||||
0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
|
||||
0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
|
||||
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001
|
||||
};
|
||||
const uint8_t dist_extra_bit_count[30] = {
|
||||
0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x2, 0x2,
|
||||
0x3, 0x3, 0x4, 0x4, 0x5, 0x5, 0x6, 0x6,
|
||||
0x7, 0x7, 0x8, 0x8, 0x9, 0x9, 0xa, 0xa,
|
||||
0xb, 0xb, 0xc, 0xc, 0xd, 0xd
|
||||
};
|
||||
|
||||
uint16_t next_lit, len, nlen;
|
||||
uint8_t next_dist;
|
||||
uint32_t repeat_length;
|
||||
uint32_t look_back_dist;
|
||||
uint32_t tmp;
|
||||
|
||||
memset(histogram, 0, sizeof(struct isal_huff_histogram));
|
||||
while (state->block_state != ISAL_BLOCK_INPUT_DONE) {
|
||||
if (state->block_state == ISAL_BLOCK_NEW_HDR) {
|
||||
tmp = read_header(state);
|
||||
|
||||
if (tmp)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
if (state->block_state == ISAL_BLOCK_TYPE0) {
|
||||
/* If the block is uncompressed, update state data accordingly */
|
||||
if (state->avail_in < 4)
|
||||
return ISAL_END_INPUT;
|
||||
|
||||
len = *(uint16_t *) state->next_in;
|
||||
state->next_in += 2;
|
||||
nlen = *(uint16_t *) state->next_in;
|
||||
state->next_in += 2;
|
||||
|
||||
/* Check if len and nlen match */
|
||||
if (len != (~nlen & 0xffff))
|
||||
return ISAL_INVALID_BLOCK;
|
||||
|
||||
if (state->avail_in < len)
|
||||
len = state->avail_in;
|
||||
else
|
||||
state->block_state = ISAL_BLOCK_NEW_HDR;
|
||||
|
||||
state->total_out += len;
|
||||
state->next_in += len;
|
||||
state->avail_in -= len + 4;
|
||||
|
||||
if (state->avail_in == 0 && state->block_state == 0)
|
||||
return ISAL_END_INPUT;
|
||||
|
||||
} else {
|
||||
/* Else decode a huffman encoded block */
|
||||
while (state->block_state == ISAL_BLOCK_CODED) {
|
||||
/* While not at the end of block, decode the next
|
||||
* symbol */
|
||||
next_lit = decode_next_large(state, &state->lit_huff_code);
|
||||
|
||||
histogram->lit_len_histogram[next_lit] += 1;
|
||||
|
||||
if (state->read_in_length < 0)
|
||||
return ISAL_END_INPUT;
|
||||
|
||||
if (next_lit < 256)
|
||||
/* Next symbol is a literal */
|
||||
state->total_out++;
|
||||
|
||||
else if (next_lit == 256)
|
||||
/* Next symbol is end of block */
|
||||
state->block_state = ISAL_BLOCK_NEW_HDR;
|
||||
|
||||
else if (next_lit < 286) {
|
||||
/* Next symbol is a repeat length followed by a
|
||||
lookback distance */
|
||||
repeat_length =
|
||||
len_start[next_lit - 257] +
|
||||
inflate_in_read_bits(state,
|
||||
len_extra_bit_count[next_lit -
|
||||
257]);
|
||||
|
||||
next_dist = decode_next_small(state,
|
||||
&state->dist_huff_code);
|
||||
|
||||
histogram->dist_histogram[next_dist] += 1;
|
||||
|
||||
look_back_dist = dist_start[next_dist] +
|
||||
inflate_in_read_bits(state,
|
||||
dist_extra_bit_count
|
||||
[next_dist]);
|
||||
|
||||
if (state->read_in_length < 0)
|
||||
return ISAL_END_INPUT;
|
||||
|
||||
if (look_back_dist > state->total_out)
|
||||
return ISAL_INVALID_LOOKBACK;
|
||||
|
||||
state->total_out += repeat_length;
|
||||
|
||||
} else
|
||||
return ISAL_INVALID_SYMBOL;
|
||||
}
|
||||
}
|
||||
|
||||
if (state->bfinal != 0 && state->block_state == ISAL_BLOCK_NEW_HDR)
|
||||
state->block_state = ISAL_BLOCK_INPUT_DONE;
|
||||
}
|
||||
state->next_in -= state->read_in_length / 8;
|
||||
state->avail_in += state->read_in_length / 8;
|
||||
|
||||
return ISAL_DECOMP_OK;
|
||||
}
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
@ -212,61 +75,12 @@ void print_histogram(struct isal_huff_histogram *histogram)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_diff_histogram(struct isal_huff_histogram *histogram1,
|
||||
struct isal_huff_histogram *histogram2)
|
||||
{
|
||||
int i;
|
||||
double relative_error;
|
||||
printf("Lit Len histogram relative error");
|
||||
for (i = 0; i < ISAL_DEF_LIT_LEN_SYMBOLS; i++) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(", ");
|
||||
|
||||
if (histogram1->lit_len_histogram[i] == histogram2->lit_len_histogram[i]) {
|
||||
printf(" % 4.0f %%", 0.0);
|
||||
} else {
|
||||
relative_error =
|
||||
abs(histogram1->lit_len_histogram[i] -
|
||||
histogram2->lit_len_histogram[i]);
|
||||
relative_error = relative_error / histogram1->lit_len_histogram[i];
|
||||
relative_error = 100.0 * relative_error;
|
||||
printf("~% 4.0f %%", relative_error);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Dist histogram relative error");
|
||||
for (i = 0; i < ISAL_DEF_DIST_SYMBOLS; i++) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(", ");
|
||||
|
||||
if (histogram1->dist_histogram[i] == histogram2->dist_histogram[i]) {
|
||||
printf(" % 4.0f %%", 0.0);
|
||||
} else {
|
||||
relative_error =
|
||||
abs(histogram1->dist_histogram[i] - histogram2->dist_histogram[i]);
|
||||
relative_error = relative_error / histogram1->dist_histogram[i];
|
||||
relative_error = 100.0 * relative_error;
|
||||
printf("~% 4.0f %%", relative_error);
|
||||
}
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in;
|
||||
unsigned char *inbuf, *outbuf;
|
||||
int i, infile_size, outbuf_size, iterations, avail_in;
|
||||
struct isal_huff_histogram histogram1, histogram2;
|
||||
struct isal_hufftables hufftables_custom;
|
||||
struct isal_zstream stream;
|
||||
struct inflate_state gstream;
|
||||
|
||||
memset(&histogram1, 0, sizeof(histogram1));
|
||||
memset(&histogram2, 0, sizeof(histogram2));
|
||||
@ -326,30 +140,6 @@ int main(int argc, char *argv[])
|
||||
printf("igzip_file: ");
|
||||
perf_print(stop, start, (long long)infile_size * i);
|
||||
|
||||
memset(&histogram1, 0, sizeof(histogram1));
|
||||
|
||||
isal_update_histogram(inbuf, infile_size, &histogram1);
|
||||
|
||||
isal_create_hufftables(&hufftables_custom, &histogram1);
|
||||
|
||||
isal_deflate_init(&stream);
|
||||
stream.end_of_stream = 1; /* Do the entire file at once */
|
||||
stream.flush = NO_FLUSH;
|
||||
stream.next_in = inbuf;
|
||||
stream.avail_in = infile_size;
|
||||
stream.next_out = outbuf;
|
||||
stream.avail_out = outbuf_size;
|
||||
stream.hufftables = &hufftables_custom;
|
||||
isal_deflate_stateless(&stream);
|
||||
|
||||
isal_inflate_init(&gstream);
|
||||
gstream.next_in = outbuf;
|
||||
gstream.avail_in = outbuf_size;
|
||||
isal_inflate_hist(&gstream, &histogram2);
|
||||
|
||||
printf("Histogram Error \n");
|
||||
print_diff_histogram(&histogram1, &histogram2);
|
||||
|
||||
fclose(in);
|
||||
fflush(0);
|
||||
return 0;
|
||||
|
@ -62,7 +62,7 @@ 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. */
|
||||
void inline byte_copy(uint8_t * dest, uint64_t lookback_distance, int repeat_length)
|
||||
static void inline byte_copy(uint8_t * dest, uint64_t lookback_distance, int repeat_length)
|
||||
{
|
||||
uint8_t *src = dest - lookback_distance;
|
||||
|
||||
@ -73,7 +73,7 @@ void inline byte_copy(uint8_t * dest, uint64_t lookback_distance, int repeat_len
|
||||
/*
|
||||
* Returns integer with first length bits reversed and all higher bits zeroed
|
||||
*/
|
||||
uint16_t inline bit_reverse2(uint16_t bits, uint8_t length)
|
||||
static uint16_t inline bit_reverse2(uint16_t bits, uint8_t length)
|
||||
{
|
||||
bits = ((bits >> 1) & 0x55555555) | ((bits & 0x55555555) << 1); // swap bits
|
||||
bits = ((bits >> 2) & 0x33333333) | ((bits & 0x33333333) << 2); // swap pairs
|
||||
@ -83,7 +83,7 @@ uint16_t inline bit_reverse2(uint16_t bits, uint8_t length)
|
||||
}
|
||||
|
||||
/* Load data from the in_stream into a buffer to allow for handling unaligned data*/
|
||||
void inline inflate_in_load(struct inflate_state *state, int min_required)
|
||||
static void inline inflate_in_load(struct inflate_state *state, int min_required)
|
||||
{
|
||||
uint64_t temp = 0;
|
||||
uint8_t new_bytes;
|
||||
@ -117,8 +117,7 @@ void inline inflate_in_load(struct inflate_state *state, int min_required)
|
||||
|
||||
/* Returns the next bit_count bits from the in stream and shifts the stream over
|
||||
* by bit-count bits */
|
||||
uint64_t inflate_in_read_bits(struct inflate_state *state, uint8_t bit_count);
|
||||
uint64_t inline inflate_in_read_bits(struct inflate_state *state, uint8_t bit_count)
|
||||
static uint64_t inline inflate_in_read_bits(struct inflate_state *state, uint8_t bit_count)
|
||||
{
|
||||
uint64_t ret;
|
||||
assert(bit_count < 57);
|
||||
@ -137,9 +136,9 @@ uint64_t inline inflate_in_read_bits(struct inflate_state *state, uint8_t bit_co
|
||||
/* Sets result to the inflate_huff_code corresponding to the huffcode defined by
|
||||
* the lengths in huff_code_table,where count is a histogram of the appearance
|
||||
* of each code length */
|
||||
void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
|
||||
struct huff_code *huff_code_table, int table_length,
|
||||
uint16_t * count)
|
||||
static void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
|
||||
struct huff_code *huff_code_table,
|
||||
int table_length, uint16_t * count)
|
||||
{
|
||||
int i, j, k;
|
||||
uint16_t code = 0;
|
||||
@ -277,9 +276,9 @@ void inline make_inflate_huff_code_large(struct inflate_huff_code_large *result,
|
||||
}
|
||||
}
|
||||
|
||||
void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
|
||||
struct huff_code *huff_code_table, int table_length,
|
||||
uint16_t * count)
|
||||
static void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
|
||||
struct huff_code *huff_code_table,
|
||||
int table_length, uint16_t * count)
|
||||
{
|
||||
int i, j, k;
|
||||
uint16_t code = 0;
|
||||
@ -419,7 +418,7 @@ void inline make_inflate_huff_code_small(struct inflate_huff_code_small *result,
|
||||
|
||||
/* Sets the inflate_huff_codes in state to be the huffcodes corresponding to the
|
||||
* deflate static header */
|
||||
int inline setup_static_header(struct inflate_state *state)
|
||||
static int inline setup_static_header(struct inflate_state *state)
|
||||
{
|
||||
/* This could be turned into a memcpy of this functions output for
|
||||
* higher speed, but then DECODE_LOOKUP_SIZE couldn't be changed without
|
||||
@ -466,10 +465,8 @@ int inline setup_static_header(struct inflate_state *state)
|
||||
|
||||
/* Decodes the next symbol symbol in in_buffer using the huff code defined by
|
||||
* huff_code */
|
||||
uint16_t decode_next_large(struct inflate_state * state,
|
||||
struct inflate_huff_code_large * huff_code);
|
||||
uint16_t inline decode_next_large(struct inflate_state *state,
|
||||
struct inflate_huff_code_large *huff_code)
|
||||
static uint16_t inline decode_next_large(struct inflate_state *state,
|
||||
struct inflate_huff_code_large *huff_code)
|
||||
{
|
||||
uint16_t next_bits;
|
||||
uint16_t next_sym;
|
||||
@ -515,10 +512,8 @@ uint16_t inline decode_next_large(struct inflate_state *state,
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t decode_next_small(struct inflate_state * state,
|
||||
struct inflate_huff_code_small * huff_code);
|
||||
uint16_t inline decode_next_small(struct inflate_state *state,
|
||||
struct inflate_huff_code_small *huff_code)
|
||||
static uint16_t inline decode_next_small(struct inflate_state *state,
|
||||
struct inflate_huff_code_small *huff_code)
|
||||
{
|
||||
uint16_t next_bits;
|
||||
uint16_t next_sym;
|
||||
@ -566,7 +561,7 @@ uint16_t inline decode_next_small(struct inflate_state *state,
|
||||
|
||||
/* Reads data from the in_buffer and sets the huff code corresponding to that
|
||||
* data */
|
||||
int inline setup_dynamic_header(struct inflate_state *state)
|
||||
static int inline setup_dynamic_header(struct inflate_state *state)
|
||||
{
|
||||
int i, j;
|
||||
struct huff_code code_huff[CODE_LEN_CODES];
|
||||
@ -824,7 +819,7 @@ int read_header_stateful(struct inflate_state *state)
|
||||
|
||||
}
|
||||
|
||||
int inline decode_literal_block(struct inflate_state *state)
|
||||
static int inline decode_literal_block(struct inflate_state *state)
|
||||
{
|
||||
uint32_t len = state->type0_block_len;
|
||||
/* If the block is uncompressed, perform a memcopy while
|
||||
|
Loading…
Reference in New Issue
Block a user