igzip: reformat using new code style

Signed-off-by: Marcel Cornu <marcel.d.cornu@intel.com>
This commit is contained in:
Marcel Cornu 2024-04-19 17:09:21 +01:00 committed by Pablo de Lara
parent 9d99f8215d
commit 55fbfabfc6
39 changed files with 20000 additions and 22325 deletions

View File

@ -38,7 +38,6 @@ DEFINE_INTERFACE_DISPATCHER(isal_adler32)
return PROVIDER_INFO(adler32_neon);
#endif
return PROVIDER_BASIC(adler32);
}
DEFINE_INTERFACE_DISPATCHER(isal_deflate_body)
@ -53,7 +52,6 @@ DEFINE_INTERFACE_DISPATCHER(isal_deflate_body)
return PROVIDER_INFO(isal_deflate_body_aarch64);
#endif
return PROVIDER_BASIC(isal_deflate_body);
}
DEFINE_INTERFACE_DISPATCHER(isal_deflate_finish)
@ -67,7 +65,6 @@ DEFINE_INTERFACE_DISPATCHER(isal_deflate_finish)
return PROVIDER_INFO(isal_deflate_finish_aarch64);
#endif
return PROVIDER_BASIC(isal_deflate_finish);
}
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_body_lvl1)
@ -148,10 +145,7 @@ DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_finish_lvl3)
return PROVIDER_BASIC(isal_deflate_icf_finish_hash_map);
}
DEFINE_INTERFACE_DISPATCHER(set_long_icf_fg)
{
return PROVIDER_INFO(set_long_icf_fg_aarch64);
}
DEFINE_INTERFACE_DISPATCHER(set_long_icf_fg) { return PROVIDER_INFO(set_long_icf_fg_aarch64); }
DEFINE_INTERFACE_DISPATCHER(encode_deflate_icf)
{

View File

@ -30,7 +30,8 @@
#include <stdint.h>
#include "igzip_checksums.h"
uint32_t adler32_base(uint32_t adler32, uint8_t * start, uint32_t length)
uint32_t
adler32_base(uint32_t adler32, uint8_t *start, uint32_t length)
{
uint8_t *end, *next = start;
uint64_t A, B;

View File

@ -35,24 +35,25 @@
#include "test.h"
#ifndef GT_L3_CACHE
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
#define GT_L3_CACHE 32 * 1024 * 1024 /* some number > last level cache */
#endif
#if !defined(COLD_TEST) && !defined(TEST_CUSTOM)
// Cached test, loop many times over small dataset
# define TEST_LEN 8*1024
# define TEST_TYPE_STR "_warm"
#elif defined (COLD_TEST)
#define TEST_LEN 8 * 1024
#define TEST_TYPE_STR "_warm"
#elif defined(COLD_TEST)
// Uncached test. Pull from large mem base.
# define TEST_LEN (2 * GT_L3_CACHE)
# define TEST_TYPE_STR "_cold"
#define TEST_LEN (2 * GT_L3_CACHE)
#define TEST_TYPE_STR "_cold"
#endif
#ifndef TEST_SEED
#define TEST_SEED 0x1234
#endif
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
void *buf;
uint32_t checksum = 0;
@ -68,7 +69,7 @@ int main(int argc, char *argv[])
BENCHMARK(&start, BENCHMARK_TIME, checksum |= isal_adler32(TEST_SEED, buf, TEST_LEN));
printf("adler32" TEST_TYPE_STR ": ");
perf_print(start, (long long)TEST_LEN);
perf_print(start, (long long) TEST_LEN);
return 0;
}

View File

@ -41,40 +41,47 @@
* state that is possible at the exit of write_bits */
#define MAX_BITBUF_BIT_WRITE 56
static inline void init(struct BitBuf2 *me)
static inline void
init(struct BitBuf2 *me)
{
me->m_bits = 0;
me->m_bit_count = 0;
}
static inline void set_buf(struct BitBuf2 *me, unsigned char *buf, unsigned int len)
static inline void
set_buf(struct BitBuf2 *me, unsigned char *buf, unsigned int len)
{
unsigned int slop = 8;
me->m_out_buf = me->m_out_start = buf;
me->m_out_end = buf + len - slop;
}
static inline int is_full(struct BitBuf2 *me)
static inline int
is_full(struct BitBuf2 *me)
{
return (me->m_out_buf > me->m_out_end);
}
static inline uint8_t *buffer_ptr(struct BitBuf2 *me)
static inline uint8_t *
buffer_ptr(struct BitBuf2 *me)
{
return me->m_out_buf;
}
static inline uint32_t buffer_used(struct BitBuf2 *me)
static inline uint32_t
buffer_used(struct BitBuf2 *me)
{
return (uint32_t) (me->m_out_buf - me->m_out_start);
}
static inline uint32_t buffer_bits_used(struct BitBuf2 *me)
static inline uint32_t
buffer_bits_used(struct BitBuf2 *me)
{
return (8 * (uint32_t) (me->m_out_buf - me->m_out_start) + me->m_bit_count);
}
static inline void flush_bits(struct BitBuf2 *me)
static inline void
flush_bits(struct BitBuf2 *me)
{
uint32_t bits;
store_le_u64(me->m_out_buf, me->m_bits);
@ -82,11 +89,11 @@ static inline void flush_bits(struct BitBuf2 *me)
me->m_bit_count -= bits;
me->m_out_buf += bits / 8;
me->m_bits >>= bits;
}
/* Can write up to 8 bytes to output buffer */
static inline void flush(struct BitBuf2 *me)
static inline void
flush(struct BitBuf2 *me)
{
uint32_t bytes;
if (me->m_bit_count) {
@ -98,7 +105,8 @@ static inline void flush(struct BitBuf2 *me)
me->m_bit_count = 0;
}
static inline void check_space(struct BitBuf2 *me, uint32_t num_bits)
static inline void
check_space(struct BitBuf2 *me, uint32_t num_bits)
{
/* Checks if bitbuf has num_bits extra space and flushes the bytes in
* the bitbuf if it doesn't. */
@ -106,24 +114,27 @@ static inline void check_space(struct BitBuf2 *me, uint32_t num_bits)
flush_bits(me);
}
static inline void write_bits_unsafe(struct BitBuf2 *me, uint64_t code, uint32_t count)
static inline void
write_bits_unsafe(struct BitBuf2 *me, uint64_t code, uint32_t count)
{
me->m_bits |= code << me->m_bit_count;
me->m_bit_count += count;
}
static inline void write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count)
static inline void
write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count)
{ /* Assumes there is space to fit code into m_bits. */
me->m_bits |= code << me->m_bit_count;
me->m_bit_count += count;
flush_bits(me);
}
static inline void write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count)
static inline void
write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count)
{ /* Assumes there is space to fit code into m_bits. */
me->m_bits |= code << me->m_bit_count;
me->m_bit_count += count;
flush(me);
}
#endif //BITBUF2_H
#endif // BITBUF2_H

View File

@ -36,13 +36,13 @@
#include "test.h"
#ifndef TEST_SEED
# define TEST_SEED 0x1234
#define TEST_SEED 0x1234
#endif
#define MAX_BUF 512
#define TEST_SIZE 20
typedef uint32_t(*checksum32_func_t) (uint32_t, const unsigned char *, uint64_t);
typedef uint32_t (*checksum32_func_t)(uint32_t, const unsigned char *, uint64_t);
typedef struct func_case {
char *note;
@ -51,12 +51,13 @@ typedef struct func_case {
} func_case_t;
func_case_t test_funcs[] = {
{"checksum32_adler", isal_adler32, adler_ref},
{ "checksum32_adler", isal_adler32, adler_ref },
};
// Generates pseudo-random data
void rand_buffer(unsigned char *buf, long buffer_size)
void
rand_buffer(unsigned char *buf, long buffer_size)
{
long i;
for (i = 0; i < buffer_size; i++)
@ -64,16 +65,23 @@ void rand_buffer(unsigned char *buf, long buffer_size)
}
// Test cases
int zeros_test(func_case_t * test_func);
int simple_pattern_test(func_case_t * test_func);
int seeds_sizes_test(func_case_t * test_func);
int eob_test(func_case_t * test_func);
int update_test(func_case_t * test_func);
int update_over_mod_test(func_case_t * test_func);
int
zeros_test(func_case_t *test_func);
int
simple_pattern_test(func_case_t *test_func);
int
seeds_sizes_test(func_case_t *test_func);
int
eob_test(func_case_t *test_func);
int
update_test(func_case_t *test_func);
int
update_over_mod_test(func_case_t *test_func);
void *buf_alloc = NULL;
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int fail = 0, fail_case;
int i, ret;
@ -115,13 +123,14 @@ int main(int argc, char *argv[])
}
// Test of all zeros
int zeros_test(func_case_t * test_func)
int
zeros_test(func_case_t *test_func)
{
uint32_t c_dut, c_ref;
int fail = 0;
unsigned char *buf = NULL;
buf = (unsigned char *)buf_alloc;
buf = (unsigned char *) buf_alloc;
memset(buf, 0, MAX_BUF * 10);
c_dut = test_func->checksum32_func_call(TEST_SEED, buf, MAX_BUF * 10);
c_ref = test_func->checksum32_ref_call(TEST_SEED, buf, MAX_BUF * 10);
@ -141,13 +150,14 @@ int zeros_test(func_case_t * test_func)
}
// Another simple test pattern
int simple_pattern_test(func_case_t * test_func)
int
simple_pattern_test(func_case_t *test_func)
{
uint32_t c_dut, c_ref;
int fail = 0;
unsigned char *buf = NULL;
buf = (unsigned char *)buf_alloc;
buf = (unsigned char *) buf_alloc;
memset(buf, 0x8a, MAX_BUF);
c_dut = test_func->checksum32_func_call(TEST_SEED, buf, MAX_BUF);
c_ref = test_func->checksum32_ref_call(TEST_SEED, buf, MAX_BUF);
@ -163,7 +173,8 @@ int simple_pattern_test(func_case_t * test_func)
return fail;
}
int seeds_sizes_test(func_case_t * test_func)
int
seeds_sizes_test(func_case_t *test_func)
{
uint32_t c_dut, c_ref;
int fail = 0;
@ -172,7 +183,7 @@ int seeds_sizes_test(func_case_t * test_func)
unsigned char *buf = NULL;
// Do a few random tests
buf = (unsigned char *)buf_alloc; //reset buf
buf = (unsigned char *) buf_alloc; // reset buf
r = rand();
rand_buffer(buf, MAX_BUF * TEST_SIZE);
@ -191,7 +202,7 @@ int seeds_sizes_test(func_case_t * test_func)
}
// Do a few random sizes
buf = (unsigned char *)buf_alloc; //reset buf
buf = (unsigned char *) buf_alloc; // reset buf
r = rand();
for (i = MAX_BUF; i >= 0; i--) {
@ -209,7 +220,7 @@ int seeds_sizes_test(func_case_t * test_func)
// Try different seeds
for (s = 0; s < 20; s++) {
buf = (unsigned char *)buf_alloc; //reset buf
buf = (unsigned char *) buf_alloc; // reset buf
r = rand(); // just to get a new seed
rand_buffer(buf, MAX_BUF * TEST_SIZE); // new pseudo-rand data
@ -223,8 +234,7 @@ int seeds_sizes_test(func_case_t * test_func)
c_ref = test_func->checksum32_ref_call(r, buf, MAX_BUF);
if (c_dut != c_ref) {
fail++;
printf("fail checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut,
c_ref);
printf("fail checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
}
#ifdef TEST_VERBOSE
else
@ -238,15 +248,16 @@ int seeds_sizes_test(func_case_t * test_func)
}
// Run tests at end of buffer
int eob_test(func_case_t * test_func)
int
eob_test(func_case_t *test_func)
{
uint32_t c_dut, c_ref;
int fail = 0;
int i;
unsigned char *buf = NULL;
buf = (unsigned char *)buf_alloc; //reset buf
buf = buf + ((MAX_BUF - 1) * TEST_SIZE); //Line up TEST_SIZE from end
buf = (unsigned char *) buf_alloc; // reset buf
buf = buf + ((MAX_BUF - 1) * TEST_SIZE); // Line up TEST_SIZE from end
for (i = 0; i < TEST_SIZE; i++) {
c_dut = test_func->checksum32_func_call(TEST_SEED, buf + i, TEST_SIZE - i);
c_ref = test_func->checksum32_ref_call(TEST_SEED, buf + i, TEST_SIZE - i);
@ -263,7 +274,8 @@ int eob_test(func_case_t * test_func)
return fail;
}
int update_test(func_case_t * test_func)
int
update_test(func_case_t *test_func)
{
uint32_t c_dut, c_ref;
int fail = 0;
@ -271,7 +283,7 @@ int update_test(func_case_t * test_func)
uint32_t r;
unsigned char *buf = NULL;
buf = (unsigned char *)buf_alloc; //reset buf
buf = (unsigned char *) buf_alloc; // reset buf
r = rand();
// Process the whole buf with reference func single call.
c_ref = test_func->checksum32_ref_call(r, buf, MAX_BUF * TEST_SIZE);
@ -295,7 +307,8 @@ int update_test(func_case_t * test_func)
return fail;
}
int update_over_mod_test(func_case_t * test_func)
int
update_over_mod_test(func_case_t *test_func)
{
uint32_t c_dut, c_ref;
int fail = 0;

View File

@ -8,73 +8,47 @@
#include <stdint.h>
uint32_t inflate_crc_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535,
0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd,
0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d,
0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac,
0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab,
0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb,
0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea,
0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce,
0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409,
0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739,
0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268,
0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0,
0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8,
0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703,
0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7,
0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae,
0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6,
0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d,
0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5,
0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
uint32_t crc32_gzip_refl_ref(uint32_t crc, const unsigned char *buf, uint64_t len)
uint32_t
crc32_gzip_refl_ref(uint32_t crc, const unsigned char *buf, uint64_t len)
{
uint64_t i;
crc = ~crc;
@ -85,8 +59,8 @@ uint32_t crc32_gzip_refl_ref(uint32_t crc, const unsigned char *buf, uint64_t le
#define ADLER_MOD 65521
uint32_t adler_ref(uint32_t init, const unsigned char *buf, uint64_t len)
uint32_t
adler_ref(uint32_t init, const unsigned char *buf, uint64_t len)
{
uint64_t i;
uint32_t a = init & 0xffff;

View File

@ -6,17 +6,17 @@
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
#ifdef _MSC_VER
# include <intrin.h>
#include <intrin.h>
#else
# include <x86intrin.h>
#include <x86intrin.h>
#endif
#endif //__x86_64__ || __i386__ || _M_X64 || _M_IX86
#include "encode_df.h"
#include "bitbuf2.h"
struct deflate_icf *encode_deflate_icf_base(struct deflate_icf *next_in,
struct deflate_icf *end_in, struct BitBuf2 *bb,
struct deflate_icf *
encode_deflate_icf_base(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb,
struct hufftables_icf *hufftables)
{
struct huff_code lsym, dsym;

View File

@ -21,16 +21,17 @@
struct deflate_icf {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
uint32_t lit_len:LIT_LEN_BIT_COUNT;
uint32_t lit_dist:DIST_LIT_BIT_COUNT;
uint32_t dist_extra:ICF_CODE_LEN - DIST_LIT_BIT_COUNT - ICF_DIST_OFFSET;
uint32_t lit_len : LIT_LEN_BIT_COUNT;
uint32_t lit_dist : DIST_LIT_BIT_COUNT;
uint32_t dist_extra : ICF_CODE_LEN - DIST_LIT_BIT_COUNT - ICF_DIST_OFFSET;
#else
uint32_t dist_extra:ICF_CODE_LEN - DIST_LIT_BIT_COUNT - ICF_DIST_OFFSET;
uint32_t lit_dist:DIST_LIT_BIT_COUNT;
uint32_t lit_len:LIT_LEN_BIT_COUNT;
uint32_t dist_extra : ICF_CODE_LEN - DIST_LIT_BIT_COUNT - ICF_DIST_OFFSET;
uint32_t lit_dist : DIST_LIT_BIT_COUNT;
uint32_t lit_len : LIT_LEN_BIT_COUNT;
#endif
};
struct deflate_icf *encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in,
struct BitBuf2 *bb, struct hufftables_icf *hufftables);
struct deflate_icf *
encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb,
struct hufftables_icf *hufftables);
#endif

View File

@ -4,7 +4,8 @@
#include "flatten_ll.h"
void flatten_ll(uint32_t * ll_hist)
void
flatten_ll(uint32_t *ll_hist)
{
uint32_t i, j;
uint32_t *s = ll_hist, x, *p;

View File

@ -1,3 +1,4 @@
#include <stdint.h>
void flatten_ll(uint32_t *ll_hist);
void
flatten_ll(uint32_t *ll_hist);

View File

@ -86,8 +86,9 @@
* @param footer: footer to append at the end of the table.
* @param begin_line: string printed at beginning of new line
*/
void fprint_uint8_table(FILE * outfile, uint8_t * table, uint64_t length, char *header,
char *footer, char *begin_line)
void
fprint_uint8_table(FILE *outfile, uint8_t *table, uint64_t length, char *header, char *footer,
char *begin_line)
{
int i;
fprintf(outfile, "%s", header);
@ -105,7 +106,6 @@ void fprint_uint8_table(FILE * outfile, uint8_t * table, uint64_t length, char *
fprintf(outfile, " ");
fprintf(outfile, "0x%02x", table[i]);
fprintf(outfile, "%s", footer);
}
/**
@ -117,8 +117,9 @@ void fprint_uint8_table(FILE * outfile, uint8_t * table, uint64_t length, char *
* @param footer: footer to append at the end of the table.
* @param begin_line: string printed at beginning of new line
*/
void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char *header,
char *footer, char *begin_line)
void
fprint_uint16_table(FILE *outfile, uint16_t *table, uint64_t length, char *header, char *footer,
char *begin_line)
{
int i;
fprintf(outfile, "%s", header);
@ -136,7 +137,6 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char
fprintf(outfile, " ");
fprintf(outfile, "0x%04x", table[i]);
fprintf(outfile, "%s", footer);
}
/**
@ -148,8 +148,9 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char
* @param footer: footer to append at the end of the table.
* @param begin_line: string printed at beginning of new line
*/
void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char *header,
char *footer, char *begin_line)
void
fprint_uint32_table(FILE *outfile, uint32_t *table, uint64_t length, char *header, char *footer,
char *begin_line)
{
int i;
fprintf(outfile, "%s", header);
@ -167,11 +168,10 @@ void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char
fprintf(outfile, " ");
fprintf(outfile, "0x%08x", table[i]);
fprintf(outfile, "%s", footer);
}
void fprint_hufftables(FILE * output_file, char *hufftables_name,
struct isal_hufftables *hufftables)
void
fprint_hufftables(FILE *output_file, char *hufftables_name, struct isal_hufftables *hufftables)
{
fprintf(output_file, "struct isal_hufftables %s = {\n\n", hufftables_name);
@ -196,37 +196,43 @@ void fprint_hufftables(FILE * output_file, char *hufftables_name,
"\t.lit_table_sizes = {", "},\n\n", "\t\t");
fprint_uint16_table(output_file, hufftables->dcodes,
ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET,
"\t.dcodes = {", "},\n\n", "\t\t");
ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET, "\t.dcodes = {", "},\n\n",
"\t\t");
fprint_uint8_table(output_file, hufftables->dcodes_sizes,
ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET,
"\t.dcodes_sizes = {", "}\n", "\t\t");
ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET, "\t.dcodes_sizes = {",
"}\n", "\t\t");
fprintf(output_file, "};\n");
}
void fprint_header(FILE * output_file)
void
fprint_header(FILE *output_file)
{
fprintf(output_file, "#include <stdint.h>\n");
fprintf(output_file, "#include <igzip_lib.h>\n\n");
fprintf(output_file, "#if IGZIP_HIST_SIZE > %d\n"
fprintf(output_file,
"#if IGZIP_HIST_SIZE > %d\n"
"# error \"Invalid history size for the custom hufftable\"\n"
"#endif\n", IGZIP_HIST_SIZE);
"#endif\n",
IGZIP_HIST_SIZE);
#ifdef LONGER_HUFFTABLE
fprintf(output_file, "#ifndef LONGER_HUFFTABLE\n"
fprintf(output_file,
"#ifndef LONGER_HUFFTABLE\n"
"# error \"Custom hufftable requires LONGER_HUFFTABLE to be defined \"\n"
"#endif\n");
#else
fprintf(output_file, "#ifdef LONGER_HUFFTABLE\n"
fprintf(output_file,
"#ifdef LONGER_HUFFTABLE\n"
"# error \"Custom hufftable requires LONGER_HUFFTABLE to not be defined \"\n"
"#endif\n");
#endif
fprintf(output_file, "\n");
fprintf(output_file, "const uint8_t gzip_hdr[] = {\n"
"\t0x1f, 0x8b, 0x08, 0x00, 0x00,\n" "\t0x00, 0x00, 0x00, 0x00, 0xff\t};\n\n");
"\t0x1f, 0x8b, 0x08, 0x00, 0x00,\n"
"\t0x00, 0x00, 0x00, 0x00, 0xff\t};\n\n");
fprintf(output_file, "const uint32_t gzip_hdr_bytes = %d;\n", GZIP_HEADER_SIZE);
fprintf(output_file, "const uint32_t gzip_trl_bytes = %d;\n\n", GZIP_TRAILER_SIZE);
@ -236,7 +242,8 @@ void fprint_header(FILE * output_file)
fprintf(output_file, "const uint32_t zlib_trl_bytes = %d;\n", ZLIB_TRAILER_SIZE);
}
static uint32_t convert_dist_to_dist_sym(uint32_t dist)
static uint32_t
convert_dist_to_dist_sym(uint32_t dist)
{
assert(dist <= 32768 && dist > 0);
if (dist <= 32768) {
@ -250,7 +257,8 @@ static uint32_t convert_dist_to_dist_sym(uint32_t dist)
/**
* @brief Returns the deflate symbol value for a repeat length.
*/
static uint32_t convert_length_to_len_sym(uint32_t length)
static uint32_t
convert_length_to_len_sym(uint32_t length)
{
assert(length > 2 && length < 259);
@ -271,7 +279,8 @@ static uint32_t convert_length_to_len_sym(uint32_t length)
return 285;
}
void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int length,
void
isal_update_histogram_dict(uint8_t *start_stream, int dict_length, int length,
struct isal_huff_histogram *histogram)
{
uint32_t literal = 0, hash;
@ -304,8 +313,7 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len
dist = (current - start_stream - seen) & 0xFFFF;
if (dist - 1 < D - 1) {
assert(start_stream <= current - dist);
match_length =
compare258(current - dist, current, end_stream - current);
match_length = compare258(current - dist, current, end_stream - current);
if (match_length >= SHORTEST_MATCH) {
next_hash = current;
#ifdef ISAL_LIMIT_HASH_UPDATE
@ -323,8 +331,7 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len
}
dist_histogram[convert_dist_to_dist_sym(dist)] += 1;
lit_len_histogram[convert_length_to_len_sym(match_length)] +=
1;
lit_len_histogram[convert_length_to_len_sym(match_length)] += 1;
current += match_length - 1;
continue;
}
@ -339,7 +346,8 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len
return;
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
long int file_length;
int argi = 1;
@ -411,8 +419,7 @@ int main(int argc, char *argv[])
}
fseek(hist_file, 0, SEEK_SET);
printf("Read %ld bytes of history file %s\n", hist_file_length,
argv[argi + 1]);
printf("Read %ld bytes of history file %s\n", hist_file_length, argv[argi + 1]);
argi += 2;
} else
memset(&histogram, 0, sizeof(histogram)); /* Initialize histograms. */

View File

@ -48,8 +48,9 @@ extern struct isal_hufftables hufftables_default;
* @param footer: footer to append at the end of the table.
* @param begin_line: string printed at beginning of new line
*/
void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char *header,
char *footer, char *begin_line)
void
fprint_uint16_table(FILE *outfile, uint16_t *table, uint64_t length, char *header, char *footer,
char *begin_line)
{
int i;
fprintf(outfile, "%s", header);
@ -67,7 +68,6 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char
fprintf(outfile, " ");
fprintf(outfile, "0x%04x", table[i]);
fprintf(outfile, "%s", footer);
}
/**
@ -79,8 +79,9 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char
* @param footer: footer to append at the end of the table.
* @param begin_line: string printed at beginning of new line
*/
void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char *header,
char *footer, char *begin_line)
void
fprint_uint32_table(FILE *outfile, uint32_t *table, uint64_t length, char *header, char *footer,
char *begin_line)
{
int i;
fprintf(outfile, "%s", header);
@ -98,23 +99,25 @@ void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char
fprintf(outfile, " ");
fprintf(outfile, "0x%08x", table[i]);
fprintf(outfile, "%s", footer);
}
void fprint_header(FILE * output_file)
void
fprint_header(FILE *output_file)
{
fprintf(output_file, "#include \"igzip_lib.h\"\n\n");
fprintf(output_file, "#define LONG_BITS_CHECK %d\n", ISAL_DECODE_LONG_BITS);
fprintf(output_file, "#define SHORT_BITS_CHECK %d\n", ISAL_DECODE_SHORT_BITS);
fprintf(output_file,
"#if (LONG_BITS_CHECK == ISAL_DECODE_LONG_BITS) && (SHORT_BITS_CHECK == ISAL_DECODE_SHORT_BITS)\n"
fprintf(output_file, "#if (LONG_BITS_CHECK == ISAL_DECODE_LONG_BITS) && (SHORT_BITS_CHECK "
"== ISAL_DECODE_SHORT_BITS)\n"
"# define ISAL_STATIC_INFLATE_TABLE\n"
"#else\n"
"# warning \"Incompatible compile time defines for optimized static inflate table.\"\n"
"# warning \"Incompatible compile time defines for optimized static "
"inflate table.\"\n"
"#endif\n\n");
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
struct inflate_state state;
FILE *file;
@ -144,7 +147,8 @@ int main(int argc, char *argv[])
}
// Add decode tables describing a type 2 static (fixed) header
fprintf(file, "#ifndef STATIC_HEADER_H\n" "#define STATIC_HEADER_H\n\n");
fprintf(file, "#ifndef STATIC_HEADER_H\n"
"#define STATIC_HEADER_H\n\n");
fprint_header(file);
@ -172,8 +176,7 @@ int main(int argc, char *argv[])
isal_inflate_init(&state);
memcpy(in_buf, &hufftables_default.deflate_hdr,
sizeof(hufftables_default.deflate_hdr));
memcpy(in_buf, &hufftables_default.deflate_hdr, sizeof(hufftables_default.deflate_hdr));
state.next_in = in_buf;
state.avail_in = DOUBLE_SYM_THRESH + 1;
state.next_out = tmp_space;

File diff suppressed because it is too large Load Diff

View File

@ -37,11 +37,11 @@
#include "bitbuf2.h"
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
# include <immintrin.h>
#include <immintrin.h>
#ifdef _MSC_VER
# include <intrin.h>
#include <intrin.h>
#else
# include <x86intrin.h>
#include <x86intrin.h>
#endif
#endif //__x86_64__ || __i386__ || _M_X64 || _M_IX86
@ -50,9 +50,9 @@
#define CODE_LEN_CODES 19
#define HUFF_LEN 19
#ifdef LONGER_HUFFTABLE
# define DCODE_OFFSET 26
#define DCODE_OFFSET 26
#else
# define DCODE_OFFSET 0
#define DCODE_OFFSET 0
#endif
#define DYN_HDR_START_LEN 17
#define MAX_HISTHEAP_SIZE LIT_LEN
@ -95,8 +95,8 @@
#define DEPTH_MASK 0x7F
#define DEPTH_MASK_HI (DEPTH_MASK << DEPTH_SHIFT)
#define DEPTH_1 (1 << DEPTH_SHIFT)
#define HEAP_TREE_SIZE (3*MAX_HISTHEAP_SIZE + 1)
#define HEAP_TREE_NODE_START (HEAP_TREE_SIZE-1)
#define HEAP_TREE_SIZE (3 * MAX_HISTHEAP_SIZE + 1)
#define HEAP_TREE_NODE_START (HEAP_TREE_SIZE - 1)
#define MAX_BL_CODE_LEN 7
/**
@ -106,11 +106,11 @@ struct huff_code {
union {
struct {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
uint32_t code_and_extra:24;
uint32_t length2:8;
uint32_t code_and_extra : 24;
uint32_t length2 : 8;
#else
uint32_t length2:8;
uint32_t code_and_extra:24;
uint32_t length2 : 8;
uint32_t code_and_extra : 24;
#endif
};

View File

@ -35,13 +35,13 @@
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
#ifdef _MSC_VER
# include <intrin.h>
# define inline __inline
#include <intrin.h>
#define inline __inline
#else
# include <x86intrin.h>
#include <x86intrin.h>
#endif
#else
# define inline __inline
#define inline __inline
#endif //__x86_64__ || __i386__ || _M_X64 || _M_IX86
/**
@ -50,7 +50,8 @@
*
* @returns bit offset of msb starting at 1 for first bit
*/
static inline uint32_t bsr(uint32_t val)
static inline uint32_t
bsr(uint32_t val)
{
uint32_t msb;
#if defined(_MSC_VER)
@ -60,7 +61,7 @@ static inline uint32_t bsr(uint32_t val)
msb = ret + 1;
} else
msb = 0;
#elif defined( __LZCNT__)
#elif defined(__LZCNT__)
msb = 32 - __lzcnt32(val);
#elif defined(__x86_64__) || defined(__aarch64__)
msb = (val == 0) ? 0 : 32 - __builtin_clz(val);
@ -71,7 +72,8 @@ static inline uint32_t bsr(uint32_t val)
return msb;
}
static inline uint32_t tzbytecnt(uint64_t val)
static inline uint32_t
tzbytecnt(uint64_t val)
{
uint32_t cnt;
@ -90,8 +92,9 @@ static inline uint32_t tzbytecnt(uint64_t val)
return cnt;
}
static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist,
uint64_t * p_code, uint64_t * p_len)
static void
compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist, uint64_t *p_code,
uint64_t *p_len)
{
assert(dist > IGZIP_DIST_TABLE_SIZE);
@ -116,8 +119,8 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist,
*p_len = len + num_extra_bits;
}
static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t dist,
uint64_t * code, uint64_t * len)
static inline void
get_dist_code(struct isal_hufftables *hufftables, uint32_t dist, uint64_t *code, uint64_t *len)
{
assert(dist >= 1);
assert(dist <= 32768);
@ -131,8 +134,8 @@ static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t di
}
}
static inline void get_len_code(struct isal_hufftables *hufftables, uint32_t length,
uint64_t * code, uint64_t * len)
static inline void
get_len_code(struct isal_hufftables *hufftables, uint32_t length, uint64_t *code, uint64_t *len)
{
assert(length >= 3);
assert(length <= 258);
@ -143,8 +146,8 @@ static inline void get_len_code(struct isal_hufftables *hufftables, uint32_t len
*len = code_len & 0x1F;
}
static inline void get_lit_code(struct isal_hufftables *hufftables, uint32_t lit,
uint64_t * code, uint64_t * len)
static inline void
get_lit_code(struct isal_hufftables *hufftables, uint32_t lit, uint64_t *code, uint64_t *len)
{
assert(lit <= 256);
@ -152,7 +155,8 @@ static inline void get_lit_code(struct isal_hufftables *hufftables, uint32_t lit
*len = hufftables->lit_table_sizes[lit];
}
static void compute_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t * extra_bits)
static void
compute_dist_icf_code(uint32_t dist, uint32_t *code, uint32_t *extra_bits)
{
uint32_t msb;
uint32_t num_extra_bits;
@ -167,7 +171,8 @@ static void compute_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t * ext
assert(*code < 30);
}
static inline void get_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t * extra_bits)
static inline void
get_dist_icf_code(uint32_t dist, uint32_t *code, uint32_t *extra_bits)
{
assert(dist >= 1);
assert(dist <= 32768);
@ -179,7 +184,8 @@ static inline void get_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t *
}
}
static inline void get_len_icf_code(uint32_t length, uint32_t * code)
static inline void
get_len_icf_code(uint32_t length, uint32_t *code)
{
assert(length >= 3);
assert(length <= 258);
@ -187,7 +193,8 @@ static inline void get_len_icf_code(uint32_t length, uint32_t * code)
*code = length + 254;
}
static inline void get_lit_icf_code(uint32_t lit, uint32_t * code)
static inline void
get_lit_icf_code(uint32_t lit, uint32_t *code)
{
assert(lit <= 256);
@ -197,7 +204,8 @@ static inline void get_lit_icf_code(uint32_t lit, uint32_t * code)
/**
* @brief Returns a hash of the first 3 bytes of input data.
*/
static inline uint32_t compute_hash(uint32_t data)
static inline uint32_t
compute_hash(uint32_t data)
{
#ifdef __SSE4_2__
@ -219,7 +227,8 @@ static inline uint32_t compute_hash(uint32_t data)
#define PROD1 0xFFFFE84B
#define PROD2 0xFFFF97B1
static inline uint32_t compute_hash_mad(uint32_t data)
static inline uint32_t
compute_hash_mad(uint32_t data)
{
int16_t data_low;
int16_t data_high;
@ -235,7 +244,8 @@ static inline uint32_t compute_hash_mad(uint32_t data)
return data;
}
static inline uint32_t compute_long_hash(uint64_t data)
static inline uint32_t
compute_long_hash(uint64_t data)
{
return compute_hash(data >> 32) ^ compute_hash(data);
@ -247,7 +257,8 @@ static inline uint32_t compute_long_hash(uint64_t data)
* @param str2: Second input string.
* @param max_length: length of the smaller string.
*/
static inline int compare258(uint8_t * str1, uint8_t * str2, uint32_t max_length)
static inline int
compare258(uint8_t *str1, uint8_t *str2, uint32_t max_length)
{
uint32_t count;
uint64_t test;
@ -308,7 +319,8 @@ static inline int compare258(uint8_t * str1, uint8_t * str2, uint32_t max_length
* @param str2: Second input string.
* @param max_length: length of the smaller string.
*/
static inline int compare(uint8_t * str1, uint8_t * str2, uint32_t max_length)
static inline int
compare(uint8_t *str1, uint8_t *str2, uint32_t max_length)
{
uint32_t count;
uint64_t test;

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@
#include <string.h>
#include <wchar.h>
#ifdef _WIN32
# include <intrin.h>
#include <intrin.h>
#endif
#define MAX_WRITE_BITS_SIZE 8
@ -54,10 +54,14 @@
#include "igzip_wrapper.h"
#include "unaligned.h"
extern void isal_deflate_hash_lvl0(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void isal_deflate_hash_lvl1(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void isal_deflate_hash_lvl2(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void isal_deflate_hash_lvl3(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void
isal_deflate_hash_lvl0(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void
isal_deflate_hash_lvl1(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void
isal_deflate_hash_lvl2(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void
isal_deflate_hash_lvl3(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern const uint8_t gzip_hdr[];
extern const uint32_t gzip_hdr_bytes;
extern const uint32_t gzip_trl_bytes;
@ -67,38 +71,52 @@ extern const uint32_t zlib_trl_bytes;
extern const struct isal_hufftables hufftables_default;
extern const struct isal_hufftables hufftables_static;
static uint32_t write_stored_block(struct isal_zstream *stream);
static uint32_t
write_stored_block(struct isal_zstream *stream);
static int write_stream_header_stateless(struct isal_zstream *stream);
static void write_stream_header(struct isal_zstream *stream);
static int write_deflate_header_stateless(struct isal_zstream *stream);
static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream);
static int
write_stream_header_stateless(struct isal_zstream *stream);
static void
write_stream_header(struct isal_zstream *stream);
static int
write_deflate_header_stateless(struct isal_zstream *stream);
static int
write_deflate_header_unaligned_stateless(struct isal_zstream *stream);
#define TYPE0_HDR_LEN 4
#define TYPE0_BLK_HDR_LEN 5
#define TYPE0_MAX_BLK_LEN 65535
void isal_deflate_body(struct isal_zstream *stream);
void isal_deflate_finish(struct isal_zstream *stream);
void
isal_deflate_body(struct isal_zstream *stream);
void
isal_deflate_finish(struct isal_zstream *stream);
void isal_deflate_icf_body(struct isal_zstream *stream);
void isal_deflate_icf_finish_lvl1(struct isal_zstream *stream);
void isal_deflate_icf_finish_lvl2(struct isal_zstream *stream);
void isal_deflate_icf_finish_lvl3(struct isal_zstream *stream);
void
isal_deflate_icf_body(struct isal_zstream *stream);
void
isal_deflate_icf_finish_lvl1(struct isal_zstream *stream);
void
isal_deflate_icf_finish_lvl2(struct isal_zstream *stream);
void
isal_deflate_icf_finish_lvl3(struct isal_zstream *stream);
/*****************************************************************/
/* Forward declarations */
static inline void reset_match_history(struct isal_zstream *stream);
static void write_header(struct isal_zstream *stream, uint8_t * deflate_hdr,
uint32_t deflate_hdr_count, uint32_t extra_bits_count,
uint32_t next_state, uint32_t toggle_end_of_stream);
static void write_trailer(struct isal_zstream *stream);
static inline void
reset_match_history(struct isal_zstream *stream);
static void
write_header(struct isal_zstream *stream, uint8_t *deflate_hdr, uint32_t deflate_hdr_count,
uint32_t extra_bits_count, uint32_t next_state, uint32_t toggle_end_of_stream);
static void
write_trailer(struct isal_zstream *stream);
/*****************************************************************/
// isal_adler32_bam1 - adler with (B | A minus 1) storage
uint32_t isal_adler32_bam1(uint32_t adler32, const unsigned char *start, uint64_t length)
uint32_t
isal_adler32_bam1(uint32_t adler32, const unsigned char *start, uint64_t length)
{
uint64_t a;
@ -113,7 +131,8 @@ uint32_t isal_adler32_bam1(uint32_t adler32, const unsigned char *start, uint64_
return (adler32 & 0xffff0000) | a;
}
static void update_checksum(struct isal_zstream *stream, uint8_t * start_in, uint64_t length)
static void
update_checksum(struct isal_zstream *stream, uint8_t *start_in, uint64_t length)
{
struct isal_zstate *state = &stream->internal_state;
switch (stream->gzip_flag) {
@ -128,8 +147,8 @@ static void update_checksum(struct isal_zstream *stream, uint8_t * start_in, uin
}
}
static
void sync_flush(struct isal_zstream *stream)
static void
sync_flush(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
uint64_t bits_to_write = 0xFFFF0000, bits_len;
@ -162,7 +181,8 @@ void sync_flush(struct isal_zstream *stream)
}
}
static void flush_write_buffer(struct isal_zstream *stream)
static void
flush_write_buffer(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
int bytes = 0;
@ -177,18 +197,19 @@ static void flush_write_buffer(struct isal_zstream *stream)
}
}
static void flush_icf_block(struct isal_zstream *stream)
static void
flush_icf_block(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
struct BitBuf2 *write_buf = &state->bitbuf;
struct deflate_icf *icf_buf_encoded_next;
set_buf(write_buf, stream->next_out, stream->avail_out);
icf_buf_encoded_next = encode_deflate_icf(level_buf->icf_buf_start + state->count,
level_buf->icf_buf_next, write_buf,
&level_buf->encode_tables);
icf_buf_encoded_next =
encode_deflate_icf(level_buf->icf_buf_start + state->count, level_buf->icf_buf_next,
write_buf, &level_buf->encode_tables);
state->count = icf_buf_encoded_next - level_buf->icf_buf_start;
stream->next_out = buffer_ptr(write_buf);
@ -206,7 +227,8 @@ static void flush_icf_block(struct isal_zstream *stream)
}
}
static int check_level_req(struct isal_zstream *stream)
static int
check_level_req(struct isal_zstream *stream)
{
if (stream->level == 0)
return 0;
@ -235,26 +257,29 @@ static int check_level_req(struct isal_zstream *stream)
return 0;
}
static int init_hash8k_buf(struct isal_zstream *stream)
static int
init_hash8k_buf(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
state->has_level_buf_init = 1;
return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash8k);
}
static int init_hash_hist_buf(struct isal_zstream *stream)
static int
init_hash_hist_buf(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
state->has_level_buf_init = 1;
return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash_hist);
}
static int init_hash_map_buf(struct isal_zstream *stream)
static int
init_hash_map_buf(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
if (!state->has_level_buf_init) {
level_buf->hash_map.matches_next = level_buf->hash_map.matches;
level_buf->hash_map.matches_end = level_buf->hash_map.matches;
@ -262,11 +287,11 @@ static int init_hash_map_buf(struct isal_zstream *stream)
state->has_level_buf_init = 1;
return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash_map);
}
/* returns the size of the level specific buffer */
static int init_lvlX_buf(struct isal_zstream *stream)
static int
init_lvlX_buf(struct isal_zstream *stream)
{
switch (stream->level) {
case 3:
@ -276,20 +301,19 @@ static int init_lvlX_buf(struct isal_zstream *stream)
default:
return init_hash8k_buf(stream);
}
}
static void init_new_icf_block(struct isal_zstream *stream)
static void
init_new_icf_block(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
int level_struct_size;
level_struct_size = init_lvlX_buf(stream);
state->block_next = state->block_end;
level_buf->icf_buf_start =
(struct deflate_icf *)(stream->level_buf + level_struct_size);
level_buf->icf_buf_start = (struct deflate_icf *) (stream->level_buf + level_struct_size);
level_buf->icf_buf_next = level_buf->icf_buf_start;
level_buf->icf_buf_avail_out =
@ -299,20 +323,23 @@ static void init_new_icf_block(struct isal_zstream *stream)
state->state = ZSTATE_BODY;
}
static int are_buffers_empty_hashX(struct isal_zstream *stream)
static int
are_buffers_empty_hashX(struct isal_zstream *stream)
{
return !stream->avail_in;
}
static int are_buffers_empty_hash_map(struct isal_zstream *stream)
static int
are_buffers_empty_hash_map(struct isal_zstream *stream)
{
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
return (!stream->avail_in
&& level_buf->hash_map.matches_next >= level_buf->hash_map.matches_end);
return (!stream->avail_in &&
level_buf->hash_map.matches_next >= level_buf->hash_map.matches_end);
}
static int are_buffers_empty(struct isal_zstream *stream)
static int
are_buffers_empty(struct isal_zstream *stream)
{
switch (stream->level) {
@ -325,10 +352,11 @@ static int are_buffers_empty(struct isal_zstream *stream)
}
}
static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in)
static void
create_icf_block_hdr(struct isal_zstream *stream, uint8_t *start_in)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
struct BitBuf2 *write_buf = &state->bitbuf;
struct BitBuf2 write_buf_tmp;
uint32_t out_size = stream->avail_out;
@ -346,8 +374,9 @@ static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in
* for bits stored in the bitbuf. Since 3 bits correspond to the deflate
* type 0 header, we need to add one byte more when the number of bits
* is at least 6 mod 8. */
block_size = (TYPE0_BLK_HDR_LEN) * ((block_in_size + TYPE0_MAX_BLK_LEN - 1) /
TYPE0_MAX_BLK_LEN) + block_in_size;
block_size = (TYPE0_BLK_HDR_LEN) *
((block_in_size + TYPE0_MAX_BLK_LEN - 1) / TYPE0_MAX_BLK_LEN) +
block_in_size;
block_size = block_size ? block_size : TYPE0_BLK_HDR_LEN;
block_size += (write_buf->m_bit_count + 2) / 8;
@ -374,17 +403,17 @@ static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in
buffer_header = 1;
}
bit_count = create_hufftables_icf(write_buf, &level_buf->encode_tables,
&level_buf->hist, state->has_eob_hdr);
bit_count = create_hufftables_icf(write_buf, &level_buf->encode_tables, &level_buf->hist,
state->has_eob_hdr);
/* Assumes that type 0 block has size less than 4G */
block_start_offset = (stream->total_in - state->block_next);
cur_in_processed = stream->next_in - start_in;
avail_output = stream->avail_out + sizeof(state->buffer) -
(stream->total_in - state->block_end);
avail_output =
stream->avail_out + sizeof(state->buffer) - (stream->total_in - state->block_end);
if (bit_count / 8 >= block_size && cur_in_processed >= block_start_offset
&& block_size <= avail_output) {
if (bit_count / 8 >= block_size && cur_in_processed >= block_start_offset &&
block_size <= avail_output) {
/* Reset stream for writing out a type0 block */
state->has_eob_hdr = 0;
memcpy(write_buf, &write_buf_tmp, sizeof(struct BitBuf2));
@ -408,7 +437,8 @@ static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in
}
}
static void isal_deflate_pass(struct isal_zstream *stream)
static void
isal_deflate_pass(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct isal_hufftables *hufftables = stream->hufftables;
@ -442,7 +472,8 @@ static void isal_deflate_pass(struct isal_zstream *stream)
write_trailer(stream);
}
static void isal_deflate_icf_finish(struct isal_zstream *stream)
static void
isal_deflate_icf_finish(struct isal_zstream *stream)
{
switch (stream->level) {
case 3:
@ -456,11 +487,12 @@ static void isal_deflate_icf_finish(struct isal_zstream *stream)
}
}
static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_start)
static void
isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t *inbuf_start)
{
uint8_t *start_in = stream->next_in;
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
do {
if (state->state == ZSTATE_NEW_HDR)
@ -479,10 +511,8 @@ static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_s
/* Note that the header may be prepended by the
* remaining bits in the previous block, as such the
* toggle header flag cannot be used */
write_header(stream, level_buf->deflate_hdr,
level_buf->deflate_hdr_count,
level_buf->deflate_hdr_extra_bits,
ZSTATE_FLUSH_ICF_BUFFER, 0);
write_header(stream, level_buf->deflate_hdr, level_buf->deflate_hdr_count,
level_buf->deflate_hdr_extra_bits, ZSTATE_FLUSH_ICF_BUFFER, 0);
if (state->state == ZSTATE_FLUSH_ICF_BUFFER)
flush_icf_block(stream);
@ -493,8 +523,7 @@ static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_s
write_stored_block(stream);
}
}
while (state->state == ZSTATE_NEW_HDR);
} while (state->state == ZSTATE_NEW_HDR);
if (state->state == ZSTATE_SYNC_FLUSH)
sync_flush(stream);
@ -509,7 +538,8 @@ static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_s
write_trailer(stream);
}
static void isal_deflate_int(struct isal_zstream *stream, uint8_t * start_in)
static void
isal_deflate_int(struct isal_zstream *stream, uint8_t *start_in)
{
struct isal_zstate *state = &stream->internal_state;
uint32_t size;
@ -528,7 +558,8 @@ static void isal_deflate_int(struct isal_zstream *stream, uint8_t * start_in)
if (state->tmp_out_start == state->tmp_out_end)
state->state -= ZSTATE_TMP_OFFSET;
if (stream->avail_out == 0 || state->state == ZSTATE_END
if (stream->avail_out == 0 ||
state->state == ZSTATE_END
// or do not write out empty blocks since the outbuffer was processed
|| (state->state == ZSTATE_NEW_HDR && stream->avail_out == 0))
return;
@ -576,14 +607,12 @@ static void isal_deflate_int(struct isal_zstream *stream, uint8_t * start_in)
state->tmp_out_start += size;
if (state->tmp_out_start != state->tmp_out_end)
state->state += ZSTATE_TMP_OFFSET;
}
}
}
static void write_constant_compressed_stateless(struct isal_zstream *stream,
uint32_t repeated_length)
static void
write_constant_compressed_stateless(struct isal_zstream *stream, uint32_t repeated_length)
{
/* Assumes repeated_length is at least 1.
* Assumes the input end_of_stream is either 0 or 1. */
@ -636,13 +665,12 @@ static void write_constant_compressed_stateless(struct isal_zstream *stream,
if (rep_extra >= 230) {
write_bits(&state->bitbuf,
CODE_280 | ((rep_extra / 2 - 115) <<
CODE_280_LENGTH), CODE_280_TOTAL_LENGTH);
CODE_280 | ((rep_extra / 2 - 115) << CODE_280_LENGTH),
CODE_280_TOTAL_LENGTH);
rep_extra -= rep_extra / 2;
}
write_bits(&state->bitbuf,
CODE_280 | ((rep_extra - 115) << CODE_280_LENGTH),
write_bits(&state->bitbuf, CODE_280 | ((rep_extra - 115) << CODE_280_LENGTH),
CODE_280_TOTAL_LENGTH);
} else {
@ -674,7 +702,8 @@ static void write_constant_compressed_stateless(struct isal_zstream *stream,
return;
}
static int detect_repeated_char_length(uint8_t * in, uint32_t length)
static int
detect_repeated_char_length(uint8_t *in, uint32_t length)
{
/* This currently assumes the first 8 bytes are the same character.
* This won't work effectively if the input stream isn't aligned well. */
@ -683,16 +712,19 @@ static int detect_repeated_char_length(uint8_t * in, uint32_t length)
uint64_t w = *p_64;
uint8_t c = (uint8_t) w;
for (; (p_64 <= (uint64_t *) (end - 8)) && (w == *p_64); p_64++) ;
for (; (p_64 <= (uint64_t *) (end - 8)) && (w == *p_64); p_64++)
;
p_8 = (uint8_t *) p_64;
for (; (p_8 < end) && (c == *p_8); p_8++) ;
for (; (p_8 < end) && (c == *p_8); p_8++)
;
return p_8 - in;
}
static int isal_deflate_int_stateless(struct isal_zstream *stream)
static int
isal_deflate_int_stateless(struct isal_zstream *stream)
{
uint32_t repeat_length;
struct isal_zstate *state = &stream->internal_state;
@ -701,9 +733,8 @@ static int isal_deflate_int_stateless(struct isal_zstream *stream)
if (write_stream_header_stateless(stream))
return STATELESS_OVERFLOW;
if (stream->avail_in >= 8
&& (load_native_u64(stream->next_in) == 0
|| load_native_u64(stream->next_in) == ~(uint64_t) 0)) {
if (stream->avail_in >= 8 && (load_native_u64(stream->next_in) == 0 ||
load_native_u64(stream->next_in) == ~(uint64_t) 0)) {
repeat_length = detect_repeated_char_length(stream->next_in, stream->avail_in);
if (stream->avail_in == repeat_length || repeat_length >= MIN_REPEAT_LEN)
@ -727,17 +758,17 @@ static int isal_deflate_int_stateless(struct isal_zstream *stream)
state->count = 0;
isal_deflate_icf_pass(stream, stream->next_in);
}
if (state->state == ZSTATE_END
|| (state->state == ZSTATE_NEW_HDR && stream->flush == FULL_FLUSH))
if (state->state == ZSTATE_END ||
(state->state == ZSTATE_NEW_HDR && stream->flush == FULL_FLUSH))
return COMP_OK;
else
return STATELESS_OVERFLOW;
}
static void write_type0_header(struct isal_zstream *stream)
static void
write_type0_header(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
uint64_t stored_blk_hdr;
@ -791,7 +822,8 @@ static void write_type0_header(struct isal_zstream *stream)
stream->internal_state.count = copy_size;
}
static uint32_t write_stored_block(struct isal_zstream *stream)
static uint32_t
write_stored_block(struct isal_zstream *stream)
{
uint32_t copy_size, avail_in, block_next_offset;
uint8_t *next_in;
@ -813,8 +845,7 @@ static uint32_t write_stored_block(struct isal_zstream *stream)
if (copy_size > stream->avail_out || copy_size > avail_in) {
state->count = copy_size;
copy_size = (stream->avail_out <= avail_in) ?
stream->avail_out : avail_in;
copy_size = (stream->avail_out <= avail_in) ? stream->avail_out : avail_in;
memcpy(stream->next_out, next_in, copy_size);
state->count -= copy_size;
@ -832,8 +863,8 @@ static uint32_t write_stored_block(struct isal_zstream *stream)
if (state->block_next == state->block_end) {
state->state = state->has_eob_hdr ? ZSTATE_TRL : ZSTATE_NEW_HDR;
if (stream->flush == FULL_FLUSH && state->state == ZSTATE_NEW_HDR
&& are_buffers_empty(stream)) {
if (stream->flush == FULL_FLUSH && state->state == ZSTATE_NEW_HDR &&
are_buffers_empty(stream)) {
/* Clear match history so there are no cross
* block length distance pairs */
reset_match_history(stream);
@ -844,10 +875,11 @@ static uint32_t write_stored_block(struct isal_zstream *stream)
return state->block_end - state->block_next;
}
static inline void reset_match_history(struct isal_zstream *stream)
static inline void
reset_match_history(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint16_t *hash_table;
uint32_t hash_table_size;
@ -878,20 +910,17 @@ static inline void reset_match_history(struct isal_zstream *stream)
uint16_t hash_init_val;
hash_init_val = stream->total_in & 0xffff;
wmemset((wchar_t *)hash_table, hash_init_val,
hash_table_size / sizeof(wchar_t));
wmemset((wchar_t *) hash_table, hash_init_val, hash_table_size / sizeof(wchar_t));
} else if (sizeof(wchar_t) == 4) {
uint32_t hash_init_val;
int rep_bits;
hash_init_val = stream->total_in & 0xffff;
for (rep_bits = sizeof(uint16_t) * 8; rep_bits < sizeof(wchar_t) * 8;
rep_bits *= 2)
for (rep_bits = sizeof(uint16_t) * 8; rep_bits < sizeof(wchar_t) * 8; rep_bits *= 2)
hash_init_val |= hash_init_val << rep_bits;
wmemset((wchar_t *)hash_table, hash_init_val,
hash_table_size / sizeof(wchar_t));
wmemset((wchar_t *) hash_table, hash_init_val, hash_table_size / sizeof(wchar_t));
} else {
if ((stream->total_in & 0xFFFF) == 0)
memset(hash_table, 0, hash_table_size);
@ -902,7 +931,6 @@ static inline void reset_match_history(struct isal_zstream *stream)
}
}
}
}
static void inline set_dist_mask(struct isal_zstream *stream)
@ -939,13 +967,14 @@ static void inline set_hash_mask(struct isal_zstream *stream)
}
}
void isal_deflate_init(struct isal_zstream *stream)
void
isal_deflate_init(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
stream->total_in = 0;
stream->total_out = 0;
stream->hufftables = (struct isal_hufftables *)&hufftables_default;
stream->hufftables = (struct isal_hufftables *) &hufftables_default;
stream->level = 0;
stream->level_buf = NULL;
stream->level_buf_size = 0;
@ -977,7 +1006,8 @@ void isal_deflate_init(struct isal_zstream *stream)
return;
}
void isal_deflate_reset(struct isal_zstream *stream)
void
isal_deflate_reset(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
@ -1003,10 +1033,10 @@ void isal_deflate_reset(struct isal_zstream *stream)
init(&state->bitbuf);
state->crc = 0;
}
void isal_gzip_header_init(struct isal_gzip_header *gz_hdr)
void
isal_gzip_header_init(struct isal_gzip_header *gz_hdr)
{
gz_hdr->text = 0;
gz_hdr->time = 0;
@ -1023,7 +1053,8 @@ void isal_gzip_header_init(struct isal_gzip_header *gz_hdr)
gz_hdr->flags = 0;
}
void isal_zlib_header_init(struct isal_zlib_header *z_hdr)
void
isal_zlib_header_init(struct isal_zlib_header *z_hdr)
{
z_hdr->info = 0;
z_hdr->level = 0;
@ -1031,7 +1062,8 @@ void isal_zlib_header_init(struct isal_zlib_header *z_hdr)
z_hdr->dict_flag = 0;
}
uint32_t isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_header *gz_hdr)
uint32_t
isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_header *gz_hdr)
{
uint32_t flags = 0, hcrc, hdr_size = GZIP_HDR_BASE;
uint8_t *out_buf = stream->next_out, *out_buf_start = stream->next_out;
@ -1105,7 +1137,8 @@ uint32_t isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_he
return ISAL_DECOMP_OK;
}
uint32_t isal_write_zlib_header(struct isal_zstream *stream, struct isal_zlib_header *z_hdr)
uint32_t
isal_write_zlib_header(struct isal_zstream *stream, struct isal_zlib_header *z_hdr)
{
uint32_t cmf, flg, dict_flag = 0, hdr_size = ZLIB_HDR_BASE;
uint8_t *out_buf = stream->next_out;
@ -1136,18 +1169,19 @@ uint32_t isal_write_zlib_header(struct isal_zstream *stream, struct isal_zlib_he
return ISAL_DECOMP_OK;
}
int isal_deflate_set_hufftables(struct isal_zstream *stream,
struct isal_hufftables *hufftables, int type)
int
isal_deflate_set_hufftables(struct isal_zstream *stream, struct isal_hufftables *hufftables,
int type)
{
if (stream->internal_state.state != ZSTATE_NEW_HDR)
return ISAL_INVALID_OPERATION;
switch (type) {
case IGZIP_HUFFTABLE_DEFAULT:
stream->hufftables = (struct isal_hufftables *)&hufftables_default;
stream->hufftables = (struct isal_hufftables *) &hufftables_default;
break;
case IGZIP_HUFFTABLE_STATIC:
stream->hufftables = (struct isal_hufftables *)&hufftables_static;
stream->hufftables = (struct isal_hufftables *) &hufftables_static;
break;
case IGZIP_HUFFTABLE_CUSTOM:
if (hufftables != NULL) {
@ -1161,11 +1195,12 @@ int isal_deflate_set_hufftables(struct isal_zstream *stream,
return COMP_OK;
}
void isal_deflate_stateless_init(struct isal_zstream *stream)
void
isal_deflate_stateless_init(struct isal_zstream *stream)
{
stream->total_in = 0;
stream->total_out = 0;
stream->hufftables = (struct isal_hufftables *)&hufftables_default;
stream->hufftables = (struct isal_hufftables *) &hufftables_default;
stream->level = 0;
stream->level_buf = NULL;
stream->level_buf_size = 0;
@ -1178,45 +1213,45 @@ void isal_deflate_stateless_init(struct isal_zstream *stream)
return;
}
void isal_deflate_hash(struct isal_zstream *stream, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash(struct isal_zstream *stream, uint8_t *dict, uint32_t dict_len)
{
/* Reset history to prevent out of bounds matches this works because
* dictionary must set at least 1 element in the history */
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint32_t hash_mask = stream->internal_state.hash_mask;
switch (stream->level) {
case 3:
memset(level_buf->lvl3.hash_table, -1, sizeof(level_buf->lvl3.hash_table));
isal_deflate_hash_lvl3(level_buf->lvl3.hash_table, hash_mask,
stream->total_in, dict, dict_len);
isal_deflate_hash_lvl3(level_buf->lvl3.hash_table, hash_mask, stream->total_in,
dict, dict_len);
break;
case 2:
memset(level_buf->lvl2.hash_table, -1, sizeof(level_buf->lvl2.hash_table));
isal_deflate_hash_lvl2(level_buf->lvl2.hash_table, hash_mask,
stream->total_in, dict, dict_len);
isal_deflate_hash_lvl2(level_buf->lvl2.hash_table, hash_mask, stream->total_in,
dict, dict_len);
break;
case 1:
memset(level_buf->lvl1.hash_table, -1, sizeof(level_buf->lvl1.hash_table));
isal_deflate_hash_lvl1(level_buf->lvl1.hash_table, hash_mask,
stream->total_in, dict, dict_len);
isal_deflate_hash_lvl1(level_buf->lvl1.hash_table, hash_mask, stream->total_in,
dict, dict_len);
break;
default:
memset(stream->internal_state.head, -1, sizeof(stream->internal_state.head));
isal_deflate_hash_lvl0(stream->internal_state.head, hash_mask,
stream->total_in, dict, dict_len);
isal_deflate_hash_lvl0(stream->internal_state.head, hash_mask, stream->total_in,
dict, dict_len);
}
stream->internal_state.has_hist = IGZIP_HIST;
}
int isal_deflate_process_dict(struct isal_zstream *stream, struct isal_dict *dict,
uint8_t * dict_data, uint32_t dict_len)
int
isal_deflate_process_dict(struct isal_zstream *stream, struct isal_dict *dict, uint8_t *dict_data,
uint32_t dict_len)
{
if ((dict == NULL)
|| (dict_len == 0)
|| (dict->level > ISAL_DEF_MAX_LEVEL))
if ((dict == NULL) || (dict_len == 0) || (dict->level > ISAL_DEF_MAX_LEVEL))
return ISAL_INVALID_STATE;
if (dict_len > IGZIP_HIST_SIZE) {
@ -1232,40 +1267,35 @@ int isal_deflate_process_dict(struct isal_zstream *stream, struct isal_dict *dic
switch (stream->level) {
case 3:
dict->hash_size = IGZIP_LVL3_HASH_SIZE;
isal_deflate_hash_lvl3(dict->hashtable, LVL3_HASH_MASK,
0, dict_data, dict_len);
isal_deflate_hash_lvl3(dict->hashtable, LVL3_HASH_MASK, 0, dict_data, dict_len);
break;
case 2:
dict->hash_size = IGZIP_LVL2_HASH_SIZE;
isal_deflate_hash_lvl2(dict->hashtable, LVL2_HASH_MASK,
0, dict_data, dict_len);
isal_deflate_hash_lvl2(dict->hashtable, LVL2_HASH_MASK, 0, dict_data, dict_len);
break;
case 1:
dict->hash_size = IGZIP_LVL1_HASH_SIZE;
isal_deflate_hash_lvl1(dict->hashtable, LVL1_HASH_MASK,
0, dict_data, dict_len);
isal_deflate_hash_lvl1(dict->hashtable, LVL1_HASH_MASK, 0, dict_data, dict_len);
break;
default:
dict->hash_size = IGZIP_LVL0_HASH_SIZE;
isal_deflate_hash_lvl0(dict->hashtable, LVL0_HASH_MASK,
0, dict_data, dict_len);
isal_deflate_hash_lvl0(dict->hashtable, LVL0_HASH_MASK, 0, dict_data, dict_len);
}
return COMP_OK;
}
int isal_deflate_reset_dict(struct isal_zstream *stream, struct isal_dict *dict)
int
isal_deflate_reset_dict(struct isal_zstream *stream, struct isal_dict *dict)
{
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
int ret;
if ((state->state != ZSTATE_NEW_HDR)
|| (state->b_bytes_processed != state->b_bytes_valid)
|| (dict->level != stream->level)
|| (dict->hist_size == 0)
|| (dict->hist_size > IGZIP_HIST_SIZE)
|| (dict->hash_size > IGZIP_LVL3_HASH_SIZE))
if ((state->state != ZSTATE_NEW_HDR) ||
(state->b_bytes_processed != state->b_bytes_valid) || (dict->level != stream->level) ||
(dict->hist_size == 0) || (dict->hist_size > IGZIP_HIST_SIZE) ||
(dict->hash_size > IGZIP_LVL3_HASH_SIZE))
return ISAL_INVALID_STATE;
ret = check_level_req(stream);
@ -1299,7 +1329,8 @@ int isal_deflate_reset_dict(struct isal_zstream *stream, struct isal_dict *dict)
return COMP_OK;
}
int isal_deflate_set_dict(struct isal_zstream *stream, uint8_t * dict, uint32_t dict_len)
int
isal_deflate_set_dict(struct isal_zstream *stream, uint8_t *dict, uint32_t dict_len)
{
struct isal_zstate *state = &stream->internal_state;
@ -1323,7 +1354,8 @@ int isal_deflate_set_dict(struct isal_zstream *stream, uint8_t * dict, uint32_t
return COMP_OK;
}
int isal_deflate_stateless(struct isal_zstream *stream)
int
isal_deflate_stateless(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
uint8_t *next_in = stream->next_in;
@ -1373,8 +1405,8 @@ int isal_deflate_stateless(struct isal_zstream *stream)
if (avail_in == 0)
stored_len = TYPE0_BLK_HDR_LEN;
else {
stored_len = TYPE0_BLK_HDR_LEN * ((avail_in + TYPE0_MAX_BLK_LEN - 1) /
TYPE0_MAX_BLK_LEN);
stored_len = TYPE0_BLK_HDR_LEN *
((avail_in + TYPE0_MAX_BLK_LEN - 1) / TYPE0_MAX_BLK_LEN);
stored_len += avail_in;
}
@ -1446,11 +1478,10 @@ int isal_deflate_stateless(struct isal_zstream *stream)
write_trailer(stream);
return COMP_OK;
}
static inline uint32_t get_hist_size(struct isal_zstream *stream, uint8_t * start_in,
int32_t buf_hist_start)
static inline uint32_t
get_hist_size(struct isal_zstream *stream, uint8_t *start_in, int32_t buf_hist_start)
{
struct isal_zstate *state = &stream->internal_state;
uint32_t history_size;
@ -1467,20 +1498,20 @@ static inline uint32_t get_hist_size(struct isal_zstream *stream, uint8_t * star
history_size = IGZIP_HIST_SIZE;
/* Calculate history required based on internal state */
if (state->state == ZSTATE_TYPE0_HDR
|| state->state == ZSTATE_TYPE0_BODY
|| state->state == ZSTATE_TMP_TYPE0_HDR || state->state == ZSTATE_TMP_TYPE0_BODY) {
if (state->state == ZSTATE_TYPE0_HDR || state->state == ZSTATE_TYPE0_BODY ||
state->state == ZSTATE_TMP_TYPE0_HDR || state->state == ZSTATE_TMP_TYPE0_BODY) {
if (stream->total_in - state->block_next > history_size) {
history_size = (stream->total_in - state->block_next);
}
} else if (stream->avail_in + buffered_size == 0
&& (stream->end_of_stream || stream->flush == FULL_FLUSH)) {
} else if (stream->avail_in + buffered_size == 0 &&
(stream->end_of_stream || stream->flush == FULL_FLUSH)) {
history_size = 0;
}
return history_size;
}
int isal_deflate(struct isal_zstream *stream)
int
isal_deflate(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
int ret = COMP_OK;
@ -1511,8 +1542,8 @@ int isal_deflate(struct isal_zstream *stream)
if (state->has_hist == IGZIP_NO_HIST) {
set_dist_mask(stream);
set_hash_mask(stream);
if (state->hash_mask > 2 * stream->avail_in
&& (stream->flush == FULL_FLUSH || stream->end_of_stream))
if (state->hash_mask > 2 * stream->avail_in &&
(stream->flush == FULL_FLUSH || stream->end_of_stream))
state->hash_mask = (1 << bsr(2 * stream->avail_in)) - 1;
stream->total_in -= buffered_size;
reset_match_history(stream);
@ -1580,10 +1611,10 @@ int isal_deflate(struct isal_zstream *stream)
/* If not much data is buffered and there is no need to
* flush the buffer, just continue rather than attempt
* to compress */
if (avail_in == 0 && buffered_size <= IGZIP_HIST_SIZE
&& stream->total_in - buffered_size - state->block_next <=
IGZIP_HIST_SIZE && !stream->end_of_stream
&& stream->flush == NO_FLUSH)
if (avail_in == 0 && buffered_size <= IGZIP_HIST_SIZE &&
stream->total_in - buffered_size - state->block_next <=
IGZIP_HIST_SIZE &&
!stream->end_of_stream && stream->flush == NO_FLUSH)
continue;
if (avail_in) {
@ -1630,8 +1661,8 @@ int isal_deflate(struct isal_zstream *stream)
in_size = stream->avail_in + buffered_size;
out_size = stream->total_out;
} while (internal && stream->avail_in > 0 && stream->avail_out > 0
&& (in_size_initial != in_size || out_size_initial != out_size));
} while (internal && stream->avail_in > 0 && stream->avail_out > 0 &&
(in_size_initial != in_size || out_size_initial != out_size));
/* Buffer history if data was pulled from the external buffer and future
* calls to deflate will be required */
@ -1670,14 +1701,14 @@ int isal_deflate(struct isal_zstream *stream)
stream->next_in += future_size;
stream->total_in += future_size;
stream->avail_in -= future_size;
}
return ret;
}
// Helper function to avoid code duplication.
static void _zlib_header_in_buffer(struct isal_zstream *stream, uint8_t * buffer)
static void
_zlib_header_in_buffer(struct isal_zstream *stream, uint8_t *buffer)
{
uint8_t hist_bits, info, level, cmf, flg;
uint8_t dict_flag = 0;
@ -1703,15 +1734,13 @@ static void _zlib_header_in_buffer(struct isal_zstream *stream, uint8_t * buffer
return;
}
static int write_stream_header_stateless(struct isal_zstream *stream)
static int
write_stream_header_stateless(struct isal_zstream *stream)
{
uint32_t hdr_bytes;
// Create a 10-byte buffer. Since the gzip header is almost fixed (9 of 10
// bytes are fixed) use it to initialize the buffer.
uint8_t buffer[10] = {
0x1f, 0x8b, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff
};
uint8_t buffer[10] = { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff };
uint32_t next_flag;
if (stream->internal_state.has_wrap_hdr)
@ -1743,17 +1772,15 @@ static int write_stream_header_stateless(struct isal_zstream *stream)
return COMP_OK;
}
static void write_stream_header(struct isal_zstream *stream)
static void
write_stream_header(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
int bytes_to_write;
uint32_t hdr_bytes;
// Create a 10-byte buffer. Since the gzip header is almost fixed (9 of 10
// bytes are fixed) use it to initialize the buffer.
uint8_t buffer[10] = {
0x1f, 0x8b, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff
};
uint8_t buffer[10] = { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff };
if (stream->internal_state.has_wrap_hdr)
return;
@ -1784,10 +1811,10 @@ static void write_stream_header(struct isal_zstream *stream)
stream->avail_out -= bytes_to_write;
stream->total_out += bytes_to_write;
stream->next_out += bytes_to_write;
}
static int write_deflate_header_stateless(struct isal_zstream *stream)
static int
write_deflate_header_stateless(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct isal_hufftables *hufftables = stream->hufftables;
@ -1825,7 +1852,8 @@ static int write_deflate_header_stateless(struct isal_zstream *stream)
return COMP_OK;
}
static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream)
static int
write_deflate_header_unaligned_stateless(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
struct isal_hufftables *hufftables = stream->hufftables;
@ -1863,14 +1891,12 @@ static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream)
write_bits(&state->bitbuf, header_bits, 32);
header_bits = load_le_u64(header_next);
}
bit_count =
(hufftables->deflate_hdr_count & 0x7) * 8 + hufftables->deflate_hdr_extra_bits;
bit_count = (hufftables->deflate_hdr_count & 0x7) * 8 + hufftables->deflate_hdr_extra_bits;
if (bit_count > MAX_BITBUF_BIT_WRITE) {
write_bits(&state->bitbuf, header_bits, MAX_BITBUF_BIT_WRITE);
header_bits >>= MAX_BITBUF_BIT_WRITE;
bit_count -= MAX_BITBUF_BIT_WRITE;
}
write_bits(&state->bitbuf, header_bits, bit_count);
@ -1891,9 +1917,9 @@ static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream)
}
/* Toggle end of stream only works when deflate header is aligned */
static void write_header(struct isal_zstream *stream, uint8_t * deflate_hdr,
uint32_t deflate_hdr_count, uint32_t extra_bits_count,
uint32_t next_state, uint32_t toggle_end_of_stream)
static void
write_header(struct isal_zstream *stream, uint8_t *deflate_hdr, uint32_t deflate_hdr_count,
uint32_t extra_bits_count, uint32_t next_state, uint32_t toggle_end_of_stream)
{
struct isal_zstate *state = &stream->internal_state;
uint32_t hdr_extra_bits = deflate_hdr[deflate_hdr_count];
@ -1954,10 +1980,10 @@ static void write_header(struct isal_zstream *stream, uint8_t * deflate_hdr,
stream->avail_out -= count;
stream->total_out += count;
}
}
static void write_trailer(struct isal_zstream *stream)
static void
write_trailer(struct isal_zstream *stream)
{
struct isal_zstate *state = &stream->internal_state;
unsigned int bytes = 0;
@ -2002,8 +2028,7 @@ static void write_trailer(struct isal_zstream *stream)
case IGZIP_GZIP:
case IGZIP_GZIP_NO_HDR:
if (stream->avail_out - bytes >= gzip_trl_bytes) {
store_le_u64(stream->next_out,
((uint64_t) stream->total_in << 32) | crc);
store_le_u64(stream->next_out, ((uint64_t) stream->total_in << 32) | crc);
stream->next_out += gzip_trl_bytes;
bytes += gzip_trl_bytes;
state->state = ZSTATE_END;

View File

@ -6,8 +6,8 @@
extern const struct isal_hufftables hufftables_default;
static inline void update_state(struct isal_zstream *stream, uint8_t * start_in,
uint8_t * next_in, uint8_t * end_in)
static inline void
update_state(struct isal_zstream *stream, uint8_t *start_in, uint8_t *next_in, uint8_t *end_in)
{
struct isal_zstate *state = &stream->internal_state;
uint32_t bytes_written;
@ -23,10 +23,10 @@ static inline void update_state(struct isal_zstream *stream, uint8_t * start_in,
stream->total_out += bytes_written;
stream->next_out += bytes_written;
stream->avail_out -= bytes_written;
}
void isal_deflate_body_base(struct isal_zstream *stream)
void
isal_deflate_body_base(struct isal_zstream *stream)
{
uint32_t literal, hash;
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
@ -84,8 +84,7 @@ void isal_deflate_body_base(struct isal_zstream *stream)
last_seen[hash] = (uint64_t) (next_hash - file_start);
}
get_len_code(stream->hufftables, match_length, &code,
&code_len);
get_len_code(stream->hufftables, match_length, &code, &code_len);
get_dist_code(stream->hufftables, dist, &code2, &code_len2);
code |= code2 << code_len;
@ -111,10 +110,10 @@ void isal_deflate_body_base(struct isal_zstream *stream)
state->state = ZSTATE_FLUSH_READ_BUFFER;
return;
}
void isal_deflate_finish_base(struct isal_zstream *stream)
void
isal_deflate_finish_base(struct isal_zstream *stream)
{
uint32_t literal = 0, hash;
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
@ -145,7 +144,8 @@ void isal_deflate_finish_base(struct isal_zstream *stream)
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
last_seen[hash] = (uint64_t) (next_in - file_start);
if (dist - 1 < hist_size) { /* The -1 are to handle the case when dist = 0 */
if (dist - 1 <
hist_size) { /* The -1 are to handle the case when dist = 0 */
match_length =
compare258(next_in - dist, next_in, end_in - next_in);
@ -167,8 +167,7 @@ void isal_deflate_finish_base(struct isal_zstream *stream)
get_len_code(stream->hufftables, match_length, &code,
&code_len);
get_dist_code(stream->hufftables, dist, &code2,
&code_len2);
get_dist_code(stream->hufftables, dist, &code2, &code_len2);
code |= code2 << code_len;
code_len += code_len2;
@ -184,7 +183,6 @@ void isal_deflate_finish_base(struct isal_zstream *stream)
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
write_bits(&state->bitbuf, code, code_len);
next_in++;
}
while (next_in < end_in) {
@ -197,7 +195,6 @@ void isal_deflate_finish_base(struct isal_zstream *stream)
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
write_bits(&state->bitbuf, code, code_len);
next_in++;
}
}
@ -217,8 +214,9 @@ void isal_deflate_finish_base(struct isal_zstream *stream)
return;
}
void isal_deflate_hash_base(uint16_t * hash_table, uint32_t hash_mask,
uint32_t current_index, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash_base(uint16_t *hash_table, uint32_t hash_mask, uint32_t current_index,
uint8_t *dict, uint32_t dict_len)
{
uint8_t *next_in = dict;
uint8_t *end_in = dict + dict_len - SHORTEST_MATCH;

View File

@ -32,122 +32,150 @@
#include "encode_df.h"
#include "igzip_level_buf_structs.h"
void isal_deflate_body_base(struct isal_zstream *stream);
void isal_deflate_finish_base(struct isal_zstream *stream);
void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream);
void icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream);
void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream);
void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream);
void isal_update_histogram_base(uint8_t * start_stream, int length,
void
isal_deflate_body_base(struct isal_zstream *stream);
void
isal_deflate_finish_base(struct isal_zstream *stream);
void
isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream);
void
icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream);
void
isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream);
void
isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream);
void
isal_update_histogram_base(uint8_t *start_stream, int length,
struct isal_huff_histogram *histogram);
struct deflate_icf *encode_deflate_icf_base(struct deflate_icf *next_in,
struct deflate_icf *end_in, struct BitBuf2 *bb,
struct deflate_icf *
encode_deflate_icf_base(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb,
struct hufftables_icf *hufftables);
uint32_t adler32_base(uint32_t init, const unsigned char *buf, uint64_t len);
int decode_huffman_code_block_stateless_base(struct inflate_state *s, uint8_t * start_out);
uint32_t
adler32_base(uint32_t init, const unsigned char *buf, uint64_t len);
int
decode_huffman_code_block_stateless_base(struct inflate_state *s, uint8_t *start_out);
extern void isal_deflate_hash_base(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
extern void
isal_deflate_hash_base(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t);
void set_long_icf_fg_base(uint8_t * next_in, uint8_t * end_in,
struct deflate_icf *match_lookup, struct level_buf *level_buf);
void gen_icf_map_h1_base(struct isal_zstream *stream,
struct deflate_icf *matches_icf_lookup, uint64_t input_size);
void
set_long_icf_fg_base(uint8_t *next_in, uint8_t *end_in, struct deflate_icf *match_lookup,
struct level_buf *level_buf);
void
gen_icf_map_h1_base(struct isal_zstream *stream, struct deflate_icf *matches_icf_lookup,
uint64_t input_size);
void isal_deflate_body(struct isal_zstream *stream)
void
isal_deflate_body(struct isal_zstream *stream)
{
isal_deflate_body_base(stream);
}
void isal_deflate_finish(struct isal_zstream *stream)
void
isal_deflate_finish(struct isal_zstream *stream)
{
isal_deflate_finish_base(stream);
}
void isal_deflate_icf_body_lvl1(struct isal_zstream *stream)
void
isal_deflate_icf_body_lvl1(struct isal_zstream *stream)
{
isal_deflate_icf_body_hash_hist_base(stream);
}
void isal_deflate_icf_body_lvl2(struct isal_zstream *stream)
void
isal_deflate_icf_body_lvl2(struct isal_zstream *stream)
{
isal_deflate_icf_body_hash_hist_base(stream);
}
void isal_deflate_icf_body_lvl3(struct isal_zstream *stream)
void
isal_deflate_icf_body_lvl3(struct isal_zstream *stream)
{
icf_body_hash1_fillgreedy_lazy(stream);
}
void isal_deflate_icf_finish_lvl1(struct isal_zstream *stream)
void
isal_deflate_icf_finish_lvl1(struct isal_zstream *stream)
{
isal_deflate_icf_finish_hash_hist_base(stream);
}
void isal_deflate_icf_finish_lvl2(struct isal_zstream *stream)
void
isal_deflate_icf_finish_lvl2(struct isal_zstream *stream)
{
isal_deflate_icf_finish_hash_hist_base(stream);
}
void isal_deflate_icf_finish_lvl3(struct isal_zstream *stream)
void
isal_deflate_icf_finish_lvl3(struct isal_zstream *stream)
{
isal_deflate_icf_finish_hash_map_base(stream);
}
void isal_update_histogram(uint8_t * start_stream, int length,
struct isal_huff_histogram *histogram)
void
isal_update_histogram(uint8_t *start_stream, int length, struct isal_huff_histogram *histogram)
{
isal_update_histogram_base(start_stream, length, histogram);
}
struct deflate_icf *encode_deflate_icf(struct deflate_icf *next_in,
struct deflate_icf *end_in, struct BitBuf2 *bb,
struct deflate_icf *
encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb,
struct hufftables_icf *hufftables)
{
return encode_deflate_icf_base(next_in, end_in, bb, hufftables);
}
uint32_t isal_adler32(uint32_t init, const unsigned char *buf, uint64_t len)
uint32_t
isal_adler32(uint32_t init, const unsigned char *buf, uint64_t len)
{
return adler32_base(init, buf, len);
}
int decode_huffman_code_block_stateless(struct inflate_state *s, uint8_t * start_out)
int
decode_huffman_code_block_stateless(struct inflate_state *s, uint8_t *start_out)
{
return decode_huffman_code_block_stateless_base(s, start_out);
}
void isal_deflate_hash_lvl0(uint16_t * hash_table, uint32_t hash_mask,
uint32_t current_index, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash_lvl0(uint16_t *hash_table, uint32_t hash_mask, uint32_t current_index,
uint8_t *dict, uint32_t dict_len)
{
isal_deflate_hash_base(hash_table, hash_mask, current_index, dict, dict_len);
}
void isal_deflate_hash_lvl1(uint16_t * hash_table, uint32_t hash_mask,
uint32_t current_index, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash_lvl1(uint16_t *hash_table, uint32_t hash_mask, uint32_t current_index,
uint8_t *dict, uint32_t dict_len)
{
isal_deflate_hash_base(hash_table, hash_mask, current_index, dict, dict_len);
}
void isal_deflate_hash_lvl2(uint16_t * hash_table, uint32_t hash_mask,
uint32_t current_index, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash_lvl2(uint16_t *hash_table, uint32_t hash_mask, uint32_t current_index,
uint8_t *dict, uint32_t dict_len)
{
isal_deflate_hash_base(hash_table, hash_mask, current_index, dict, dict_len);
}
void isal_deflate_hash_lvl3(uint16_t * hash_table, uint32_t hash_mask,
uint32_t current_index, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash_lvl3(uint16_t *hash_table, uint32_t hash_mask, uint32_t current_index,
uint8_t *dict, uint32_t dict_len)
{
isal_deflate_hash_base(hash_table, hash_mask, current_index, dict, dict_len);
}
void set_long_icf_fg(uint8_t * next_in, uint8_t * end_in,
struct deflate_icf *match_lookup, struct level_buf *level_buf)
void
set_long_icf_fg(uint8_t *next_in, uint8_t *end_in, struct deflate_icf *match_lookup,
struct level_buf *level_buf)
{
set_long_icf_fg_base(next_in, end_in, match_lookup, level_buf);
}
void gen_icf_map_lh1(struct isal_zstream *stream,
struct deflate_icf *matches_icf_lookup, uint64_t input_size)
void
gen_icf_map_lh1(struct isal_zstream *stream, struct deflate_icf *matches_icf_lookup,
uint64_t input_size)
{
gen_icf_map_h1_base(stream, matches_icf_lookup, input_size);
}

View File

@ -7,11 +7,13 @@
#include "test.h"
#include "huff_codes.h"
#define DICT_LEN 32*1024
#define DICT_LEN 32 * 1024
extern void isal_deflate_hash(struct isal_zstream *stream, uint8_t * dict, int dict_len);
extern void
isal_deflate_hash(struct isal_zstream *stream, uint8_t *dict, int dict_len);
void create_rand_data(uint8_t * data, uint32_t size)
void
create_rand_data(uint8_t *data, uint32_t size)
{
int i;
for (i = 0; i < size; i++) {
@ -19,7 +21,8 @@ void create_rand_data(uint8_t * data, uint32_t size)
}
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int time = BENCHMARK_TIME;
struct isal_zstream stream;
@ -34,7 +37,7 @@ int main(int argc, char *argv[])
BENCHMARK(&start, time, isal_deflate_hash(&stream, dict, dict_len));
printf("igzip_build_hash_table_perf: in_size=%u ", dict_len);
perf_print(start, (long long)dict_len);
perf_print(start, (long long) dict_len);
return 0;
}

View File

@ -6,7 +6,9 @@
#define MAX_ADLER_BUF (1 << 28)
#define ADLER_MOD 65521
uint32_t isal_adler32(uint32_t init_crc, const unsigned char *buf, uint64_t len);
uint32_t isal_adler32_bam1(uint32_t init_crc, const unsigned char *buf, uint64_t len);
uint32_t
isal_adler32(uint32_t init_crc, const unsigned char *buf, uint64_t len);
uint32_t
isal_adler32_bam1(uint32_t init_crc, const unsigned char *buf, uint64_t len);
#endif

View File

@ -33,14 +33,15 @@
#define BUF_SIZE 8192
#ifndef LEVEL
# define LEVEL 0
#define LEVEL 0
#else
# define LEVEL 1
#define LEVEL 1
#endif
struct isal_zstream stream;
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE];
FILE *in, *out;

View File

@ -91,10 +91,10 @@ int level_size_buf[10] = {
#endif
};
int usage(void)
int
usage(void)
{
fprintf(stderr,
"Usage: igzip_file_perf [options] <infile>\n"
fprintf(stderr, "Usage: igzip_file_perf [options] <infile>\n"
" -h help\n"
" -X use compression level X with 0 <= X <= 1\n"
" -b <size> input buffer size, 0 buffers all the input\n"
@ -106,10 +106,10 @@ int usage(void)
exit(0);
}
void deflate_perf(struct isal_zstream *stream, uint8_t * inbuf, size_t infile_size,
size_t inbuf_size, uint8_t * outbuf, size_t outbuf_size, int level,
uint8_t * level_buf, int level_size, uint32_t hist_bits, uint8_t * dictbuf,
size_t dictfile_size, struct isal_dict *dict_str,
void
deflate_perf(struct isal_zstream *stream, uint8_t *inbuf, size_t infile_size, size_t inbuf_size,
uint8_t *outbuf, size_t outbuf_size, int level, uint8_t *level_buf, int level_size,
uint32_t hist_bits, uint8_t *dictbuf, size_t dictfile_size, struct isal_dict *dict_str,
struct isal_hufftables *hufftables_custom)
{
int avail_in;
@ -146,7 +146,8 @@ void deflate_perf(struct isal_zstream *stream, uint8_t * inbuf, size_t infile_si
}
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
FILE *in = NULL, *out = NULL, *dict = NULL;
unsigned char *inbuf, *outbuf, *level_buf = NULL, *dictbuf = NULL;
@ -296,22 +297,21 @@ int main(int argc, char *argv[])
struct perf start;
if (time > 0) {
BENCHMARK(&start, time,
deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf,
outbuf_size, level, level_buf, level_size, hist_bits,
dictbuf, dictfile_size, &dict_str, NULL));
} else {
deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size,
level, level_buf, level_size, hist_bits, dictbuf,
dictfile_size, &dict_str, NULL);
dictfile_size, &dict_str, NULL));
} else {
deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size, level,
level_buf, level_size, hist_bits, dictbuf, dictfile_size, &dict_str,
NULL);
}
if (stream.avail_in != 0) {
fprintf(stderr, "Could not compress all of inbuf\n");
exit(0);
}
printf(" file %s - in_size=%lu out_size=%d ratio=%3.1f%%",
in_file_name, infile_size, stream.total_out,
100.0 * stream.total_out / infile_size);
printf(" file %s - in_size=%lu out_size=%d ratio=%3.1f%%", in_file_name, infile_size,
stream.total_out, 100.0 * stream.total_out / infile_size);
if (level == 0) {
memset(&histogram, 0, sizeof(histogram));
@ -319,9 +319,9 @@ int main(int argc, char *argv[])
isal_update_histogram(inbuf, infile_size, &histogram);
isal_create_hufftables(&hufftables_custom, &histogram);
deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size,
level, level_buf, level_size, hist_bits, dictbuf,
dictfile_size, &dict_str, &hufftables_custom);
deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size, level,
level_buf, level_size, hist_bits, dictbuf, dictfile_size, &dict_str,
&hufftables_custom);
printf(" ratio_custom=%3.1f%%", 100.0 * stream.total_out / infile_size);
}
@ -333,7 +333,7 @@ int main(int argc, char *argv[])
}
printf("igzip_file: ");
perf_print(start, (long long)infile_size);
perf_print(start, (long long) infile_size);
if (argc > 2 && out) {
printf("writing %s\n", out_file_name);

View File

@ -38,10 +38,11 @@
#define BUF_SIZE 1024
#define MIN_TEST_LOOPS 8
#ifndef RUN_MEM_SIZE
# define RUN_MEM_SIZE 2000000000
#define RUN_MEM_SIZE 2000000000
#endif
void print_histogram(struct isal_huff_histogram *histogram)
void
print_histogram(struct isal_huff_histogram *histogram)
{
int i;
printf("Lit Len histogram");
@ -65,7 +66,8 @@ void print_histogram(struct isal_huff_histogram *histogram)
printf("\n");
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
FILE *in;
unsigned char *inbuf;
@ -115,11 +117,10 @@ int main(int argc, char *argv[])
}
struct perf start;
BENCHMARK(&start, BENCHMARK_TIME,
isal_update_histogram(inbuf, infile_size, &histogram1));
BENCHMARK(&start, BENCHMARK_TIME, isal_update_histogram(inbuf, infile_size, &histogram1));
printf(" file %s - in_size=%lu\n", argv[1], infile_size);
printf("igzip_hist_file: ");
perf_print(start, (long long)infile_size);
perf_print(start, (long long) infile_size);
fclose(in);
fflush(0);

View File

@ -6,20 +6,20 @@
#include "igzip_level_buf_structs.h"
#include "unaligned.h"
static inline void write_deflate_icf(struct deflate_icf *icf, uint32_t lit_len,
uint32_t lit_dist, uint32_t extra_bits)
static inline void
write_deflate_icf(struct deflate_icf *icf, uint32_t lit_len, uint32_t lit_dist, uint32_t extra_bits)
{
icf->lit_len = lit_len;
icf->lit_dist = lit_dist;
icf->dist_extra = extra_bits;
}
static inline void update_state(struct isal_zstream *stream, uint8_t * start_in,
uint8_t * next_in, uint8_t * end_in,
static inline void
update_state(struct isal_zstream *stream, uint8_t *start_in, uint8_t *next_in, uint8_t *end_in,
struct deflate_icf *start_out, struct deflate_icf *next_out,
struct deflate_icf *end_out)
{
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
if (next_in - start_in > 0)
stream->internal_state.has_hist = IGZIP_HIST;
@ -33,7 +33,8 @@ static inline void update_state(struct isal_zstream *stream, uint8_t * start_in,
level_buf->icf_buf_avail_out = end_out - next_out;
}
void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream)
void
isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream)
{
uint32_t literal, hash;
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
@ -42,7 +43,7 @@ void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream)
uint32_t dist;
uint32_t code, code2, extra_bits;
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint16_t *last_seen = level_buf->hash_hist.hash_table;
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
uint32_t hist_size = state->dist_mask;
@ -58,9 +59,8 @@ void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream)
end_in = start_in + stream->avail_in;
next_in = start_in;
start_out = ((struct level_buf *)stream->level_buf)->icf_buf_next;
end_out =
start_out + ((struct level_buf *)stream->level_buf)->icf_buf_avail_out /
start_out = ((struct level_buf *) stream->level_buf)->icf_buf_next;
end_out = start_out + ((struct level_buf *) stream->level_buf)->icf_buf_avail_out /
sizeof(struct deflate_icf);
next_out = start_out;
@ -127,10 +127,10 @@ void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream)
state->state = ZSTATE_FLUSH_READ_BUFFER;
return;
}
void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
void
isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
{
uint32_t literal = 0, hash;
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
@ -139,7 +139,7 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
uint32_t dist;
uint32_t code, code2, extra_bits;
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint16_t *last_seen = level_buf->hash_hist.hash_table;
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
uint32_t hist_size = state->dist_mask;
@ -149,8 +149,8 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
end_in = start_in + stream->avail_in;
next_in = start_in;
start_out = ((struct level_buf *)stream->level_buf)->icf_buf_next;
end_out = start_out + ((struct level_buf *)stream->level_buf)->icf_buf_avail_out /
start_out = ((struct level_buf *) stream->level_buf)->icf_buf_next;
end_out = start_out + ((struct level_buf *) stream->level_buf)->icf_buf_avail_out /
sizeof(struct deflate_icf);
next_out = start_out;
@ -211,7 +211,6 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
next_out++;
next_in++;
}
while (next_in < end_in) {
@ -228,7 +227,6 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
next_out++;
next_in++;
}
if (next_in == end_in) {
@ -241,7 +239,8 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream)
return;
}
void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream)
void
isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream)
{
uint32_t literal = 0, hash;
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
@ -250,7 +249,7 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream)
uint32_t dist;
uint32_t code, code2, extra_bits;
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint16_t *last_seen = level_buf->hash_map.hash_table;
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
uint32_t hist_size = state->dist_mask;
@ -321,7 +320,6 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream)
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
next_out++;
next_in++;
}
while (next_in < end_in) {
@ -338,7 +336,6 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream)
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
next_out++;
next_in++;
}
if (next_in == end_in) {
@ -351,8 +348,9 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream)
return;
}
void isal_deflate_hash_mad_base(uint16_t * hash_table, uint32_t hash_mask,
uint32_t current_index, uint8_t * dict, uint32_t dict_len)
void
isal_deflate_hash_mad_base(uint16_t *hash_table, uint32_t hash_mask, uint32_t current_index,
uint8_t *dict, uint32_t dict_len)
{
uint8_t *next_in = dict;
uint8_t *end_in = dict + dict_len - SHORTEST_MATCH;

View File

@ -3,40 +3,45 @@
#include "encode_df.h"
#include "igzip_level_buf_structs.h"
extern uint64_t gen_icf_map_lh1(struct isal_zstream *, struct deflate_icf *, uint32_t);
extern void set_long_icf_fg(uint8_t *, uint64_t, uint64_t, struct deflate_icf *);
extern void isal_deflate_icf_body_lvl1(struct isal_zstream *);
extern void isal_deflate_icf_body_lvl2(struct isal_zstream *);
extern void isal_deflate_icf_body_lvl3(struct isal_zstream *);
extern uint64_t
gen_icf_map_lh1(struct isal_zstream *, struct deflate_icf *, uint32_t);
extern void
set_long_icf_fg(uint8_t *, uint64_t, uint64_t, struct deflate_icf *);
extern void
isal_deflate_icf_body_lvl1(struct isal_zstream *);
extern void
isal_deflate_icf_body_lvl2(struct isal_zstream *);
extern void
isal_deflate_icf_body_lvl3(struct isal_zstream *);
/*
*************************************************************
* Helper functions
************************************************************
* Helper functions
************************************************************
*/
static inline void write_deflate_icf(struct deflate_icf *icf, uint32_t lit_len,
uint32_t lit_dist, uint32_t extra_bits)
static inline void
write_deflate_icf(struct deflate_icf *icf, uint32_t lit_len, uint32_t lit_dist, uint32_t extra_bits)
{
/* icf->lit_len = lit_len; */
/* icf->lit_dist = lit_dist; */
/* icf->dist_extra = extra_bits; */
store_native_u32((uint8_t *) icf, lit_len | (lit_dist << LIT_LEN_BIT_COUNT)
| (extra_bits << (LIT_LEN_BIT_COUNT + DIST_LIT_BIT_COUNT)));
store_native_u32((uint8_t *) icf,
lit_len | (lit_dist << LIT_LEN_BIT_COUNT) |
(extra_bits << (LIT_LEN_BIT_COUNT + DIST_LIT_BIT_COUNT)));
}
void set_long_icf_fg_base(uint8_t * next_in, uint64_t processed, uint64_t input_size,
void
set_long_icf_fg_base(uint8_t *next_in, uint64_t processed, uint64_t input_size,
struct deflate_icf *match_lookup)
{
uint8_t *end_processed = next_in + processed;
uint8_t *end_in = next_in + input_size;
uint32_t dist_code, dist_extra, dist, len;
uint32_t match_len;
uint32_t dist_start[] = {
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
uint32_t dist_start[] = { 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, 0x0000, 0x0000
};
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 };
if (end_in > end_processed + ISAL_LOOK_AHEAD)
end_in = end_processed + ISAL_LOOK_AHEAD;
@ -47,11 +52,12 @@ void set_long_icf_fg_base(uint8_t * next_in, uint64_t processed, uint64_t input_
dist = dist_start[dist_code] + dist_extra;
len = match_lookup->lit_len;
if (len >= 8 + LEN_OFFSET) {
match_len = compare((next_in + 8) - dist, next_in + 8,
end_in - (next_in + 8)) + LEN_OFFSET + 8;
match_len =
compare((next_in + 8) - dist, next_in + 8, end_in - (next_in + 8)) +
LEN_OFFSET + 8;
while (match_len > match_lookup->lit_len
&& match_len >= LEN_OFFSET + SHORTEST_MATCH) {
while (match_len > match_lookup->lit_len &&
match_len >= LEN_OFFSET + SHORTEST_MATCH) {
write_deflate_icf(match_lookup,
match_len > LEN_MAX ? LEN_MAX : match_len,
dist_code, dist_extra);
@ -68,11 +74,12 @@ void set_long_icf_fg_base(uint8_t * next_in, uint64_t processed, uint64_t input_
/*
*************************************************************
* Methods for generating one pass match lookup table
************************************************************
* Methods for generating one pass match lookup table
************************************************************
*/
uint64_t gen_icf_map_h1_base(struct isal_zstream *stream,
struct deflate_icf *matches_icf_lookup, uint64_t input_size)
uint64_t
gen_icf_map_h1_base(struct isal_zstream *stream, struct deflate_icf *matches_icf_lookup,
uint64_t input_size)
{
uint32_t dist, len, extra_bits;
@ -81,7 +88,7 @@ uint64_t gen_icf_map_h1_base(struct isal_zstream *stream,
uint32_t hash;
uint64_t next_bytes, match_bytes;
uint64_t match;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint16_t *hash_table = level_buf->hash_map.hash_table;
uint32_t hist_size = stream->internal_state.dist_mask;
uint32_t hash_mask = stream->internal_state.hash_mask;
@ -130,21 +137,20 @@ uint64_t gen_icf_map_h1_base(struct isal_zstream *stream,
/*
*************************************************************
* One pass methods for parsing provided match lookup table
************************************************************
* One pass methods for parsing provided match lookup table
************************************************************
*/
static struct deflate_icf *compress_icf_map_g(struct isal_zstream *stream,
struct deflate_icf *matches_next,
static struct deflate_icf *
compress_icf_map_g(struct isal_zstream *stream, struct deflate_icf *matches_next,
struct deflate_icf *matches_end)
{
uint32_t lit_len, lit_len2, dist;
uint64_t code;
struct isal_zstate *state = &stream->internal_state;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
struct deflate_icf *matches_start = matches_next;
struct deflate_icf *icf_buf_end =
level_buf->icf_buf_next +
level_buf->icf_buf_avail_out / sizeof(struct deflate_icf);
level_buf->icf_buf_next + level_buf->icf_buf_avail_out / sizeof(struct deflate_icf);
while (matches_next + 1 < matches_end && level_buf->icf_buf_next + 1 < icf_buf_end) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@ -222,32 +228,33 @@ static struct deflate_icf *compress_icf_map_g(struct isal_zstream *stream,
}
return matches_next;
}
/*
*************************************************************
* Compression functions combining different methods
************************************************************
* Compression functions combining different methods
************************************************************
*/
static inline void icf_body_next_state(struct isal_zstream *stream)
static inline void
icf_body_next_state(struct isal_zstream *stream)
{
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
struct isal_zstate *state = &stream->internal_state;
if (level_buf->icf_buf_avail_out <= 0)
state->state = ZSTATE_CREATE_HDR;
else if (stream->avail_in <= ISAL_LOOK_AHEAD
&& (stream->end_of_stream || stream->flush != NO_FLUSH))
else if (stream->avail_in <= ISAL_LOOK_AHEAD &&
(stream->end_of_stream || stream->flush != NO_FLUSH))
state->state = ZSTATE_FLUSH_READ_BUFFER;
}
void icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream)
void
icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream)
{
struct deflate_icf *matches_icf, *matches_next_icf, *matches_end_icf;
struct deflate_icf *matches_icf_lookup;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint32_t input_size, processed;
matches_icf = level_buf->hash_map.matches;
@ -282,11 +289,12 @@ void icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream)
icf_body_next_state(stream);
}
void icf_body_lazyhash1_fillgreedy_greedy(struct isal_zstream *stream)
void
icf_body_lazyhash1_fillgreedy_greedy(struct isal_zstream *stream)
{
struct deflate_icf *matches_icf, *matches_next_icf, *matches_end_icf;
struct deflate_icf *matches_icf_lookup;
struct level_buf *level_buf = (struct level_buf *)stream->level_buf;
struct level_buf *level_buf = (struct level_buf *) stream->level_buf;
uint32_t input_size, processed;
matches_icf = level_buf->hash_map.matches;
@ -321,7 +329,8 @@ void icf_body_lazyhash1_fillgreedy_greedy(struct isal_zstream *stream)
icf_body_next_state(stream);
}
void isal_deflate_icf_body(struct isal_zstream *stream)
void
isal_deflate_icf_body(struct isal_zstream *stream)
{
switch (stream->level) {
case 3:

View File

@ -39,7 +39,8 @@
#include "static_inflate.h"
#endif
extern int decode_huffman_code_block_stateless(struct inflate_state *, uint8_t * start_out);
extern int
decode_huffman_code_block_stateless(struct inflate_state *, uint8_t *start_out);
extern struct isal_hufftables hufftables_default; /* For known header detection */
#define LARGE_SHORT_SYM_LEN 25
@ -95,41 +96,34 @@ struct rfc1951_tables {
uint32_t dist_start[32];
uint8_t len_extra_bit_count[32];
uint16_t len_start[32];
};
/* The following tables are based on the tables in the deflate standard,
* RFC 1951 page 11. */
static struct rfc1951_tables rfc_lookup_table = {
.dist_extra_bit_count = {
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02,
0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06,
0x07, 0x07, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a,
0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x00, 0x00},
.dist_extra_bit_count = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04,
0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x09,
0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x00, 0x00 },
.dist_start = {
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
.dist_start = { 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, 0x0000, 0x0000},
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 },
.len_extra_bit_count = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00},
.len_extra_bit_count = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04,
0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00 },
.len_start = {
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
.len_start = { 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
0x000b, 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f,
0x0023, 0x002b, 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073,
0x0083, 0x00a3, 0x00c3, 0x00e3, 0x0102, 0x0103, 0x0000, 0x0000}
0x0083, 0x00a3, 0x00c3, 0x00e3, 0x0102, 0x0103, 0x0000, 0x0000 }
};
/*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. */
static 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;
@ -137,7 +131,8 @@ static void inline byte_copy(uint8_t * dest, uint64_t lookback_distance, int rep
*dest++ = *src++;
}
static void update_checksum(struct inflate_state *state, uint8_t * start_in, uint64_t length)
static void
update_checksum(struct inflate_state *state, uint8_t *start_in, uint64_t length)
{
switch (state->crc_flag) {
case ISAL_GZIP:
@ -153,45 +148,32 @@ static void update_checksum(struct inflate_state *state, uint8_t * start_in, uin
}
}
static void finalize_adler32(struct inflate_state *state)
static void
finalize_adler32(struct inflate_state *state)
{
state->crc = (state->crc & 0xffff0000) | (((state->crc & 0xffff) + 1) % ADLER_MOD);
}
static const uint8_t bitrev_table[] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70,
0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8,
0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34,
0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc,
0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52,
0xd2, 0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a,
0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16,
0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61,
0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9,
0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25,
0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd,
0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x03, 0x83, 0x43,
0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0x0b, 0x8b,
0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07,
0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f,
0xff,
};
@ -235,13 +217,11 @@ static void inline inflate_in_load(struct inflate_state *state, int min_required
state->next_in++;
state->avail_in--;
state->read_in_length += 8;
}
}
}
static uint64_t inline inflate_in_read_bits_unsafe(struct inflate_state *state,
uint8_t bit_count)
static uint64_t inline inflate_in_read_bits_unsafe(struct inflate_state *state, uint8_t bit_count)
{
uint64_t ret;
@ -266,8 +246,7 @@ static void inline write_huff_code(struct huff_code *huff_code, uint32_t code, u
huff_code->code_and_length = code | length << 24;
}
static int inline set_codes(struct huff_code *huff_code_table, int table_length,
uint16_t * count)
static int inline set_codes(struct huff_code *huff_code_table, int table_length, uint16_t *count)
{
uint32_t max, code, length;
uint32_t next_code[MAX_HUFF_TREE_DEPTH + 1];
@ -300,10 +279,8 @@ static int inline set_codes(struct huff_code *huff_code_table, int table_length,
}
static int inline set_and_expand_lit_len_huffcode(struct huff_code *lit_len_huff,
uint32_t table_length,
uint16_t * count,
uint16_t * expand_count,
uint32_t * code_list)
uint32_t table_length, uint16_t *count,
uint16_t *expand_count, uint32_t *code_list)
{
int len_sym, len_size, extra_count, extra;
uint32_t count_total, count_tmp;
@ -401,18 +378,15 @@ static int inline set_and_expand_lit_len_huffcode(struct huff_code *lit_len_huff
return 0;
}
static int inline index_to_sym(int index)
{
return (index != 513) ? index : 512;
}
static int inline index_to_sym(int index) { return (index != 513) ? index : 512; }
/* 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 */
static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *result,
struct huff_code *huff_code_table,
uint32_t table_length, uint16_t * count_total,
uint32_t * code_list, uint32_t multisym)
static void
make_inflate_huff_code_lit_len(struct inflate_huff_code_large *result,
struct huff_code *huff_code_table, uint32_t table_length,
uint16_t *count_total, uint32_t *code_list, uint32_t multisym)
{
int i, j;
uint16_t code = 0;
@ -460,8 +434,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
copy_size *= 2;
/* Encode code singletons */
for (index1 = count_total[last_length];
index1 < count_total[last_length + 1]; index1++) {
for (index1 = count_total[last_length]; index1 < count_total[last_length + 1];
index1++) {
sym1_index = code_list[index1];
sym1 = index_to_sym(sym1_index);
sym1_len = huff_code_table[sym1_index].length;
@ -471,8 +445,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
continue;
/* Set new codes */
short_code_lookup[sym1_code] =
sym1 | sym1_len << LARGE_SHORT_CODE_LEN_OFFSET |
short_code_lookup[sym1_code] = sym1 |
sym1_len << LARGE_SHORT_CODE_LEN_OFFSET |
(1 << LARGE_SYM_COUNT_OFFSET);
}
@ -495,8 +469,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
}
sym2_len = last_length - sym1_len;
for (index2 = count_total[sym2_len];
index2 < count_total[sym2_len + 1]; index2++) {
for (index2 = count_total[sym2_len]; index2 < count_total[sym2_len + 1];
index2++) {
sym2_index = code_list[index2];
sym2 = index_to_sym(sym2_index);
@ -509,8 +483,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
code_length = sym1_len + sym2_len;
short_code_lookup[code] =
sym1 | (sym2 << 8) |
(code_length << LARGE_SHORT_CODE_LEN_OFFSET)
| (2 << LARGE_SYM_COUNT_OFFSET);
(code_length << LARGE_SHORT_CODE_LEN_OFFSET) |
(2 << LARGE_SYM_COUNT_OFFSET);
}
}
@ -564,14 +538,11 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
code_length = sym1_len + sym2_len + sym3_len;
short_code_lookup[code] =
sym1 | (sym2 << 8) | sym3 << 16 |
(code_length << LARGE_SHORT_CODE_LEN_OFFSET)
| (3 << LARGE_SYM_COUNT_OFFSET);
}
(code_length << LARGE_SHORT_CODE_LEN_OFFSET) |
(3 << LARGE_SYM_COUNT_OFFSET);
}
}
}
}
index1 = count_total[ISAL_DECODE_LONG_BITS + 1];
@ -585,9 +556,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
continue;
max_length = huff_code_table[long_code_list[i]].length;
first_bits =
huff_code_table[long_code_list[i]].code_and_extra
& ((1 << ISAL_DECODE_LONG_BITS) - 1);
first_bits = huff_code_table[long_code_list[i]].code_and_extra &
((1 << ISAL_DECODE_LONG_BITS) - 1);
temp_code_list[0] = long_code_list[i];
temp_code_length = 1;
@ -620,17 +590,17 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul
sym1 | (sym1_len << LARGE_LONG_CODE_LEN_OFFSET);
}
huff_code_table[sym1_index].code_and_extra = INVALID_CODE;
}
result->short_code_lookup[first_bits] = long_code_lookup_length |
(max_length << LARGE_SHORT_MAX_LEN_OFFSET) | LARGE_FLAG_BIT;
(max_length << LARGE_SHORT_MAX_LEN_OFFSET) |
LARGE_FLAG_BIT;
long_code_lookup_length += 1 << (max_length - ISAL_DECODE_LONG_BITS);
}
}
static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *result,
struct huff_code *huff_code_table,
uint32_t table_length, uint16_t * count,
uint32_t table_length, uint16_t *count,
uint32_t max_symbol)
{
int i, j, k;
@ -705,7 +675,8 @@ static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *r
* address are the same as the code for the current symbol. The
* first 9 bits are the code, bits 14:10 are the code length,
* bit 15 is a flag representing this is a symbol*/
short_code_lookup[huff_code_table[i].code] = i |
short_code_lookup[huff_code_table[i].code] =
i |
rfc_lookup_table.dist_extra_bit_count[i] << DIST_SYM_EXTRA_OFFSET |
(huff_code_table[i].length) << SMALL_SHORT_CODE_LEN_OFFSET;
}
@ -722,9 +693,8 @@ static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *r
continue;
max_length = huff_code_table[long_code_list[i]].length;
first_bits =
huff_code_table[long_code_list[i]].code
& ((1 << ISAL_DECODE_SHORT_BITS) - 1);
first_bits = huff_code_table[long_code_list[i]].code &
((1 << ISAL_DECODE_SHORT_BITS) - 1);
temp_code_list[0] = long_code_list[i];
temp_code_length = 1;
@ -758,22 +728,22 @@ static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *r
}
result->long_code_lookup[long_code_lookup_length + long_bits] =
sym |
rfc_lookup_table.dist_extra_bit_count[sym] <<
DIST_SYM_EXTRA_OFFSET |
rfc_lookup_table.dist_extra_bit_count[sym]
<< DIST_SYM_EXTRA_OFFSET |
(code_length << SMALL_LONG_CODE_LEN_OFFSET);
}
huff_code_table[sym].code = 0xFFFF;
}
result->short_code_lookup[first_bits] = long_code_lookup_length |
(max_length << SMALL_SHORT_CODE_LEN_OFFSET) | SMALL_FLAG_BIT;
result->short_code_lookup[first_bits] =
long_code_lookup_length | (max_length << SMALL_SHORT_CODE_LEN_OFFSET) |
SMALL_FLAG_BIT;
long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS);
}
}
static void inline make_inflate_huff_code_header(struct inflate_huff_code_small *result,
struct huff_code *huff_code_table,
uint32_t table_length, uint16_t * count,
uint32_t table_length, uint16_t *count,
uint32_t max_symbol)
{
int i, j, k;
@ -858,9 +828,8 @@ static void inline make_inflate_huff_code_header(struct inflate_huff_code_small
continue;
max_length = huff_code_table[long_code_list[i]].length;
first_bits =
huff_code_table[long_code_list[i]].code
& ((1 << ISAL_DECODE_SHORT_BITS) - 1);
first_bits = huff_code_table[long_code_list[i]].code &
((1 << ISAL_DECODE_SHORT_BITS) - 1);
temp_code_list[0] = long_code_list[i];
temp_code_length = 1;
@ -891,14 +860,15 @@ static void inline make_inflate_huff_code_header(struct inflate_huff_code_small
}
huff_code_table[temp_code_list[j]].code = 0xFFFF;
}
result->short_code_lookup[first_bits] = long_code_lookup_length |
(max_length << SMALL_SHORT_CODE_LEN_OFFSET) | SMALL_FLAG_BIT;
result->short_code_lookup[first_bits] =
long_code_lookup_length | (max_length << SMALL_SHORT_CODE_LEN_OFFSET) |
SMALL_FLAG_BIT;
long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS);
}
}
static int header_matches_pregen(struct inflate_state *state)
static int
header_matches_pregen(struct inflate_state *state)
{
#ifndef ISAL_STATIC_INFLATE_TABLE
return 0;
@ -958,7 +928,8 @@ static int header_matches_pregen(struct inflate_state *state)
#endif // ISAL_STATIC_INFLATE_TABLE
}
static int setup_pregen_header(struct inflate_state *state)
static int
setup_pregen_header(struct inflate_state *state)
{
#ifdef ISAL_STATIC_INFLATE_TABLE
memcpy(&state->lit_huff_code, &pregen_lit_huff_code, sizeof(pregen_lit_huff_code));
@ -978,8 +949,9 @@ static int inline setup_static_header(struct inflate_state *state)
#else
#ifndef NO_STATIC_INFLATE_H
# warning "Defaulting to static inflate table fallback."
# warning "For best performance, run generate_static_inflate, replace static_inflate.h, and recompile"
#warning "Defaulting to static inflate table fallback."
#warning \
"For best performance, run generate_static_inflate, replace static_inflate.h, and recompile"
#endif
int i;
struct huff_code lit_code[LIT_LEN_ELEMS];
@ -987,17 +959,14 @@ static int inline setup_static_header(struct inflate_state *state)
uint32_t multisym = SINGLE_SYM_FLAG, max_dist = DIST_LEN;
/* These tables are based on the static huffman tree described in RFC
* 1951 */
uint16_t lit_count[MAX_LIT_LEN_COUNT] = {
0, 0, 0, 0, 0, 0, 0, 24, 152, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
uint16_t lit_count[MAX_LIT_LEN_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 24, 152, 112, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
uint16_t lit_expand_count[MAX_LIT_LEN_COUNT] = {
0, 0, 0, 0, 0, 0, 0, -15, 1, 16, 32, 48, 16, 128, 0, 0, 0, 0, 0, 0, 0, 0
};
uint16_t dist_count[16] = {
0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
uint32_t code_list[LIT_LEN_ELEMS + 2]; /* The +2 is for the extra codes in the static header */
uint16_t lit_expand_count[MAX_LIT_LEN_COUNT] = { 0, 0, 0, 0, 0, 0, 0, -15, 1, 16, 32,
48, 16, 128, 0, 0, 0, 0, 0, 0, 0, 0 };
uint16_t dist_count[16] = { 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
uint32_t code_list[LIT_LEN_ELEMS +
2]; /* The +2 is for the extra codes in the static header */
/* These for loops set the code lengths for the static literal/length
* and distance codes defined in the deflate standard RFC 1951 */
for (i = 0; i < 144; i++)
@ -1020,14 +989,14 @@ static int inline setup_static_header(struct inflate_state *state)
set_codes(dist_code, DIST_LEN + 2, dist_count);
make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_code, LIT_LEN_ELEMS,
lit_count, code_list, multisym);
make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_code, LIT_LEN_ELEMS, lit_count,
code_list, multisym);
if (state->hist_bits && state->hist_bits < 15)
max_dist = 2 * state->hist_bits;
make_inflate_huff_code_dist(&state->dist_huff_code, dist_code, DIST_LEN + 2,
dist_count, max_dist);
make_inflate_huff_code_dist(&state->dist_huff_code, dist_code, DIST_LEN + 2, dist_count,
max_dist);
#endif
state->block_state = ISAL_BLOCK_CODED;
@ -1036,7 +1005,7 @@ static 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 and returns the value in next_lits and sym_count */
static void inline decode_next_lit_len(uint32_t * next_lits, uint32_t * sym_count,
static void inline decode_next_lit_len(uint32_t *next_lits, uint32_t *sym_count,
struct inflate_state *state,
struct inflate_huff_code_large *huff_code)
{
@ -1077,8 +1046,7 @@ static void inline decode_next_lit_len(uint32_t * next_lits, uint32_t * sym_coun
bit_mask = next_sym >> LARGE_SHORT_MAX_LEN_OFFSET;
bit_mask = (1 << bit_mask) - 1;
next_bits = state->read_in & bit_mask;
next_sym =
huff_code->long_code_lookup[(next_sym & LARGE_SHORT_SYM_MASK) +
next_sym = huff_code->long_code_lookup[(next_sym & LARGE_SHORT_SYM_MASK) +
(next_bits >> ISAL_DECODE_LONG_BITS)];
bit_count = next_sym >> LARGE_LONG_CODE_LEN_OFFSET;
state->read_in >>= bit_count;
@ -1133,8 +1101,7 @@ static uint16_t inline decode_next_dist(struct inflate_state *state,
bit_mask = (next_sym - SMALL_FLAG_BIT) >> SMALL_SHORT_CODE_LEN_OFFSET;
bit_mask = (1 << bit_mask) - 1;
next_bits = state->read_in & bit_mask;
next_sym =
huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) +
next_sym = huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) +
(next_bits >> ISAL_DECODE_SHORT_BITS)];
bit_count = next_sym >> SMALL_LONG_CODE_LEN_OFFSET;
state->read_in >>= bit_count;
@ -1188,14 +1155,12 @@ static uint16_t inline decode_next_header(struct inflate_state *state,
bit_mask = (next_sym - SMALL_FLAG_BIT) >> SMALL_SHORT_CODE_LEN_OFFSET;
bit_mask = (1 << bit_mask) - 1;
next_bits = state->read_in & bit_mask;
next_sym =
huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) +
next_sym = huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) +
(next_bits >> ISAL_DECODE_SHORT_BITS)];
bit_count = next_sym >> SMALL_LONG_CODE_LEN_OFFSET;
state->read_in >>= bit_count;
state->read_in_length -= bit_count;
return next_sym & SMALL_LONG_SYM_MASK;
}
}
@ -1209,8 +1174,8 @@ static int inline setup_dynamic_header(struct inflate_state *state)
struct huff_code *previous = NULL, *current, *end, rep_code;
struct inflate_huff_code_small inflate_code_huff;
uint64_t hclen, hdist, hlit;
uint16_t code_count[16], lit_count[MAX_LIT_LEN_COUNT],
lit_expand_count[MAX_LIT_LEN_COUNT], dist_count[16];
uint16_t code_count[16], lit_count[MAX_LIT_LEN_COUNT], lit_expand_count[MAX_LIT_LEN_COUNT],
dist_count[16];
uint16_t *count;
uint16_t symbol;
uint32_t multisym = DEFAULT_SYM_FLAG, length, max_dist = DIST_LEN;
@ -1218,17 +1183,18 @@ static int inline setup_dynamic_header(struct inflate_state *state)
uint64_t flag = 0;
int extra_count;
uint32_t code_list[LIT_LEN_ELEMS + 2]; /* The +2 is for the extra codes in the static header */
uint32_t code_list[LIT_LEN_ELEMS +
2]; /* The +2 is for the extra codes in the static header */
/* This order is defined in RFC 1951 page 13 */
const uint8_t code_length_order[CODE_LEN_CODES] = {
0x10, 0x11, 0x12, 0x00, 0x08, 0x07, 0x09, 0x06,
0x0a, 0x05, 0x0b, 0x04, 0x0c, 0x03, 0x0d, 0x02, 0x0e, 0x01, 0x0f
};
const uint8_t code_length_order[CODE_LEN_CODES] = { 0x10, 0x11, 0x12, 0x00, 0x08,
0x07, 0x09, 0x06, 0x0a, 0x05,
0x0b, 0x04, 0x0c, 0x03, 0x0d,
0x02, 0x0e, 0x01, 0x0f };
/* If you are given a whole header and it matches the pregen header */
if (state->avail_in > (hufftables_default.deflate_hdr_count + sizeof(uint64_t))
&& header_matches_pregen(state))
if (state->avail_in > (hufftables_default.deflate_hdr_count + sizeof(uint64_t)) &&
header_matches_pregen(state))
return setup_pregen_header(state);
if (state->bfinal && state->avail_in <= SINGLE_SYM_THRESH) {
@ -1281,8 +1247,8 @@ static int inline setup_dynamic_header(struct inflate_state *state)
if (!flag || set_codes(code_huff, CODE_LEN_CODES, code_count))
return ISAL_INVALID_BLOCK;
make_inflate_huff_code_header(&inflate_code_huff, code_huff, CODE_LEN_CODES,
code_count, CODE_LEN_CODES);
make_inflate_huff_code_header(&inflate_code_huff, code_huff, CODE_LEN_CODES, code_count,
CODE_LEN_CODES);
/* Decode the lit/len and dist huffman codes using the code huffman code */
count = lit_count;
@ -1293,8 +1259,7 @@ static int inline setup_dynamic_header(struct inflate_state *state)
symbol = decode_next_header(state, &inflate_code_huff);
if (state->read_in_length < 0) {
if (current > &lit_and_dist_huff[256]
&& lit_and_dist_huff[256].length <= 0)
if (current > &lit_and_dist_huff[256] && lit_and_dist_huff[256].length <= 0)
return ISAL_INVALID_BLOCK;
return ISAL_END_INPUT;
}
@ -1347,17 +1312,19 @@ static int inline setup_dynamic_header(struct inflate_state *state)
current++;
if (rep_code.length == 0 // No symbol
|| (previous >= lit_and_dist_huff + LIT_TABLE_SIZE + hlit) // Dist table
|| (previous < lit_and_dist_huff + 264)) // Lit/Len with no extra
|| (previous >=
lit_and_dist_huff + LIT_TABLE_SIZE + hlit) // Dist table
||
(previous < lit_and_dist_huff + 264)) // Lit/Len with no extra
continue;
extra_count =
rfc_lookup_table.len_extra_bit_count
[previous - lit_and_dist_huff - LIT_TABLE_SIZE];
rfc_lookup_table
.len_extra_bit_count[previous - lit_and_dist_huff -
LIT_TABLE_SIZE];
lit_expand_count[rep_code.length]--;
lit_expand_count[rep_code.length +
extra_count] += (1 << extra_count);
lit_expand_count[rep_code.length + extra_count] +=
(1 << extra_count);
}
} else if (symbol == 17) {
/* If a repeat zeroes if found, update then next
@ -1368,8 +1335,8 @@ static int inline setup_dynamic_header(struct inflate_state *state)
current = current + i;
previous = current - 1;
if (count != dist_count
&& current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) {
if (count != dist_count &&
current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) {
/* Switch code upon completion of lit_len table */
current += LIT_LEN - LIT_TABLE_SIZE - hlit;
count = dist_count;
@ -1386,8 +1353,8 @@ static int inline setup_dynamic_header(struct inflate_state *state)
current = current + i;
previous = current - 1;
if (count != dist_count
&& current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) {
if (count != dist_count &&
current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) {
/* Switch code upon completion of lit_len table */
current += LIT_LEN - LIT_TABLE_SIZE - hlit;
count = dist_count;
@ -1397,7 +1364,6 @@ static int inline setup_dynamic_header(struct inflate_state *state)
} else
return ISAL_INVALID_BLOCK;
}
if (current > end || lit_and_dist_huff[256].length <= 0)
@ -1412,11 +1378,11 @@ static int inline setup_dynamic_header(struct inflate_state *state)
if (state->hist_bits && state->hist_bits < 15)
max_dist = 2 * state->hist_bits;
make_inflate_huff_code_dist(&state->dist_huff_code, &lit_and_dist_huff[LIT_LEN],
DIST_LEN, dist_count, max_dist);
make_inflate_huff_code_dist(&state->dist_huff_code, &lit_and_dist_huff[LIT_LEN], DIST_LEN,
dist_count, max_dist);
if (set_and_expand_lit_len_huffcode
(lit_and_dist_huff, LIT_LEN, lit_count, lit_expand_count, code_list))
if (set_and_expand_lit_len_huffcode(lit_and_dist_huff, LIT_LEN, lit_count, lit_expand_count,
code_list))
return ISAL_INVALID_BLOCK;
make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_and_dist_huff, LIT_LEN_ELEMS,
@ -1429,7 +1395,8 @@ static int inline setup_dynamic_header(struct inflate_state *state)
/* Reads in the header pointed to by in_stream and sets up state to reflect that
* header information*/
static int read_header(struct inflate_state *state)
static int
read_header(struct inflate_state *state)
{
uint8_t bytes;
uint32_t btype;
@ -1485,7 +1452,8 @@ static int read_header(struct inflate_state *state)
/* Reads in the header pointed to by in_stream and sets up state to reflect that
* header information*/
static int read_header_stateful(struct inflate_state *state)
static int
read_header_stateful(struct inflate_state *state)
{
uint64_t read_in_start = state->read_in;
int32_t read_in_length_start = state->read_in_length;
@ -1522,8 +1490,7 @@ static int read_header_stateful(struct inflate_state *state)
/* 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;
memcpy(&state->tmp_in_buffer[state->tmp_in_size], next_in_start,
avail_in_start);
memcpy(&state->tmp_in_buffer[state->tmp_in_size], next_in_start, avail_in_start);
state->tmp_in_size += avail_in_start;
state->avail_in = 0;
state->next_in = next_in_start + avail_in_start;
@ -1532,7 +1499,6 @@ static int read_header_stateful(struct inflate_state *state)
state->tmp_in_size = 0;
return ret;
}
static int inline decode_literal_block(struct inflate_state *state)
@ -1598,11 +1564,11 @@ static int inline decode_literal_block(struct inflate_state *state)
return ISAL_OUT_OVERFLOW;
return 0;
}
/* Decodes the next block if it was encoded using a huffman code */
int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_t * start_out)
int
decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_t *start_out)
{
uint16_t next_lit;
uint8_t next_dist;
@ -1660,8 +1626,9 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_
return ISAL_OUT_OVERFLOW;
else if (next_lits == 256) {
state->write_overflow_len -= 1;
state->block_state = state->bfinal ?
ISAL_BLOCK_INPUT_DONE : ISAL_BLOCK_NEW_HDR;
state->block_state = state->bfinal
? ISAL_BLOCK_INPUT_DONE
: ISAL_BLOCK_NEW_HDR;
return ISAL_OUT_OVERFLOW;
} else {
state->write_overflow_len -= 1;
@ -1678,8 +1645,8 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_
/* If the next symbol is the end of
* block, update the state data
* accordingly */
state->block_state = state->bfinal ?
ISAL_BLOCK_INPUT_DONE : ISAL_BLOCK_NEW_HDR;
state->block_state =
state->bfinal ? ISAL_BLOCK_INPUT_DONE : ISAL_BLOCK_NEW_HDR;
} else if (next_lit <= MAX_LIT_LEN_SYM) {
/* Else if the next symbol is a repeat
@ -1695,10 +1662,11 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_
if (next_dist >= DIST_LEN)
return ISAL_INVALID_SYMBOL;
look_back_dist = rfc->dist_start[next_dist] +
inflate_in_read_bits(state,
rfc->dist_extra_bit_count
[next_dist]);
look_back_dist =
rfc->dist_start[next_dist] +
inflate_in_read_bits(
state,
rfc->dist_extra_bit_count[next_dist]);
}
if (state->read_in_length < 0) {
@ -1725,12 +1693,10 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_
}
if (look_back_dist > repeat_length)
memcpy(state->next_out,
state->next_out - look_back_dist,
memcpy(state->next_out, state->next_out - look_back_dist,
repeat_length);
else
byte_copy(state->next_out, look_back_dist,
repeat_length);
byte_copy(state->next_out, look_back_dist, repeat_length);
state->next_out += repeat_length;
state->avail_out -= repeat_length;
@ -1746,12 +1712,12 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_
next_lits >>= 8;
sym_count--;
}
}
return 0;
}
void isal_inflate_init(struct inflate_state *state)
void
isal_inflate_init(struct inflate_state *state)
{
state->read_in = 0;
@ -1778,7 +1744,8 @@ void isal_inflate_init(struct inflate_state *state)
state->tmp_out_valid = 0;
}
void isal_inflate_reset(struct inflate_state *state)
void
isal_inflate_reset(struct inflate_state *state)
{
state->read_in = 0;
state->read_in_length = 0;
@ -1798,8 +1765,8 @@ void isal_inflate_reset(struct inflate_state *state)
state->tmp_out_valid = 0;
}
static inline uint32_t fixed_size_read(struct inflate_state *state,
uint8_t ** read_buf, int read_size)
static inline uint32_t
fixed_size_read(struct inflate_state *state, uint8_t **read_buf, int read_size)
{
uint32_t tmp_in_size = state->tmp_in_size;
@ -1815,8 +1782,7 @@ static inline uint32_t fixed_size_read(struct inflate_state *state,
*read_buf = state->next_in;
if (tmp_in_size) {
memcpy(state->tmp_in_buffer + tmp_in_size, state->next_in,
read_size - tmp_in_size);
memcpy(state->tmp_in_buffer + tmp_in_size, state->next_in, read_size - tmp_in_size);
*read_buf = state->tmp_in_buffer;
state->tmp_in_size = 0;
}
@ -1826,12 +1792,11 @@ static inline uint32_t fixed_size_read(struct inflate_state *state,
tmp_in_size = 0;
return 0;
}
static inline uint32_t buffer_header_copy(struct inflate_state *state, uint32_t in_len,
uint8_t * buf, uint32_t buffer_len, uint32_t offset,
uint32_t buf_error)
static inline uint32_t
buffer_header_copy(struct inflate_state *state, uint32_t in_len, uint8_t *buf, uint32_t buffer_len,
uint32_t offset, uint32_t buf_error)
{
uint32_t len = in_len;
uint32_t buf_len = buffer_len - offset;
@ -1859,16 +1824,16 @@ static inline uint32_t buffer_header_copy(struct inflate_state *state, uint32_t
}
}
static inline uint32_t string_header_copy(struct inflate_state *state,
char *str_buf, uint32_t str_len,
uint32_t offset, uint32_t str_error)
static inline uint32_t
string_header_copy(struct inflate_state *state, char *str_buf, uint32_t str_len, uint32_t offset,
uint32_t str_error)
{
uint32_t len, max_len = str_len - offset;
if (max_len > state->avail_in || str_buf == NULL)
max_len = state->avail_in;
len = strnlen((char *)state->next_in, max_len);
len = strnlen((char *) state->next_in, max_len);
if (str_buf != NULL)
memcpy(&str_buf[offset], state->next_in, len);
@ -1892,7 +1857,8 @@ static inline uint32_t string_header_copy(struct inflate_state *state,
return 0;
}
static int check_gzip_checksum(struct inflate_state *state)
static int
check_gzip_checksum(struct inflate_state *state)
{
uint64_t trailer, crc, total_out;
uint8_t *next_in;
@ -1913,8 +1879,7 @@ static int check_gzip_checksum(struct inflate_state *state)
byte_count = state->read_in_length / 8;
offset = state->read_in_length % 8;
store_le_u64(state->tmp_in_buffer + tmp_in_size,
state->read_in >> offset);
store_le_u64(state->tmp_in_buffer + tmp_in_size, state->read_in >> offset);
state->read_in = 0;
state->read_in_length = 0;
@ -1942,7 +1907,8 @@ static int check_gzip_checksum(struct inflate_state *state)
return ISAL_DECOMP_OK;
}
static int check_zlib_checksum(struct inflate_state *state)
static int
check_zlib_checksum(struct inflate_state *state)
{
uint32_t trailer;
@ -1964,8 +1930,7 @@ static int check_zlib_checksum(struct inflate_state *state)
byte_count = state->read_in_length / 8;
offset = state->read_in_length % 8;
store_le_u64(state->tmp_in_buffer + tmp_in_size,
state->read_in >> offset);
store_le_u64(state->tmp_in_buffer + tmp_in_size, state->read_in >> offset);
state->read_in = 0;
state->read_in_length = 0;
@ -1990,7 +1955,8 @@ static int check_zlib_checksum(struct inflate_state *state)
return ISAL_DECOMP_OK;
}
int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *gz_hdr)
int
isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *gz_hdr)
{
int cm, flags = gz_hdr->flags, id1, id2;
uint16_t xlen = gz_hdr->extra_len;
@ -2049,9 +2015,7 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *
case ISAL_GZIP_EXTRA:
offset = gz_hdr->extra_len - count;
ret =
buffer_header_copy(state, count, gz_hdr->extra,
gz_hdr->extra_buf_len,
ret = buffer_header_copy(state, count, gz_hdr->extra, gz_hdr->extra_buf_len,
offset, ISAL_EXTRA_OVERFLOW);
if (ret) {
@ -2065,9 +2029,8 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *
if (flags & NAME_FLAG) {
case ISAL_GZIP_NAME:
offset = state->count;
ret = string_header_copy(state, gz_hdr->name,
gz_hdr->name_buf_len,
offset, ISAL_NAME_OVERFLOW);
ret = string_header_copy(state, gz_hdr->name, gz_hdr->name_buf_len, offset,
ISAL_NAME_OVERFLOW);
if (ret) {
state->block_state = ISAL_GZIP_NAME;
break;
@ -2077,8 +2040,7 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *
if (flags & COMMENT_FLAG) {
case ISAL_GZIP_COMMENT:
offset = state->count;
ret = string_header_copy(state, gz_hdr->comment,
gz_hdr->comment_buf_len,
ret = string_header_copy(state, gz_hdr->comment, gz_hdr->comment_buf_len,
offset, ISAL_COMMENT_OVERFLOW);
if (ret) {
state->block_state = ISAL_GZIP_COMMENT;
@ -2112,7 +2074,8 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *
return ret;
}
int isal_read_zlib_header(struct inflate_state *state, struct isal_zlib_header *zlib_hdr)
int
isal_read_zlib_header(struct inflate_state *state, struct isal_zlib_header *zlib_hdr)
{
int cmf, method, flags;
uint32_t block_state = state->block_state;
@ -2158,11 +2121,12 @@ int isal_read_zlib_header(struct inflate_state *state, struct isal_zlib_header *
return ret;
}
int isal_inflate_set_dict(struct inflate_state *state, uint8_t * dict, uint32_t dict_len)
int
isal_inflate_set_dict(struct inflate_state *state, uint8_t *dict, uint32_t dict_len)
{
if (state->block_state != ISAL_BLOCK_NEW_HDR
|| state->tmp_out_processed != state->tmp_out_valid)
if (state->block_state != ISAL_BLOCK_NEW_HDR ||
state->tmp_out_processed != state->tmp_out_valid)
return ISAL_INVALID_STATE;
if (dict_len > IGZIP_HIST_SIZE) {
@ -2178,7 +2142,8 @@ int isal_inflate_set_dict(struct inflate_state *state, uint8_t * dict, uint32_t
return COMP_OK;
}
int isal_inflate_stateless(struct inflate_state *state)
int
isal_inflate_stateless(struct inflate_state *state)
{
uint32_t ret = 0;
uint8_t *start_out = state->next_out;
@ -2209,7 +2174,6 @@ int isal_inflate_stateless(struct inflate_state *state)
return ret;
if (z_hdr.dict_flag)
return ISAL_NEED_DICT;
}
while (state->block_state != ISAL_BLOCK_FINISH) {
@ -2260,7 +2224,8 @@ int isal_inflate_stateless(struct inflate_state *state)
return ret;
}
int isal_inflate(struct inflate_state *state)
int
isal_inflate(struct inflate_state *state)
{
uint8_t *start_out = state->next_out;
@ -2313,8 +2278,7 @@ int isal_inflate(struct inflate_state *state)
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_LOOK_AHEAD -
state->avail_out = sizeof(state->tmp_out_buffer) - ISAL_LOOK_AHEAD -
state->tmp_out_valid;
if ((int32_t) state->avail_out < 0)
@ -2322,8 +2286,8 @@ int isal_inflate(struct inflate_state *state)
/* Decode into internal buffer until exit */
while (state->block_state != ISAL_BLOCK_INPUT_DONE) {
if (state->block_state == ISAL_BLOCK_NEW_HDR
|| state->block_state == ISAL_BLOCK_HDR) {
if (state->block_state == ISAL_BLOCK_NEW_HDR ||
state->block_state == ISAL_BLOCK_HDR) {
ret = read_header_stateful(state);
if (ret)
@ -2372,15 +2336,15 @@ int isal_inflate(struct inflate_state *state)
if (copy_size > avail_out)
copy_size = avail_out;
memcpy(state->next_out,
&state->tmp_out_buffer[state->tmp_out_processed], copy_size);
memcpy(state->next_out, &state->tmp_out_buffer[state->tmp_out_processed],
copy_size);
state->tmp_out_processed += copy_size;
state->avail_out -= copy_size;
state->next_out += copy_size;
if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK
|| ret == ISAL_INVALID_SYMBOL) {
if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK ||
ret == ISAL_INVALID_SYMBOL) {
/* Set total_out to not count data in tmp_out_buffer */
state->total_out -= state->tmp_out_valid - state->tmp_out_processed;
if (state->crc_flag)
@ -2392,8 +2356,8 @@ int isal_inflate(struct inflate_state *state)
* decompressing into the out buffer */
if (state->tmp_out_processed == state->tmp_out_valid) {
while (state->block_state != ISAL_BLOCK_INPUT_DONE) {
if (state->block_state == ISAL_BLOCK_NEW_HDR
|| state->block_state == ISAL_BLOCK_HDR) {
if (state->block_state == ISAL_BLOCK_NEW_HDR ||
state->block_state == ISAL_BLOCK_HDR) {
ret = read_header_stateful(state);
if (ret)
break;
@ -2402,9 +2366,7 @@ int isal_inflate(struct inflate_state *state)
if (state->block_state == ISAL_BLOCK_TYPE0)
ret = decode_literal_block(state);
else
ret =
decode_huffman_code_block_stateless(state,
start_out);
ret = decode_huffman_code_block_stateless(state, start_out);
if (ret)
break;
}
@ -2413,14 +2375,13 @@ int isal_inflate(struct inflate_state *state)
if (state->crc_flag)
update_checksum(state, start_out, state->next_out - start_out);
if (state->block_state != ISAL_BLOCK_INPUT_DONE
|| state->copy_overflow_length + state->write_overflow_len +
state->tmp_out_valid > sizeof(state->tmp_out_buffer)) {
if (state->block_state != ISAL_BLOCK_INPUT_DONE ||
state->copy_overflow_length + state->write_overflow_len + state->tmp_out_valid >
sizeof(state->tmp_out_buffer)) {
/* Save decompression history in tmp_out buffer */
if (state->tmp_out_valid == state->tmp_out_processed
&& avail_out - state->avail_out >= ISAL_DEF_HIST_SIZE) {
memcpy(state->tmp_out_buffer,
state->next_out - ISAL_DEF_HIST_SIZE,
if (state->tmp_out_valid == state->tmp_out_processed &&
avail_out - state->avail_out >= ISAL_DEF_HIST_SIZE) {
memcpy(state->tmp_out_buffer, 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;
@ -2430,12 +2391,10 @@ int isal_inflate(struct inflate_state *state)
if (shift_size > state->tmp_out_processed)
shift_size = state->tmp_out_processed;
memmove(state->tmp_out_buffer,
&state->tmp_out_buffer[shift_size],
memmove(state->tmp_out_buffer, &state->tmp_out_buffer[shift_size],
state->tmp_out_valid - shift_size);
state->tmp_out_valid -= shift_size;
state->tmp_out_processed -= shift_size;
}
}
@ -2458,14 +2417,14 @@ int isal_inflate(struct inflate_state *state)
state->copy_overflow_length = 0;
}
if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK
|| ret == ISAL_INVALID_SYMBOL) {
if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK ||
ret == ISAL_INVALID_SYMBOL) {
state->total_out -= state->tmp_out_valid - state->tmp_out_processed;
return ret;
}
if (state->block_state == ISAL_BLOCK_INPUT_DONE
&& state->tmp_out_valid == state->tmp_out_processed) {
if (state->block_state == ISAL_BLOCK_INPUT_DONE &&
state->tmp_out_valid == state->tmp_out_processed) {
state->block_state = ISAL_BLOCK_FINISH;
switch (state->crc_flag) {

View File

@ -39,13 +39,14 @@
/*Don't use file larger memory can support because compression and decompression
* are done in a stateless manner. */
#if __WORDSIZE == 64
#define MAX_INPUT_FILE_SIZE 2L*1024L*1024L*1024L
#define MAX_INPUT_FILE_SIZE 2L * 1024L * 1024L * 1024L
#else
#define MAX_INPUT_FILE_SIZE 512L*1024L*1024L
#define MAX_INPUT_FILE_SIZE 512L * 1024L * 1024L
#endif
int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
uint8_t * uncompress_buf, uint32_t * uncompress_len)
int
inflate_multi_pass(uint8_t *compress_buf, uint64_t compress_len, uint8_t *uncompress_buf,
uint32_t *uncompress_len)
{
struct inflate_state *state = NULL;
int ret = 0;
@ -146,23 +147,20 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
return ret;
}
int test(uint8_t * compressed_stream,
uint64_t * compressed_length,
uint8_t * uncompressed_stream, uint32_t uncompressed_length,
uint8_t * uncompressed_test_stream, uint32_t uncompressed_test_stream_length)
int
test(uint8_t *compressed_stream, uint64_t *compressed_length, uint8_t *uncompressed_stream,
uint32_t uncompressed_length, uint8_t *uncompressed_test_stream,
uint32_t uncompressed_test_stream_length)
{
int ret;
ret =
compress2(compressed_stream, (uLongf *) compressed_length,
uncompressed_stream, uncompressed_length, 6);
ret = compress2(compressed_stream, (uLongf *) compressed_length, uncompressed_stream,
uncompressed_length, 6);
if (ret) {
printf("Failed compressing input with exit code %d", ret);
return ret;
}
ret =
inflate_multi_pass(compressed_stream + 2,
*compressed_length - 2 - 4,
ret = inflate_multi_pass(compressed_stream + 2, *compressed_length - 2 - 4,
uncompressed_test_stream, &uncompressed_test_stream_length);
switch (ret) {
case 0:
@ -195,8 +193,8 @@ int test(uint8_t * compressed_stream,
if (uncompressed_test_stream_length != uncompressed_length) {
printf("incorrect amount of data was decompressed from compressed data\n");
printf("%d decompressed of %d compressed",
uncompressed_test_stream_length, uncompressed_length);
printf("%d decompressed of %d compressed", uncompressed_test_stream_length,
uncompressed_length);
return -1;
}
if (memcmp(uncompressed_stream, uncompressed_test_stream, uncompressed_length)) {
@ -214,7 +212,8 @@ int test(uint8_t * compressed_stream,
return 0;
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
int i, j, ret = 0, fin_ret = 0;
FILE *file = NULL;
@ -272,12 +271,11 @@ int main(int argc, char **argv)
exit(0);
}
uncompressed_length =
(uncompressed_stream == NULL) ? 0 : fread(uncompressed_stream, 1,
file_length, file);
uncompressed_length = (uncompressed_stream == NULL)
? 0
: fread(uncompressed_stream, 1, file_length, file);
uncompressed_test_stream_length = uncompressed_length;
ret =
test(compressed_stream, &compressed_length, uncompressed_stream,
ret = test(compressed_stream, &compressed_length, uncompressed_stream,
uncompressed_length, uncompressed_test_stream,
uncompressed_test_stream_length);
if (ret) {

View File

@ -106,12 +106,7 @@ int level_size_buf[10] = {
#endif
};
enum {
ISAL_STATELESS,
ISAL_STATEFUL,
ISAL_WITH_DICTIONARY,
ZLIB
};
enum { ISAL_STATELESS, ISAL_STATEFUL, ISAL_WITH_DICTIONARY, ZLIB };
struct compress_strategy {
int32_t mode;
@ -138,24 +133,29 @@ struct perf_info {
struct perf start;
};
void init_perf_info(struct perf_info *info)
void
init_perf_info(struct perf_info *info)
{
memset(info, 0, sizeof(*info));
info->deflate_time = BENCHMARK_TIME;
info->inflate_time = BENCHMARK_TIME;
}
int usage(void)
int
usage(void)
{
fprintf(stderr,
"Usage: igzip_perf [options] <infile>\n"
" -h help, print this message\n"
" The options -l, -f, -z may be used up to "
xstr(COMPRESSION_QUEUE_LIMIT) " times\n"
" -l <level> isa-l stateless deflate level to test ("
xstr(ISAL_DEF_MIN_LEVEL) "-" xstr(ISAL_DEF_MAX_LEVEL) ")\n"
" -f <level> isa-l stateful deflate level to test ("
xstr(ISAL_DEF_MIN_LEVEL) "-" xstr(ISAL_DEF_MAX_LEVEL) ")\n"
" The options -l, -f, -z may be used up to " xstr(
COMPRESSION_QUEUE_LIMIT) " times\n"
" -l <level> isa-l stateless deflate level to "
"test (" xstr(ISAL_DEF_MIN_LEVEL) "-" xstr(
ISAL_DEF_MAX_LEVEL) ")\n"
" -f <level> isa-l "
"stateful deflate "
"level to test (" xstr(ISAL_DEF_MIN_LEVEL) "-" xstr(
ISAL_DEF_MAX_LEVEL) ")\n"
" -z <level> zlib deflate level to test\n"
" -d <time> approx time in seconds for deflate (at least 0)\n"
" -i <time> approx time in seconds for inflate (at least 0)\n"
@ -170,20 +170,23 @@ int usage(void)
exit(0);
}
void print_perf_info_line(struct perf_info *info)
void
print_perf_info_line(struct perf_info *info)
{
printf("igzip_perf-> compress level: %d flush_type: %d block_size: %d\n",
info->strategy.level, info->flush_type, info->inblock_size);
}
void print_file_line(struct perf_info *info)
void
print_file_line(struct perf_info *info)
{
printf(" file info-> name: %s file_size: %lu compress_size: %lu ratio: %2.02f%%\n",
info->file_name, info->file_size, info->deflate_size,
100.0 * info->deflate_size / info->file_size);
}
void print_deflate_perf_line(struct perf_info *info)
void
print_deflate_perf_line(struct perf_info *info)
{
if (info->strategy.mode == ISAL_STATELESS)
printf(" isal_stateless_deflate-> ");
@ -197,7 +200,8 @@ void print_deflate_perf_line(struct perf_info *info)
perf_print(info->start, info->file_size);
}
void print_inflate_perf_line(struct perf_info *info)
void
print_inflate_perf_line(struct perf_info *info)
{
if (info->inflate_mode == ISAL_STATELESS)
printf(" isal_stateless_inflate-> ");
@ -211,10 +215,10 @@ void print_inflate_perf_line(struct perf_info *info)
perf_print(info->start, info->file_size);
}
int isal_deflate_round(struct isal_zstream *stream, uint8_t * outbuf, uint32_t outbuf_size,
uint8_t * inbuf, uint32_t inbuf_size,
uint32_t level, uint8_t * level_buf, uint32_t level_buf_size,
int flush_type, int hist_bits)
int
isal_deflate_round(struct isal_zstream *stream, uint8_t *outbuf, uint32_t outbuf_size,
uint8_t *inbuf, uint32_t inbuf_size, uint32_t level, uint8_t *level_buf,
uint32_t level_buf_size, int flush_type, int hist_bits)
{
int check;
@ -241,11 +245,11 @@ int isal_deflate_round(struct isal_zstream *stream, uint8_t * outbuf, uint32_t o
return 0;
}
int isal_deflate_dict_round(struct isal_zstream *stream, uint8_t * outbuf,
uint32_t outbuf_size, uint8_t * inbuf,
uint32_t inbuf_size, uint32_t level,
uint8_t * level_buf, uint32_t level_buf_size, int flush_type,
int hist_bits, struct isal_dict *dict_str)
int
isal_deflate_dict_round(struct isal_zstream *stream, uint8_t *outbuf, uint32_t outbuf_size,
uint8_t *inbuf, uint32_t inbuf_size, uint32_t level, uint8_t *level_buf,
uint32_t level_buf_size, int flush_type, int hist_bits,
struct isal_dict *dict_str)
{
int check;
@ -275,8 +279,9 @@ int isal_deflate_dict_round(struct isal_zstream *stream, uint8_t * outbuf,
return 0;
}
int isal_inflate_round(struct inflate_state *state, uint8_t * inbuf, uint32_t inbuf_size,
uint8_t * outbuf, uint32_t outbuf_size, int hist_bits)
int
isal_inflate_round(struct inflate_state *state, uint8_t *inbuf, uint32_t inbuf_size,
uint8_t *outbuf, uint32_t outbuf_size, int hist_bits)
{
int check = 0;
@ -298,11 +303,11 @@ int isal_inflate_round(struct inflate_state *state, uint8_t * inbuf, uint32_t in
return 0;
}
int isal_deflate_stateful_round(struct isal_zstream *stream, uint8_t * outbuf,
uint32_t outbuf_size, uint8_t * inbuf,
uint32_t inbuf_size, uint32_t in_block_size, uint32_t level,
uint8_t * level_buf, uint32_t level_buf_size, int flush_type,
int hist_bits)
int
isal_deflate_stateful_round(struct isal_zstream *stream, uint8_t *outbuf, uint32_t outbuf_size,
uint8_t *inbuf, uint32_t inbuf_size, uint32_t in_block_size,
uint32_t level, uint8_t *level_buf, uint32_t level_buf_size,
int flush_type, int hist_bits)
{
uint64_t inbuf_remaining;
int check = COMP_OK;
@ -345,10 +350,10 @@ int isal_deflate_stateful_round(struct isal_zstream *stream, uint8_t * outbuf,
return 0;
}
int isal_inflate_stateful_round(struct inflate_state *state, uint8_t * inbuf,
uint32_t inbuf_size, uint32_t in_block_size, uint8_t * outbuf,
uint32_t outbuf_size, int hist_bits,
uint8_t * dict_buf, int dict_file_size)
int
isal_inflate_stateful_round(struct inflate_state *state, uint8_t *inbuf, uint32_t inbuf_size,
uint32_t in_block_size, uint8_t *outbuf, uint32_t outbuf_size,
int hist_bits, uint8_t *dict_buf, int dict_file_size)
{
int check = ISAL_DECOMP_OK;
uint64_t inbuf_remaining;
@ -379,9 +384,9 @@ int isal_inflate_stateful_round(struct inflate_state *state, uint8_t * inbuf,
return 0;
}
int zlib_deflate_round(z_stream * gstream, uint8_t * outbuf, uInt outbuf_size,
uint8_t * inbuf, uLong inbuf_size,
uLong in_block_size, int level, int flush_type)
int
zlib_deflate_round(z_stream *gstream, uint8_t *outbuf, uInt outbuf_size, uint8_t *inbuf,
uLong inbuf_size, uLong in_block_size, int level, int flush_type)
{
uLong inbuf_remaining;
int check = Z_OK;
@ -417,8 +422,9 @@ int zlib_deflate_round(z_stream * gstream, uint8_t * outbuf, uInt outbuf_size,
return 0;
}
int zlib_inflate_round(z_stream * gstream, uint8_t * inbuf,
uLong inbuf_size, uint8_t * outbuf, uInt outbuf_size)
int
zlib_inflate_round(z_stream *gstream, uint8_t *inbuf, uLong inbuf_size, uint8_t *outbuf,
uInt outbuf_size)
{
int check = 0;
@ -436,9 +442,9 @@ int zlib_inflate_round(z_stream * gstream, uint8_t * inbuf,
return 0;
}
int isal_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
uint64_t inbuf_size, int level, int flush_type, int hist_bits, int time,
struct perf *start)
int
isal_deflate_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, uint64_t inbuf_size,
int level, int flush_type, int hist_bits, int time, struct perf *start)
{
struct isal_zstream stream;
uint8_t *level_buf = NULL;
@ -450,18 +456,18 @@ int isal_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
return 1;
}
BENCHMARK(start, time, check =
isal_deflate_round(&stream, outbuf, *outbuf_size, inbuf,
inbuf_size, level, level_buf,
level_size_buf[level], flush_type, hist_bits));
BENCHMARK(start, time,
check = isal_deflate_round(&stream, outbuf, *outbuf_size, inbuf, inbuf_size,
level, level_buf, level_size_buf[level], flush_type,
hist_bits));
*outbuf_size = stream.total_out;
return check;
}
int isal_deflate_dict_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
uint64_t inbuf_size, int level, int flush_type, int hist_bits,
int time, struct perf *start, uint8_t * dict_buf,
int dict_file_size)
int
isal_deflate_dict_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, uint64_t inbuf_size,
int level, int flush_type, int hist_bits, int time, struct perf *start,
uint8_t *dict_buf, int dict_file_size)
{
struct isal_zstream stream;
struct isal_dict dict_str;
@ -481,21 +487,20 @@ int isal_deflate_dict_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * i
return 1;
}
BENCHMARK(start, time, check =
isal_deflate_dict_round(&stream, outbuf, *outbuf_size, inbuf,
inbuf_size, level, level_buf,
level_size_buf[level], flush_type, hist_bits,
&dict_str));
BENCHMARK(start, time,
check = isal_deflate_dict_round(&stream, outbuf, *outbuf_size, inbuf, inbuf_size,
level, level_buf, level_size_buf[level],
flush_type, hist_bits, &dict_str));
if (level_buf != NULL)
free(level_buf);
*outbuf_size = stream.total_out;
return check;
}
int isal_deflate_stateful_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
uint64_t inbuf_size, int level, int flush_type,
uint64_t in_block_size, int hist_bits, int time,
struct perf *start)
int
isal_deflate_stateful_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf,
uint64_t inbuf_size, int level, int flush_type, uint64_t in_block_size,
int hist_bits, int time, struct perf *start)
{
struct isal_zstream stream;
uint8_t *level_buf = NULL;
@ -510,18 +515,18 @@ int isal_deflate_stateful_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t
return 1;
}
BENCHMARK(start, time, check =
isal_deflate_stateful_round(&stream, outbuf, *outbuf_size, inbuf, inbuf_size,
in_block_size, level, level_buf,
level_size_buf[level], flush_type, hist_bits));
BENCHMARK(start, time,
check = isal_deflate_stateful_round(
&stream, outbuf, *outbuf_size, inbuf, inbuf_size, in_block_size, level,
level_buf, level_size_buf[level], flush_type, hist_bits));
*outbuf_size = stream.total_out;
return check;
}
int zlib_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
uint64_t inbuf_size, int level, int flush_type,
uint64_t in_block_size, int hist_bits, int time, struct perf *start)
int
zlib_deflate_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, uint64_t inbuf_size,
int level, int flush_type, uint64_t in_block_size, int hist_bits, int time,
struct perf *start)
{
int check;
z_stream gstream;
@ -547,8 +552,8 @@ int zlib_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
if (0 != deflateInit2(&gstream, level, Z_DEFLATED, hist_bits, 9, Z_DEFAULT_STRATEGY))
return 1;
BENCHMARK(start, time, check =
zlib_deflate_round(&gstream, outbuf, *outbuf_size, inbuf, inbuf_size,
BENCHMARK(start, time,
check = zlib_deflate_round(&gstream, outbuf, *outbuf_size, inbuf, inbuf_size,
in_block_size, level, flush_type));
*outbuf_size = gstream.total_out;
@ -557,9 +562,9 @@ int zlib_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf,
return check;
}
int isal_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf,
uint64_t outbuf_size, uint8_t * filebuf, uint64_t file_size,
int hist_bits, int time, struct perf *start)
int
isal_inflate_perf(uint8_t *inbuf, uint64_t inbuf_size, uint8_t *outbuf, uint64_t outbuf_size,
uint8_t *filebuf, uint64_t file_size, int hist_bits, int time, struct perf *start)
{
struct inflate_state state;
int check;
@ -569,16 +574,17 @@ int isal_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf,
if (check || state.total_out != file_size || memcmp(outbuf, filebuf, file_size))
return 1;
BENCHMARK(start, time, isal_inflate_round(&state, inbuf, inbuf_size,
outbuf, outbuf_size, hist_bits));
BENCHMARK(start, time,
isal_inflate_round(&state, inbuf, inbuf_size, outbuf, outbuf_size, hist_bits));
return check;
}
int isal_inflate_stateful_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf,
uint64_t outbuf_size, uint8_t * filebuf, uint64_t file_size,
uint64_t in_block_size, int hist_bits, int time,
struct perf *start, uint8_t * dict_buf, int dict_file_size)
int
isal_inflate_stateful_perf(uint8_t *inbuf, uint64_t inbuf_size, uint8_t *outbuf,
uint64_t outbuf_size, uint8_t *filebuf, uint64_t file_size,
uint64_t in_block_size, int hist_bits, int time, struct perf *start,
uint8_t *dict_buf, int dict_file_size)
{
struct inflate_state state;
int check;
@ -593,16 +599,14 @@ int isal_inflate_stateful_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * o
BENCHMARK(start, time,
isal_inflate_stateful_round(&state, inbuf, inbuf_size, in_block_size, outbuf,
outbuf_size, hist_bits, dict_buf,
dict_file_size));
outbuf_size, hist_bits, dict_buf, dict_file_size));
return 0;
}
int zlib_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf,
uint64_t outbuf_size, uint8_t * filebuf, uint64_t file_size,
int hist_bits, int time, struct perf *start)
int
zlib_inflate_perf(uint8_t *inbuf, uint64_t inbuf_size, uint8_t *outbuf, uint64_t outbuf_size,
uint8_t *filebuf, uint64_t file_size, int hist_bits, int time, struct perf *start)
{
int check;
z_stream gstream;
@ -632,7 +636,8 @@ int zlib_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf,
return 0;
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
FILE *in = NULL;
FILE *dict_fn = NULL;
@ -744,8 +749,8 @@ int main(int argc, char *argv[])
break;
case 'y':
info.flush_type = atoi(optarg);
if (info.flush_type != NO_FLUSH && info.flush_type != SYNC_FLUSH
&& info.flush_type != FULL_FLUSH) {
if (info.flush_type != NO_FLUSH && info.flush_type != SYNC_FLUSH &&
info.flush_type != FULL_FLUSH) {
printf("Unsupported flush type\n");
exit(0);
}
@ -848,32 +853,26 @@ int main(int argc, char *argv[])
if (dict_file_size != 0) {
info.strategy.mode = ISAL_WITH_DICTIONARY;
ret = isal_deflate_dict_perf(compressbuf, &info.deflate_size,
filebuf, info.file_size,
compression_queue[i].level,
info.flush_type, info.hist_bits,
info.deflate_time, &info.start,
dict_buf, dict_file_size);
ret = isal_deflate_dict_perf(
compressbuf, &info.deflate_size, filebuf, info.file_size,
compression_queue[i].level, info.flush_type, info.hist_bits,
info.deflate_time, &info.start, dict_buf, dict_file_size);
} else if (info.strategy.mode == ISAL_STATELESS)
ret = isal_deflate_perf(compressbuf, &info.deflate_size, filebuf,
info.file_size,
compression_queue[i].level,
info.flush_type, info.hist_bits,
info.deflate_time, &info.start);
info.file_size, compression_queue[i].level,
info.flush_type, info.hist_bits, info.deflate_time,
&info.start);
else if (info.strategy.mode == ISAL_STATEFUL)
ret = isal_deflate_stateful_perf(compressbuf, &info.deflate_size,
filebuf, info.file_size,
compression_queue[i].level,
info.flush_type, info.inblock_size,
info.hist_bits, info.deflate_time,
&info.start);
ret = isal_deflate_stateful_perf(
compressbuf, &info.deflate_size, filebuf, info.file_size,
compression_queue[i].level, info.flush_type, info.inblock_size,
info.hist_bits, info.deflate_time, &info.start);
else if (info.strategy.mode == ZLIB)
ret = zlib_deflate_perf(compressbuf, &info.deflate_size, filebuf,
info.file_size, compression_queue[i].level,
info.flush_type, info.inblock_size,
info.hist_bits, info.deflate_time,
&info.start);
info.flush_type, info.inblock_size, info.hist_bits,
info.deflate_time, &info.start);
if (ret) {
printf(" Error in compression\n");
continue;
@ -906,8 +905,7 @@ int main(int argc, char *argv[])
info.inflate_mode = ISAL_STATELESS;
ret = isal_inflate_perf(compressbuf, info.deflate_size, decompbuf,
decompbuf_size, filebuf, info.file_size,
info.hist_bits, info.inflate_time,
&info.start);
info.hist_bits, info.inflate_time, &info.start);
if (ret)
printf(" Error in isal stateless inflate\n");
else
@ -918,12 +916,10 @@ int main(int argc, char *argv[])
info.inflate_mode =
(dict_file_size == 0) ? ISAL_STATEFUL : ISAL_WITH_DICTIONARY;
ret = isal_inflate_stateful_perf(compressbuf, info.deflate_size,
decompbuf, decompbuf_size, filebuf,
info.file_size, info.inblock_size,
info.hist_bits, info.inflate_time,
&info.start, dict_buf,
dict_file_size);
ret = isal_inflate_stateful_perf(
compressbuf, info.deflate_size, decompbuf, decompbuf_size, filebuf,
info.file_size, info.inblock_size, info.hist_bits,
info.inflate_time, &info.start, dict_buf, dict_file_size);
if (ret)
printf(" Error in isal stateful inflate\n");
@ -935,8 +931,7 @@ int main(int argc, char *argv[])
info.inflate_mode = ZLIB;
ret = zlib_inflate_perf(compressbuf, info.deflate_size, decompbuf,
decompbuf_size, filebuf, info.file_size,
info.hist_bits, info.inflate_time,
&info.start);
info.hist_bits, info.inflate_time, &info.start);
if (ret)
printf(" Error in zlib inflate\n");
else

File diff suppressed because it is too large Load Diff

View File

@ -38,13 +38,14 @@
#define MIN_BUF_SIZE (4 * 1024)
#define MIN_TEST_LOOPS 10
#ifndef RUN_MEM_SIZE
# define RUN_MEM_SIZE 500000000
#define RUN_MEM_SIZE 500000000
#endif
#define DEFAULT_SEG_SIZE (512 * 1024)
#define DEFAULT_SAMPLE_SIZE (32 * 1024)
int usage(void)
int
usage(void)
{
fprintf(stderr,
"Usage: igzip_semi_dynamic [options] <infile>\n"
@ -53,11 +54,13 @@ int usage(void)
" -t <type> 1:stateless 0:(default)stateful\n"
" -c <size> chunk size default=%d\n"
" -s <size> sample size default=%d\n"
" -o <file> output file\n", DEFAULT_SEG_SIZE, DEFAULT_SAMPLE_SIZE);
" -o <file> output file\n",
DEFAULT_SEG_SIZE, DEFAULT_SAMPLE_SIZE);
exit(0);
}
int str_to_i(char *s)
int
str_to_i(char *s)
{
#define ARG_MAX 32
@ -89,9 +92,9 @@ int str_to_i(char *s)
return i;
}
void semi_dyn_stateless_perf(struct isal_zstream *stream, uint8_t * inbuf,
uint64_t infile_size, uint8_t * outbuf, uint64_t outbuf_size,
int segment_size, int hist_size)
void
semi_dyn_stateless_perf(struct isal_zstream *stream, uint8_t *inbuf, uint64_t infile_size,
uint8_t *outbuf, uint64_t outbuf_size, int segment_size, int hist_size)
{
struct isal_huff_histogram histogram;
struct isal_hufftables hufftable;
@ -130,9 +133,9 @@ void semi_dyn_stateless_perf(struct isal_zstream *stream, uint8_t * inbuf,
}
}
void semi_dyn_stateful_perf(struct isal_zstream *stream, uint8_t * inbuf,
uint64_t infile_size, uint8_t * outbuf, uint64_t outbuf_size,
int segment_size, int hist_size)
void
semi_dyn_stateful_perf(struct isal_zstream *stream, uint8_t *inbuf, uint64_t infile_size,
uint8_t *outbuf, uint64_t outbuf_size, int segment_size, int hist_size)
{
struct isal_huff_histogram histogram;
struct isal_hufftables hufftable;
@ -171,7 +174,8 @@ void semi_dyn_stateful_perf(struct isal_zstream *stream, uint8_t * inbuf,
}
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
FILE *in = stdin, *out = NULL;
unsigned char *inbuf, *outbuf;
@ -269,15 +273,14 @@ int main(int argc, char *argv[])
if (do_stateful) {
BENCHMARK(&start, BENCHMARK_TIME,
semi_dyn_stateful_perf(&stream, inbuf, infile_size, outbuf,
outbuf_size, segment_size, hist_size)
);
semi_dyn_stateful_perf(&stream, inbuf, infile_size, outbuf, outbuf_size,
segment_size, hist_size));
}
if (do_stateless) {
BENCHMARK(&start, BENCHMARK_TIME,
semi_dyn_stateless_perf(&stream, inbuf, infile_size, outbuf,
outbuf_size, segment_size, hist_size));
semi_dyn_stateless_perf(&stream, inbuf, infile_size, outbuf, outbuf_size,
segment_size, hist_size));
}
if (stream.avail_in != 0) {
@ -289,7 +292,7 @@ int main(int argc, char *argv[])
infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);
printf("igzip_semi_dyn_file: ");
perf_print(start, (long long)infile_size);
perf_print(start, (long long) infile_size);
if (out != NULL) {
printf("writing %s\n", out_file_name);

View File

@ -36,7 +36,8 @@
struct isal_zstream stream;
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE];
FILE *in, *out;

View File

@ -7,10 +7,10 @@
#include "igzip_wrapper.h"
#ifndef TEST_SEED
# define TEST_SEED 0x1234
#define TEST_SEED 0x1234
#endif
#ifndef RANDOMS
# define RANDOMS 0x4000
#define RANDOMS 0x4000
#endif
#define EXTRA_SIZE_MAX 256
@ -48,7 +48,8 @@ enum {
MALLOC_FAILED
};
void print_error(int32_t error)
void
print_error(int32_t error)
{
printf("Error Code %d: ", error);
switch (error) {
@ -126,7 +127,8 @@ void print_error(int32_t error)
}
}
void print_uint8_t(uint8_t * array, uint64_t length, char *prepend)
void
print_uint8_t(uint8_t *array, uint64_t length, char *prepend)
{
const int line_size = 16;
int i;
@ -151,7 +153,8 @@ void print_uint8_t(uint8_t * array, uint64_t length, char *prepend)
printf("\n");
}
void print_string(char *str, uint32_t str_max_len, char *prepend)
void
print_string(char *str, uint32_t str_max_len, char *prepend)
{
const int line_size = 64;
uint32_t i = 0;
@ -168,10 +171,11 @@ void print_string(char *str, uint32_t str_max_len, char *prepend)
printf("\n");
}
void print_gzip_header(struct isal_gzip_header *gz_hdr, char *prepend1, char *prepend2)
void
print_gzip_header(struct isal_gzip_header *gz_hdr, char *prepend1, char *prepend2)
{
printf("%sText: %d, Time: 0x%08x, Xflags: 0x%x, OS: 0x%x\n", prepend1,
gz_hdr->text, gz_hdr->time, gz_hdr->xflags, gz_hdr->os);
printf("%sText: %d, Time: 0x%08x, Xflags: 0x%x, OS: 0x%x\n", prepend1, gz_hdr->text,
gz_hdr->time, gz_hdr->xflags, gz_hdr->os);
printf("%sExtra: Extra_len = 0x%x\n", prepend1, gz_hdr->extra_len);
if (gz_hdr->extra_len < EXTRA_SIZE_MAX)
@ -192,17 +196,17 @@ void print_gzip_header(struct isal_gzip_header *gz_hdr, char *prepend1, char *pr
printf("%sComment field larger than COMMENT_SIZE_MAX\n", prepend2);
}
void print_zlib_header(struct isal_zlib_header *z_hdr, char *prepend)
void
print_zlib_header(struct isal_zlib_header *z_hdr, char *prepend)
{
printf("%sInfo: 0x%x\n", prepend, z_hdr->info);
printf("%sLevel: 0x%x\n", prepend, z_hdr->level);
printf("%sDictionary: Flag = 0x%x, Id =0x%x\n", prepend, z_hdr->dict_flag,
z_hdr->dict_id);
printf("%sDictionary: Flag = 0x%x, Id =0x%x\n", prepend, z_hdr->dict_flag, z_hdr->dict_id);
}
void print_gzip_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len,
struct isal_gzip_header *gz_hdr_orig,
struct isal_gzip_header *gz_hdr)
void
print_gzip_final_verbose(uint8_t *hdr_buf, uint32_t hdr_buf_len,
struct isal_gzip_header *gz_hdr_orig, struct isal_gzip_header *gz_hdr)
{
#ifdef VERBOSE
printf("\n");
@ -227,9 +231,9 @@ void print_gzip_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len,
return;
}
void print_zlib_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len,
struct isal_zlib_header *z_hdr_orig,
struct isal_zlib_header *z_hdr)
void
print_zlib_final_verbose(uint8_t *hdr_buf, uint32_t hdr_buf_len,
struct isal_zlib_header *z_hdr_orig, struct isal_zlib_header *z_hdr)
{
#ifdef VERBOSE
printf("\n");
@ -254,7 +258,8 @@ void print_zlib_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len,
return;
}
int gzip_header_size(struct isal_gzip_header *gz_hdr)
int
gzip_header_size(struct isal_gzip_header *gz_hdr)
{
int hdr_size = 10;
if (gz_hdr->extra != NULL) {
@ -274,7 +279,8 @@ int gzip_header_size(struct isal_gzip_header *gz_hdr)
return hdr_size;
}
int zlib_header_size(struct isal_zlib_header *z_hdr)
int
zlib_header_size(struct isal_zlib_header *z_hdr)
{
if (z_hdr->dict_flag)
return 6;
@ -282,7 +288,8 @@ int zlib_header_size(struct isal_zlib_header *z_hdr)
return 2;
}
void rand_string(char *string, uint32_t str_len)
void
rand_string(char *string, uint32_t str_len)
{
int i;
@ -294,7 +301,8 @@ void rand_string(char *string, uint32_t str_len)
string[str_len - 1] = 0;
}
void rand_buf(uint8_t * buf, uint32_t buf_len)
void
rand_buf(uint8_t *buf, uint32_t buf_len)
{
int i;
@ -306,7 +314,8 @@ void rand_buf(uint8_t * buf, uint32_t buf_len)
}
}
int malloc_gzip_header(struct isal_gzip_header *gz_hdr)
int
malloc_gzip_header(struct isal_gzip_header *gz_hdr)
{
gz_hdr->extra = NULL;
if (gz_hdr->extra_buf_len) {
@ -337,7 +346,8 @@ int malloc_gzip_header(struct isal_gzip_header *gz_hdr)
return 0;
}
void free_gzip_header(struct isal_gzip_header *gz_hdr)
void
free_gzip_header(struct isal_gzip_header *gz_hdr)
{
if (gz_hdr->extra != NULL) {
free(gz_hdr->extra);
@ -353,10 +363,10 @@ void free_gzip_header(struct isal_gzip_header *gz_hdr)
free(gz_hdr->comment);
gz_hdr->comment = NULL;
}
}
int gen_rand_gzip_header(struct isal_gzip_header *gz_hdr)
int
gen_rand_gzip_header(struct isal_gzip_header *gz_hdr)
{
int ret = 0;
int field_set_space = 8;
@ -396,7 +406,8 @@ int gen_rand_gzip_header(struct isal_gzip_header *gz_hdr)
return ret;
}
void gen_rand_zlib_header(struct isal_zlib_header *z_hdr)
void
gen_rand_zlib_header(struct isal_zlib_header *z_hdr)
{
z_hdr->info = rand() % 16;
z_hdr->level = rand() % 4;
@ -404,7 +415,8 @@ void gen_rand_zlib_header(struct isal_zlib_header *z_hdr)
z_hdr->dict_id = rand();
}
int write_gzip_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_gzip_header *gz_hdr)
int
write_gzip_header(uint8_t *hdr_buf, uint32_t hdr_buf_len, struct isal_gzip_header *gz_hdr)
{
struct isal_zstream stream;
@ -436,13 +448,15 @@ int write_gzip_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_gzip_
if (len) {
print_gzip_final_verbose(hdr_buf, hdr_buf_len, gz_hdr, NULL);
print_error(INCORRECT_WRITE_RETURN);
return INCORRECT_WRITE_RETURN;;
return INCORRECT_WRITE_RETURN;
;
}
return 0;
}
int write_zlib_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_header *z_hdr)
int
write_zlib_header(uint8_t *hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_header *z_hdr)
{
struct isal_zstream stream;
uint32_t hdr_len = zlib_header_size(z_hdr);
@ -472,13 +486,15 @@ int write_zlib_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_
if (len) {
print_zlib_final_verbose(hdr_buf, hdr_buf_len, z_hdr, NULL);
print_error(INCORRECT_WRITE_RETURN);
return INCORRECT_WRITE_RETURN;;
return INCORRECT_WRITE_RETURN;
;
}
return 0;
}
int compare_gzip_headers(struct isal_gzip_header *gz_hdr1, struct isal_gzip_header *gz_hdr2)
int
compare_gzip_headers(struct isal_gzip_header *gz_hdr1, struct isal_gzip_header *gz_hdr2)
{
int ret = 0;
uint32_t max_len;
@ -526,7 +542,8 @@ int compare_gzip_headers(struct isal_gzip_header *gz_hdr1, struct isal_gzip_head
return ret;
}
int compare_zlib_headers(struct isal_zlib_header *z_hdr1, struct isal_zlib_header *z_hdr2)
int
compare_zlib_headers(struct isal_zlib_header *z_hdr1, struct isal_zlib_header *z_hdr2)
{
if (z_hdr1->info != z_hdr2->info)
return INCORRECT_INFO;
@ -543,7 +560,8 @@ int compare_zlib_headers(struct isal_zlib_header *z_hdr1, struct isal_zlib_heade
return 0;
}
int read_gzip_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len,
int
read_gzip_header_simple(uint8_t *hdr_buf, uint32_t hdr_buf_len,
struct isal_gzip_header *gz_hdr_orig)
{
@ -551,7 +569,7 @@ int read_gzip_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len,
struct inflate_state state;
struct isal_gzip_header gz_hdr;
rand_buf((uint8_t *) & gz_hdr, sizeof(gz_hdr));
rand_buf((uint8_t *) &gz_hdr, sizeof(gz_hdr));
gz_hdr.extra_buf_len = gz_hdr_orig->extra_buf_len;
gz_hdr.name_buf_len = gz_hdr_orig->name_buf_len;
gz_hdr.comment_buf_len = gz_hdr_orig->comment_buf_len;
@ -587,15 +605,15 @@ int read_gzip_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len,
return ret;
}
int read_zlib_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len,
struct isal_zlib_header *z_hdr_orig)
int
read_zlib_header_simple(uint8_t *hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_header *z_hdr_orig)
{
int ret = 0;
struct inflate_state state;
struct isal_zlib_header z_hdr;
rand_buf((uint8_t *) & z_hdr, sizeof(z_hdr));
rand_buf((uint8_t *) &z_hdr, sizeof(z_hdr));
isal_inflate_init(&state);
state.next_in = hdr_buf;
@ -618,7 +636,8 @@ int read_zlib_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len,
return ret;
}
int read_gzip_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len,
int
read_gzip_header_streaming(uint8_t *hdr_buf, uint32_t hdr_buf_len,
struct isal_gzip_header *gz_hdr_orig)
{
int ret = 0;
@ -628,7 +647,7 @@ int read_gzip_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len,
struct isal_gzip_header gz_hdr;
void *tmp_ptr;
rand_buf((uint8_t *) & gz_hdr, sizeof(gz_hdr));
rand_buf((uint8_t *) &gz_hdr, sizeof(gz_hdr));
max_dec_size = (rand() % hdr_buf_len) + 2;
@ -753,7 +772,8 @@ int read_gzip_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len,
return ret;
}
int read_zlib_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len,
int
read_zlib_header_streaming(uint8_t *hdr_buf, uint32_t hdr_buf_len,
struct isal_zlib_header *z_hdr_orig)
{
int ret = ISAL_END_INPUT;
@ -761,7 +781,7 @@ int read_zlib_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len,
struct inflate_state state;
struct isal_zlib_header z_hdr;
rand_buf((uint8_t *) & z_hdr, sizeof(z_hdr));
rand_buf((uint8_t *) &z_hdr, sizeof(z_hdr));
max_dec_size = (rand() % hdr_buf_len) + 2;
@ -795,7 +815,8 @@ int read_zlib_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len,
return ret;
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
uint8_t *hdr_buf = NULL;
uint32_t hdr_buf_len;
@ -813,7 +834,7 @@ int main(int argc, char *argv[])
printf("gzip wrapper test: ");
for (i = 0; i < RANDOMS; i++) {
rand_buf((uint8_t *) & gz_hdr_orig, sizeof(gz_hdr_orig));
rand_buf((uint8_t *) &gz_hdr_orig, sizeof(gz_hdr_orig));
ret = gen_rand_gzip_header(&gz_hdr_orig);
if (ret) {
@ -895,7 +916,7 @@ int main(int argc, char *argv[])
printf("igzip wrapper_hdr test finished: All tests passed \n");
ret = 0;
exit:
exit:
if (hdr_buf != NULL)
free(hdr_buf);

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,8 @@
#include "huff_codes.h"
#include "unaligned.h"
static inline void heapify(uint64_t * heap, uint64_t heap_size, uint64_t index)
static inline void
heapify(uint64_t *heap, uint64_t heap_size, uint64_t index)
{
uint64_t child = 2 * index, tmp;
while (child <= heap_size) {
@ -48,16 +49,17 @@ static inline void heapify(uint64_t * heap, uint64_t heap_size, uint64_t index)
}
}
void build_heap(uint64_t * heap, uint64_t heap_size)
void
build_heap(uint64_t *heap, uint64_t heap_size)
{
uint64_t i;
heap[heap_size + 1] = -1;
for (i = heap_size / 2; i > 0; i--)
heapify(heap, heap_size, i);
}
uint32_t build_huff_tree(struct heap_tree *heap_space, uint64_t heap_size, uint64_t node_ptr)
uint32_t
build_huff_tree(struct heap_tree *heap_space, uint64_t heap_size, uint64_t node_ptr)
{
uint64_t *heap = (uint64_t *) heap_space;
uint64_t h1, h2;
@ -77,7 +79,6 @@ uint32_t build_huff_tree(struct heap_tree *heap_space, uint64_t heap_size, uint6
store_native_u16_to_u64(&heap[node_ptr], h1);
store_native_u16_to_u64(&heap[node_ptr - 1], h2);
node_ptr -= 2;
}
h1 = heap[1];
store_native_u16_to_u64(&heap[node_ptr], h1);

View File

@ -48,7 +48,7 @@
/* MIN_REPEAT_LEN currently optimizes storage space, another possibility is to
* find the size which optimizes speed instead.*/
#define MIN_REPEAT_LEN 4*1024
#define MIN_REPEAT_LEN 4 * 1024
#define HEADER_LENGTH 16
@ -56,12 +56,11 @@
* smaller than 258 */
#define MAX_FIXUP_CODE_LENGTH 8
/* Headers for constant 0x00 and 0xFF blocks
* This also contains the first literal character. */
const uint32_t repeated_char_header[2][5] = {
{ 0x0121c0ec, 0xc30c0000, 0x7d57fab0, 0x49270938}, /* Deflate header for 0x00 */
{ 0x0121c0ec, 0xc30c0000, 0x7baaff30, 0x49270938} /* Deflate header for 0xFF */
{ 0x0121c0ec, 0xc30c0000, 0x7d57fab0, 0x49270938 }, /* Deflate header for 0x00 */
{ 0x0121c0ec, 0xc30c0000, 0x7baaff30, 0x49270938 } /* Deflate header for 0xFF */
};

File diff suppressed because it is too large Load Diff