mirror of
https://github.com/intel/isa-l.git
synced 2024-12-12 09:23:50 +01:00
igzip: reformat using new code style
Signed-off-by: Marcel Cornu <marcel.d.cornu@intel.com>
This commit is contained in:
parent
9d99f8215d
commit
55fbfabfc6
@ -31,221 +31,215 @@
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_adler32)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_ASIMD)
|
||||
return PROVIDER_INFO(adler32_neon);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_ASIMD)
|
||||
return PROVIDER_INFO(adler32_neon);
|
||||
#elif defined(__APPLE__)
|
||||
return PROVIDER_INFO(adler32_neon);
|
||||
return PROVIDER_INFO(adler32_neon);
|
||||
#endif
|
||||
return PROVIDER_BASIC(adler32);
|
||||
|
||||
return PROVIDER_BASIC(adler32);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_body)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_body_aarch64);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_body_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_body_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_body_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_body);
|
||||
|
||||
return PROVIDER_BASIC(isal_deflate_body);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_finish)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_finish_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_finish_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_finish_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_finish_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_finish);
|
||||
|
||||
return PROVIDER_BASIC(isal_deflate_finish);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_body_lvl1)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_icf_body_hash_hist);
|
||||
return PROVIDER_BASIC(isal_deflate_icf_body_hash_hist);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_finish_lvl1)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_icf_finish_hash_hist);
|
||||
return PROVIDER_BASIC(isal_deflate_icf_finish_hash_hist);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_body_lvl2)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_body_hash_hist_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_icf_body_hash_hist);
|
||||
return PROVIDER_BASIC(isal_deflate_icf_body_hash_hist);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_finish_lvl2)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_hist_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_icf_finish_hash_hist);
|
||||
return PROVIDER_BASIC(isal_deflate_icf_finish_hash_hist);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_body_lvl3)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(icf_body_hash1_fillgreedy_lazy);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(icf_body_hash1_fillgreedy_lazy);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(icf_body_hash1_fillgreedy_lazy);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(icf_body_hash1_fillgreedy_lazy);
|
||||
#endif
|
||||
return PROVIDER_INFO(icf_body_hash1_fillgreedy_lazy);
|
||||
return PROVIDER_INFO(icf_body_hash1_fillgreedy_lazy);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_finish_lvl3)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_map_base);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_map_base);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_map_base);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_icf_finish_hash_map_base);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_icf_finish_hash_map);
|
||||
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)
|
||||
{
|
||||
return PROVIDER_INFO(encode_deflate_icf_aarch64);
|
||||
return PROVIDER_INFO(encode_deflate_icf_aarch64);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_update_histogram)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_update_histogram_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_update_histogram_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_update_histogram_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_update_histogram_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_update_histogram);
|
||||
return PROVIDER_BASIC(isal_update_histogram);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(gen_icf_map_lh1)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32) {
|
||||
return PROVIDER_INFO(gen_icf_map_h1_aarch64);
|
||||
}
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32) {
|
||||
return PROVIDER_INFO(gen_icf_map_h1_aarch64);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(gen_icf_map_h1_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(gen_icf_map_h1_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(gen_icf_map_h1);
|
||||
return PROVIDER_BASIC(gen_icf_map_h1);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_hash_lvl0)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_hash_lvl1)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_hash_lvl2)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(isal_deflate_hash_lvl3)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(isal_deflate_hash_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
return PROVIDER_BASIC(isal_deflate_hash);
|
||||
}
|
||||
|
||||
DEFINE_INTERFACE_DISPATCHER(decode_huffman_code_block_stateless)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(decode_huffman_code_block_stateless_aarch64);
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if (auxval & HWCAP_CRC32)
|
||||
return PROVIDER_INFO(decode_huffman_code_block_stateless_aarch64);
|
||||
#elif defined(__APPLE__)
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(decode_huffman_code_block_stateless_aarch64);
|
||||
if (sysctlEnabled(SYSCTL_CRC32_KEY))
|
||||
return PROVIDER_INFO(decode_huffman_code_block_stateless_aarch64);
|
||||
#endif
|
||||
return PROVIDER_BASIC(decode_huffman_code_block_stateless);
|
||||
return PROVIDER_BASIC(decode_huffman_code_block_stateless);
|
||||
}
|
||||
|
@ -30,34 +30,35 @@
|
||||
#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;
|
||||
uint8_t *end, *next = start;
|
||||
uint64_t A, B;
|
||||
|
||||
A = adler32 & 0xffff;
|
||||
B = adler32 >> 16;
|
||||
A = adler32 & 0xffff;
|
||||
B = adler32 >> 16;
|
||||
|
||||
while (length > MAX_ADLER_BUF) {
|
||||
end = next + MAX_ADLER_BUF;
|
||||
for (; next < end; next++) {
|
||||
A += *next;
|
||||
B += A;
|
||||
}
|
||||
while (length > MAX_ADLER_BUF) {
|
||||
end = next + MAX_ADLER_BUF;
|
||||
for (; next < end; next++) {
|
||||
A += *next;
|
||||
B += A;
|
||||
}
|
||||
|
||||
A = A % ADLER_MOD;
|
||||
B = B % ADLER_MOD;
|
||||
length -= MAX_ADLER_BUF;
|
||||
}
|
||||
A = A % ADLER_MOD;
|
||||
B = B % ADLER_MOD;
|
||||
length -= MAX_ADLER_BUF;
|
||||
}
|
||||
|
||||
end = next + length;
|
||||
for (; next < end; next++) {
|
||||
A += *next;
|
||||
B += A;
|
||||
}
|
||||
end = next + length;
|
||||
for (; next < end; next++) {
|
||||
A += *next;
|
||||
B += A;
|
||||
}
|
||||
|
||||
A = A % ADLER_MOD;
|
||||
B = B % ADLER_MOD;
|
||||
A = A % ADLER_MOD;
|
||||
B = B % ADLER_MOD;
|
||||
|
||||
return B << 16 | A;
|
||||
return B << 16 | A;
|
||||
}
|
||||
|
@ -35,40 +35,41 @@
|
||||
#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;
|
||||
struct perf start;
|
||||
void *buf;
|
||||
uint32_t checksum = 0;
|
||||
struct perf start;
|
||||
|
||||
printf("adler32_perf:\n");
|
||||
printf("adler32_perf:\n");
|
||||
|
||||
if (posix_memalign(&buf, 1024, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
memset(buf, 0, TEST_LEN);
|
||||
if (posix_memalign(&buf, 1024, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
memset(buf, 0, TEST_LEN);
|
||||
|
||||
BENCHMARK(&start, BENCHMARK_TIME, checksum |= isal_adler32(TEST_SEED, buf, TEST_LEN));
|
||||
printf("adler32" TEST_TYPE_STR ": ");
|
||||
perf_print(start, (long long)TEST_LEN);
|
||||
BENCHMARK(&start, BENCHMARK_TIME, checksum |= isal_adler32(TEST_SEED, buf, TEST_LEN));
|
||||
printf("adler32" TEST_TYPE_STR ": ");
|
||||
perf_print(start, (long long) TEST_LEN);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
113
igzip/bitbuf2.h
113
igzip/bitbuf2.h
@ -41,89 +41,100 @@
|
||||
* 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;
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
bits = me->m_bit_count & ~7;
|
||||
me->m_bit_count -= bits;
|
||||
me->m_out_buf += bits / 8;
|
||||
me->m_bits >>= bits;
|
||||
|
||||
uint32_t bits;
|
||||
store_le_u64(me->m_out_buf, me->m_bits);
|
||||
bits = me->m_bit_count & ~7;
|
||||
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) {
|
||||
store_le_u64(me->m_out_buf, me->m_bits);
|
||||
bytes = (me->m_bit_count + 7) / 8;
|
||||
me->m_out_buf += bytes;
|
||||
}
|
||||
me->m_bits = 0;
|
||||
me->m_bit_count = 0;
|
||||
uint32_t bytes;
|
||||
if (me->m_bit_count) {
|
||||
store_le_u64(me->m_out_buf, me->m_bits);
|
||||
bytes = (me->m_bit_count + 7) / 8;
|
||||
me->m_out_buf += bytes;
|
||||
}
|
||||
me->m_bits = 0;
|
||||
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. */
|
||||
if (63 - me->m_bit_count < num_bits)
|
||||
flush_bits(me);
|
||||
/* Checks if bitbuf has num_bits extra space and flushes the bytes in
|
||||
* the bitbuf if it doesn't. */
|
||||
if (63 - me->m_bit_count < 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;
|
||||
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)
|
||||
{ /* 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(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)
|
||||
{ /* 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);
|
||||
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
|
||||
|
@ -36,294 +36,307 @@
|
||||
#include "test.h"
|
||||
|
||||
#ifndef TEST_SEED
|
||||
# define TEST_SEED 0x1234
|
||||
#define TEST_SEED 0x1234
|
||||
#endif
|
||||
|
||||
#define MAX_BUF 512
|
||||
#define TEST_SIZE 20
|
||||
#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;
|
||||
checksum32_func_t checksum32_func_call;
|
||||
checksum32_func_t checksum32_ref_call;
|
||||
char *note;
|
||||
checksum32_func_t checksum32_func_call;
|
||||
checksum32_func_t checksum32_ref_call;
|
||||
} 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++)
|
||||
buf[i] = rand();
|
||||
long i;
|
||||
for (i = 0; i < buffer_size; i++)
|
||||
buf[i] = rand();
|
||||
}
|
||||
|
||||
// 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;
|
||||
func_case_t *test_func;
|
||||
int fail = 0, fail_case;
|
||||
int i, ret;
|
||||
func_case_t *test_func;
|
||||
|
||||
// Align to MAX_BUF boundary
|
||||
ret = posix_memalign(&buf_alloc, MAX_BUF, MAX_BUF * TEST_SIZE);
|
||||
if (ret) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
srand(TEST_SEED);
|
||||
printf("CHECKSUM32 Tests seed=0x%x\n", TEST_SEED);
|
||||
// Align to MAX_BUF boundary
|
||||
ret = posix_memalign(&buf_alloc, MAX_BUF, MAX_BUF * TEST_SIZE);
|
||||
if (ret) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
srand(TEST_SEED);
|
||||
printf("CHECKSUM32 Tests seed=0x%x\n", TEST_SEED);
|
||||
|
||||
for (i = 0; i < sizeof(test_funcs) / sizeof(test_funcs[0]); i++) {
|
||||
fail_case = 0;
|
||||
test_func = &test_funcs[i];
|
||||
for (i = 0; i < sizeof(test_funcs) / sizeof(test_funcs[0]); i++) {
|
||||
fail_case = 0;
|
||||
test_func = &test_funcs[i];
|
||||
|
||||
printf("Test %s ", test_func->note);
|
||||
fail_case += zeros_test(test_func);
|
||||
fail_case += simple_pattern_test(test_func);
|
||||
fail_case += seeds_sizes_test(test_func);
|
||||
fail_case += eob_test(test_func);
|
||||
fail_case += update_test(test_func);
|
||||
fail_case += update_over_mod_test(test_func);
|
||||
printf("Test %s done: %s\n", test_func->note, fail_case ? "Fail" : "Pass");
|
||||
printf("Test %s ", test_func->note);
|
||||
fail_case += zeros_test(test_func);
|
||||
fail_case += simple_pattern_test(test_func);
|
||||
fail_case += seeds_sizes_test(test_func);
|
||||
fail_case += eob_test(test_func);
|
||||
fail_case += update_test(test_func);
|
||||
fail_case += update_over_mod_test(test_func);
|
||||
printf("Test %s done: %s\n", test_func->note, fail_case ? "Fail" : "Pass");
|
||||
|
||||
if (fail_case) {
|
||||
printf("\n%s Failed %d tests\n", test_func->note, fail_case);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
if (fail_case) {
|
||||
printf("\n%s Failed %d tests\n", test_func->note, fail_case);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("CHECKSUM32 Tests all done: %s\n", fail ? "Fail" : "Pass");
|
||||
printf("CHECKSUM32 Tests all done: %s\n", fail ? "Fail" : "Pass");
|
||||
|
||||
aligned_free(buf_alloc);
|
||||
aligned_free(buf_alloc);
|
||||
|
||||
return fail;
|
||||
return fail;
|
||||
}
|
||||
|
||||
// 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;
|
||||
uint32_t c_dut, c_ref;
|
||||
int fail = 0;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("\n opt ref\n");
|
||||
printf(" ------ ------\n");
|
||||
printf("checksum zero = 0x%8x 0x%8x \n", c_dut, c_ref);
|
||||
}
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("\n opt ref\n");
|
||||
printf(" ------ ------\n");
|
||||
printf("checksum zero = 0x%8x 0x%8x \n", c_dut, c_ref);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
|
||||
return fail;
|
||||
return fail;
|
||||
}
|
||||
|
||||
// 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;
|
||||
uint32_t c_dut, c_ref;
|
||||
int fail = 0;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
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);
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("fail checksum all 8a = 0x%8x 0x%8x\n", c_dut, c_ref);
|
||||
}
|
||||
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);
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("fail checksum all 8a = 0x%8x 0x%8x\n", c_dut, c_ref);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
|
||||
return fail;
|
||||
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;
|
||||
int i;
|
||||
uint32_t r, s;
|
||||
unsigned char *buf = NULL;
|
||||
uint32_t c_dut, c_ref;
|
||||
int fail = 0;
|
||||
int i;
|
||||
uint32_t r, s;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
// Do a few random tests
|
||||
buf = (unsigned char *)buf_alloc; //reset buf
|
||||
r = rand();
|
||||
rand_buffer(buf, MAX_BUF * TEST_SIZE);
|
||||
// Do a few random tests
|
||||
buf = (unsigned char *) buf_alloc; // reset buf
|
||||
r = rand();
|
||||
rand_buffer(buf, MAX_BUF * TEST_SIZE);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, MAX_BUF);
|
||||
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);
|
||||
}
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, MAX_BUF);
|
||||
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);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
buf += MAX_BUF;
|
||||
}
|
||||
buf += MAX_BUF;
|
||||
}
|
||||
|
||||
// Do a few random sizes
|
||||
buf = (unsigned char *)buf_alloc; //reset buf
|
||||
r = rand();
|
||||
// Do a few random sizes
|
||||
buf = (unsigned char *) buf_alloc; // reset buf
|
||||
r = rand();
|
||||
|
||||
for (i = MAX_BUF; i >= 0; i--) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, i);
|
||||
c_ref = test_func->checksum32_ref_call(r, buf, i);
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("fail random size%i 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
for (i = MAX_BUF; i >= 0; i--) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, i);
|
||||
c_ref = test_func->checksum32_ref_call(r, buf, i);
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("fail random size%i 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Try different seeds
|
||||
for (s = 0; s < 20; s++) {
|
||||
buf = (unsigned char *)buf_alloc; //reset buf
|
||||
// Try different seeds
|
||||
for (s = 0; s < 20; s++) {
|
||||
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
|
||||
r = rand(); // just to get a new seed
|
||||
rand_buffer(buf, MAX_BUF * TEST_SIZE); // new pseudo-rand data
|
||||
|
||||
#ifdef TEST_VERBOSE
|
||||
printf("seed = 0x%x\n", r);
|
||||
printf("seed = 0x%x\n", r);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, MAX_BUF);
|
||||
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);
|
||||
}
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, MAX_BUF);
|
||||
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);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
buf += MAX_BUF;
|
||||
}
|
||||
}
|
||||
buf += MAX_BUF;
|
||||
}
|
||||
}
|
||||
|
||||
return fail;
|
||||
return fail;
|
||||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
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);
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("fail checksum eob rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
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);
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("fail checksum eob rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return fail;
|
||||
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;
|
||||
int i;
|
||||
uint32_t r;
|
||||
unsigned char *buf = NULL;
|
||||
uint32_t c_dut, c_ref;
|
||||
int fail = 0;
|
||||
int i;
|
||||
uint32_t r;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
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);
|
||||
// Process buf with update method.
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, MAX_BUF);
|
||||
// Update checksum seeds and buf pointer.
|
||||
r = c_dut;
|
||||
buf += MAX_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);
|
||||
// Process buf with update method.
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
c_dut = test_func->checksum32_func_call(r, buf, MAX_BUF);
|
||||
// Update checksum seeds and buf pointer.
|
||||
r = c_dut;
|
||||
buf += MAX_BUF;
|
||||
}
|
||||
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
|
||||
return fail;
|
||||
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;
|
||||
int i;
|
||||
unsigned char *buf = NULL;
|
||||
uint32_t c_dut, c_ref;
|
||||
int fail = 0;
|
||||
int i;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
buf = malloc(ADLER_MOD);
|
||||
if (buf == NULL)
|
||||
return 1;
|
||||
memset(buf, 0xff, ADLER_MOD);
|
||||
buf = malloc(ADLER_MOD);
|
||||
if (buf == NULL)
|
||||
return 1;
|
||||
memset(buf, 0xff, ADLER_MOD);
|
||||
|
||||
c_ref = c_dut = rand();
|
||||
c_ref = c_dut = rand();
|
||||
|
||||
// Process buf with update method.
|
||||
for (i = 0; i < 20; i++) {
|
||||
c_ref = test_func->checksum32_ref_call(c_ref, buf, ADLER_MOD - 64);
|
||||
c_dut = test_func->checksum32_func_call(c_dut, buf, ADLER_MOD - 64);
|
||||
}
|
||||
// Process buf with update method.
|
||||
for (i = 0; i < 20; i++) {
|
||||
c_ref = test_func->checksum32_ref_call(c_ref, buf, ADLER_MOD - 64);
|
||||
c_dut = test_func->checksum32_func_call(c_dut, buf, ADLER_MOD - 64);
|
||||
}
|
||||
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
if (c_dut != c_ref) {
|
||||
fail++;
|
||||
printf("checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref);
|
||||
}
|
||||
#ifdef TEST_VERBOSE
|
||||
else
|
||||
printf(".");
|
||||
else
|
||||
printf(".");
|
||||
#endif
|
||||
|
||||
free(buf);
|
||||
return fail;
|
||||
free(buf);
|
||||
return fail;
|
||||
}
|
||||
|
@ -8,95 +8,69 @@
|
||||
#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;
|
||||
for (i = 0; i < len; i++)
|
||||
crc = (crc >> 8) ^ inflate_crc_table[(crc & 0xff) ^ buf[i]];
|
||||
return ~crc;
|
||||
uint64_t i;
|
||||
crc = ~crc;
|
||||
for (i = 0; i < len; i++)
|
||||
crc = (crc >> 8) ^ inflate_crc_table[(crc & 0xff) ^ buf[i]];
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
#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;
|
||||
uint32_t b = init >> 16;
|
||||
uint64_t i;
|
||||
uint32_t a = init & 0xffff;
|
||||
uint32_t b = init >> 16;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
a = (a + buf[i]) % ADLER_MOD;
|
||||
b = (b + a) % ADLER_MOD;
|
||||
}
|
||||
return (b << 16) | a;
|
||||
for (i = 0; i < len; i++) {
|
||||
a = (a + buf[i]) % ADLER_MOD;
|
||||
b = (b + a) % ADLER_MOD;
|
||||
}
|
||||
return (b << 16) | a;
|
||||
}
|
||||
|
||||
#endif /* CHECKSUM_TEST_REF_H */
|
||||
|
@ -4,35 +4,35 @@
|
||||
#include <memory.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
|
||||
#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 hufftables_icf *hufftables)
|
||||
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;
|
||||
struct huff_code lsym, dsym;
|
||||
|
||||
while (next_in < end_in && !is_full(bb)) {
|
||||
lsym = hufftables->lit_len_table[next_in->lit_len];
|
||||
dsym = hufftables->dist_lit_table[next_in->lit_dist];
|
||||
while (next_in < end_in && !is_full(bb)) {
|
||||
lsym = hufftables->lit_len_table[next_in->lit_len];
|
||||
dsym = hufftables->dist_lit_table[next_in->lit_dist];
|
||||
|
||||
// insert ll code, dist_code, and extra_bits
|
||||
write_bits_unsafe(bb, lsym.code_and_extra, lsym.length);
|
||||
write_bits_unsafe(bb, dsym.code, dsym.length);
|
||||
write_bits_unsafe(bb, next_in->dist_extra, dsym.extra_bit_count);
|
||||
flush_bits(bb);
|
||||
// insert ll code, dist_code, and extra_bits
|
||||
write_bits_unsafe(bb, lsym.code_and_extra, lsym.length);
|
||||
write_bits_unsafe(bb, dsym.code, dsym.length);
|
||||
write_bits_unsafe(bb, next_in->dist_extra, dsym.extra_bit_count);
|
||||
flush_bits(bb);
|
||||
|
||||
next_in++;
|
||||
}
|
||||
next_in++;
|
||||
}
|
||||
|
||||
return next_in;
|
||||
return next_in;
|
||||
}
|
||||
|
@ -6,31 +6,32 @@
|
||||
#include "huff_codes.h"
|
||||
|
||||
/* Deflate Intermediate Compression Format */
|
||||
#define LIT_LEN_BIT_COUNT 10
|
||||
#define LIT_LEN_MASK ((1 << LIT_LEN_BIT_COUNT) - 1)
|
||||
#define LIT_LEN_BIT_COUNT 10
|
||||
#define LIT_LEN_MASK ((1 << LIT_LEN_BIT_COUNT) - 1)
|
||||
#define DIST_LIT_BIT_COUNT 9
|
||||
#define DIST_LIT_MASK ((1 << DIST_LIT_BIT_COUNT) - 1)
|
||||
#define ICF_DIST_OFFSET LIT_LEN_BIT_COUNT
|
||||
#define NULL_DIST_SYM 30
|
||||
#define DIST_LIT_MASK ((1 << DIST_LIT_BIT_COUNT) - 1)
|
||||
#define ICF_DIST_OFFSET LIT_LEN_BIT_COUNT
|
||||
#define NULL_DIST_SYM 30
|
||||
|
||||
#define LEN_START ISAL_DEF_LIT_SYMBOLS
|
||||
#define LEN_OFFSET (LEN_START - ISAL_DEF_MIN_MATCH)
|
||||
#define LEN_MAX (LEN_OFFSET + ISAL_DEF_MAX_MATCH)
|
||||
#define LIT_START (NULL_DIST_SYM + 1)
|
||||
#define LEN_START ISAL_DEF_LIT_SYMBOLS
|
||||
#define LEN_OFFSET (LEN_START - ISAL_DEF_MIN_MATCH)
|
||||
#define LEN_MAX (LEN_OFFSET + ISAL_DEF_MAX_MATCH)
|
||||
#define LIT_START (NULL_DIST_SYM + 1)
|
||||
#define ICF_CODE_LEN 32
|
||||
|
||||
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
|
||||
|
@ -4,38 +4,39 @@
|
||||
|
||||
#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;
|
||||
uint32_t i, j;
|
||||
uint32_t *s = ll_hist, x, *p;
|
||||
|
||||
s[265] += s[266];
|
||||
s[266] = s[267] + s[268];
|
||||
s[267] = s[269] + s[270];
|
||||
s[268] = s[271] + s[272];
|
||||
s[269] = s[273] + s[274] + s[275] + s[276];
|
||||
s[270] = s[277] + s[278] + s[279] + s[280];
|
||||
s[271] = s[281] + s[282] + s[283] + s[284];
|
||||
s[272] = s[285] + s[286] + s[287] + s[288];
|
||||
p = s + 289;
|
||||
for (i = 273; i < 277; i++) {
|
||||
x = *(p++);
|
||||
for (j = 1; j < 8; j++)
|
||||
x += *(p++);
|
||||
s[i] = x;
|
||||
}
|
||||
for (; i < 281; i++) {
|
||||
x = *(p++);
|
||||
for (j = 1; j < 16; j++)
|
||||
x += *(p++);
|
||||
s[i] = x;
|
||||
}
|
||||
for (; i < 285; i++) {
|
||||
x = *(p++);
|
||||
for (j = 1; j < 32; j++)
|
||||
x += *(p++);
|
||||
s[i] = x;
|
||||
}
|
||||
s[284] -= s[512];
|
||||
s[285] = s[512];
|
||||
s[265] += s[266];
|
||||
s[266] = s[267] + s[268];
|
||||
s[267] = s[269] + s[270];
|
||||
s[268] = s[271] + s[272];
|
||||
s[269] = s[273] + s[274] + s[275] + s[276];
|
||||
s[270] = s[277] + s[278] + s[279] + s[280];
|
||||
s[271] = s[281] + s[282] + s[283] + s[284];
|
||||
s[272] = s[285] + s[286] + s[287] + s[288];
|
||||
p = s + 289;
|
||||
for (i = 273; i < 277; i++) {
|
||||
x = *(p++);
|
||||
for (j = 1; j < 8; j++)
|
||||
x += *(p++);
|
||||
s[i] = x;
|
||||
}
|
||||
for (; i < 281; i++) {
|
||||
x = *(p++);
|
||||
for (j = 1; j < 16; j++)
|
||||
x += *(p++);
|
||||
s[i] = x;
|
||||
}
|
||||
for (; i < 285; i++) {
|
||||
x = *(p++);
|
||||
for (j = 1; j < 32; j++)
|
||||
x += *(p++);
|
||||
s[i] = x;
|
||||
}
|
||||
s[284] -= s[512];
|
||||
s[285] = s[512];
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void flatten_ll(uint32_t *ll_hist);
|
||||
void
|
||||
flatten_ll(uint32_t *ll_hist);
|
||||
|
@ -72,9 +72,9 @@
|
||||
|
||||
#define MAX_HEADER_SIZE ISAL_DEF_MAX_HDR_SIZE
|
||||
|
||||
#define GZIP_HEADER_SIZE 10
|
||||
#define GZIP_HEADER_SIZE 10
|
||||
#define GZIP_TRAILER_SIZE 8
|
||||
#define ZLIB_HEADER_SIZE 2
|
||||
#define ZLIB_HEADER_SIZE 2
|
||||
#define ZLIB_TRAILER_SIZE 4
|
||||
|
||||
/**
|
||||
@ -86,26 +86,26 @@
|
||||
* @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);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%02x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%02x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
int i;
|
||||
fprintf(outfile, "%s", header);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%02x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%02x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,26 +117,26 @@ 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);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
int i;
|
||||
fprintf(outfile, "%s", header);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,341 +148,348 @@ 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);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%08x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%08x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
int i;
|
||||
fprintf(outfile, "%s", header);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%08x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "%s", begin_line);
|
||||
else
|
||||
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);
|
||||
fprintf(output_file, "struct isal_hufftables %s = {\n\n", hufftables_name);
|
||||
|
||||
fprint_uint8_table(output_file, hufftables->deflate_hdr,
|
||||
hufftables->deflate_hdr_count +
|
||||
(hufftables->deflate_hdr_extra_bits + 7) / 8,
|
||||
"\t.deflate_hdr = {", "},\n\n", "\t\t");
|
||||
fprint_uint8_table(output_file, hufftables->deflate_hdr,
|
||||
hufftables->deflate_hdr_count +
|
||||
(hufftables->deflate_hdr_extra_bits + 7) / 8,
|
||||
"\t.deflate_hdr = {", "},\n\n", "\t\t");
|
||||
|
||||
fprintf(output_file, "\t.deflate_hdr_count = %d,\n", hufftables->deflate_hdr_count);
|
||||
fprintf(output_file, "\t.deflate_hdr_extra_bits = %d,\n\n",
|
||||
hufftables->deflate_hdr_extra_bits);
|
||||
fprintf(output_file, "\t.deflate_hdr_count = %d,\n", hufftables->deflate_hdr_count);
|
||||
fprintf(output_file, "\t.deflate_hdr_extra_bits = %d,\n\n",
|
||||
hufftables->deflate_hdr_extra_bits);
|
||||
|
||||
fprint_uint32_table(output_file, hufftables->dist_table, IGZIP_DIST_TABLE_SIZE,
|
||||
"\t.dist_table = {", "},\n\n", "\t\t");
|
||||
fprint_uint32_table(output_file, hufftables->dist_table, IGZIP_DIST_TABLE_SIZE,
|
||||
"\t.dist_table = {", "},\n\n", "\t\t");
|
||||
|
||||
fprint_uint32_table(output_file, hufftables->len_table, IGZIP_LEN_TABLE_SIZE,
|
||||
"\t.len_table = {", "},\n\n", "\t\t");
|
||||
fprint_uint32_table(output_file, hufftables->len_table, IGZIP_LEN_TABLE_SIZE,
|
||||
"\t.len_table = {", "},\n\n", "\t\t");
|
||||
|
||||
fprint_uint16_table(output_file, hufftables->lit_table, IGZIP_LIT_TABLE_SIZE,
|
||||
"\t.lit_table = {", "},\n\n", "\t\t");
|
||||
fprint_uint8_table(output_file, hufftables->lit_table_sizes, IGZIP_LIT_TABLE_SIZE,
|
||||
"\t.lit_table_sizes = {", "},\n\n", "\t\t");
|
||||
fprint_uint16_table(output_file, hufftables->lit_table, IGZIP_LIT_TABLE_SIZE,
|
||||
"\t.lit_table = {", "},\n\n", "\t\t");
|
||||
fprint_uint8_table(output_file, hufftables->lit_table_sizes, IGZIP_LIT_TABLE_SIZE,
|
||||
"\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");
|
||||
fprint_uint8_table(output_file, hufftables->dcodes_sizes,
|
||||
ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET,
|
||||
"\t.dcodes_sizes = {", "}\n", "\t\t");
|
||||
fprintf(output_file, "};\n");
|
||||
fprint_uint16_table(output_file, hufftables->dcodes,
|
||||
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");
|
||||
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, "#include <stdint.h>\n");
|
||||
fprintf(output_file, "#include <igzip_lib.h>\n\n");
|
||||
|
||||
fprintf(output_file, "#if IGZIP_HIST_SIZE > %d\n"
|
||||
"# error \"Invalid history size for the custom hufftable\"\n"
|
||||
"#endif\n", IGZIP_HIST_SIZE);
|
||||
fprintf(output_file,
|
||||
"#if IGZIP_HIST_SIZE > %d\n"
|
||||
"# error \"Invalid history size for the custom hufftable\"\n"
|
||||
"#endif\n",
|
||||
IGZIP_HIST_SIZE);
|
||||
|
||||
#ifdef LONGER_HUFFTABLE
|
||||
fprintf(output_file, "#ifndef LONGER_HUFFTABLE\n"
|
||||
"# error \"Custom hufftable requires LONGER_HUFFTABLE to be defined \"\n"
|
||||
"#endif\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"
|
||||
"# error \"Custom hufftable requires LONGER_HUFFTABLE to not be defined \"\n"
|
||||
"#endif\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, "\n");
|
||||
|
||||
fprintf(output_file, "const uint8_t gzip_hdr[] = {\n"
|
||||
"\t0x1f, 0x8b, 0x08, 0x00, 0x00,\n" "\t0x00, 0x00, 0x00, 0x00, 0xff\t};\n\n");
|
||||
fprintf(output_file, "const uint8_t gzip_hdr[] = {\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);
|
||||
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);
|
||||
|
||||
fprintf(output_file, "const uint8_t zlib_hdr[] = { 0x78, 0x01 };\n\n");
|
||||
fprintf(output_file, "const uint32_t zlib_hdr_bytes = %d;\n", ZLIB_HEADER_SIZE);
|
||||
fprintf(output_file, "const uint32_t zlib_trl_bytes = %d;\n", ZLIB_TRAILER_SIZE);
|
||||
fprintf(output_file, "const uint8_t zlib_hdr[] = { 0x78, 0x01 };\n\n");
|
||||
fprintf(output_file, "const uint32_t zlib_hdr_bytes = %d;\n", ZLIB_HEADER_SIZE);
|
||||
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) {
|
||||
uint32_t msb = dist > 4 ? bsr(dist - 1) - 2 : 0;
|
||||
return (msb * 2) + ((dist - 1) >> msb);
|
||||
} else {
|
||||
return ~0;
|
||||
}
|
||||
assert(dist <= 32768 && dist > 0);
|
||||
if (dist <= 32768) {
|
||||
uint32_t msb = dist > 4 ? bsr(dist - 1) - 2 : 0;
|
||||
return (msb * 2) + ((dist - 1) >> msb);
|
||||
} else {
|
||||
return ~0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
assert(length > 2 && length < 259);
|
||||
|
||||
/* Based on tables on page 11 in RFC 1951 */
|
||||
if (length < 11)
|
||||
return 257 + length - 3;
|
||||
else if (length < 19)
|
||||
return 261 + (length - 3) / 2;
|
||||
else if (length < 35)
|
||||
return 265 + (length - 3) / 4;
|
||||
else if (length < 67)
|
||||
return 269 + (length - 3) / 8;
|
||||
else if (length < 131)
|
||||
return 273 + (length - 3) / 16;
|
||||
else if (length < 258)
|
||||
return 277 + (length - 3) / 32;
|
||||
else
|
||||
return 285;
|
||||
/* Based on tables on page 11 in RFC 1951 */
|
||||
if (length < 11)
|
||||
return 257 + length - 3;
|
||||
else if (length < 19)
|
||||
return 261 + (length - 3) / 2;
|
||||
else if (length < 35)
|
||||
return 265 + (length - 3) / 4;
|
||||
else if (length < 67)
|
||||
return 269 + (length - 3) / 8;
|
||||
else if (length < 131)
|
||||
return 273 + (length - 3) / 16;
|
||||
else if (length < 258)
|
||||
return 277 + (length - 3) / 32;
|
||||
else
|
||||
return 285;
|
||||
}
|
||||
|
||||
void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int length,
|
||||
struct isal_huff_histogram *histogram)
|
||||
void
|
||||
isal_update_histogram_dict(uint8_t *start_stream, int dict_length, int length,
|
||||
struct isal_huff_histogram *histogram)
|
||||
{
|
||||
uint32_t literal = 0, hash;
|
||||
uint16_t seen, *last_seen = histogram->hash_table;
|
||||
uint8_t *current, *end_stream, *next_hash, *end, *end_dict;
|
||||
uint32_t match_length;
|
||||
uint32_t dist;
|
||||
uint64_t *lit_len_histogram = histogram->lit_len_histogram;
|
||||
uint64_t *dist_histogram = histogram->dist_histogram;
|
||||
uint32_t literal = 0, hash;
|
||||
uint16_t seen, *last_seen = histogram->hash_table;
|
||||
uint8_t *current, *end_stream, *next_hash, *end, *end_dict;
|
||||
uint32_t match_length;
|
||||
uint32_t dist;
|
||||
uint64_t *lit_len_histogram = histogram->lit_len_histogram;
|
||||
uint64_t *dist_histogram = histogram->dist_histogram;
|
||||
|
||||
if (length <= 0)
|
||||
return;
|
||||
if (length <= 0)
|
||||
return;
|
||||
|
||||
end_stream = start_stream + dict_length + length;
|
||||
end_dict = start_stream + dict_length;
|
||||
end_stream = start_stream + dict_length + length;
|
||||
end_dict = start_stream + dict_length;
|
||||
|
||||
memset(last_seen, 0, sizeof(histogram->hash_table)); /* Initialize last_seen to be 0. */
|
||||
memset(last_seen, 0, sizeof(histogram->hash_table)); /* Initialize last_seen to be 0. */
|
||||
|
||||
for (current = start_stream; current < end_dict - 4; current++) {
|
||||
literal = load_le_u32(current);
|
||||
hash = compute_hash(literal) & LVL0_HASH_MASK;
|
||||
last_seen[hash] = (current - start_stream) & 0xFFFF;
|
||||
}
|
||||
for (current = start_stream; current < end_dict - 4; current++) {
|
||||
literal = load_le_u32(current);
|
||||
hash = compute_hash(literal) & LVL0_HASH_MASK;
|
||||
last_seen[hash] = (current - start_stream) & 0xFFFF;
|
||||
}
|
||||
|
||||
for (current = start_stream + dict_length; current < end_stream - 3; current++) {
|
||||
literal = load_le_u32(current);
|
||||
hash = compute_hash(literal) & LVL0_HASH_MASK;
|
||||
seen = last_seen[hash];
|
||||
last_seen[hash] = (current - start_stream) & 0xFFFF;
|
||||
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);
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = current;
|
||||
for (current = start_stream + dict_length; current < end_stream - 3; current++) {
|
||||
literal = load_le_u32(current);
|
||||
hash = compute_hash(literal) & LVL0_HASH_MASK;
|
||||
seen = last_seen[hash];
|
||||
last_seen[hash] = (current - start_stream) & 0xFFFF;
|
||||
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);
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = current;
|
||||
#ifdef ISAL_LIMIT_HASH_UPDATE
|
||||
end = next_hash + 3;
|
||||
end = next_hash + 3;
|
||||
#else
|
||||
end = next_hash + match_length;
|
||||
end = next_hash + match_length;
|
||||
#endif
|
||||
if (end > end_stream - 3)
|
||||
end = end_stream - 3;
|
||||
next_hash++;
|
||||
for (; next_hash < end; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & LVL0_HASH_MASK;
|
||||
last_seen[hash] = (next_hash - start_stream) & 0xFFFF;
|
||||
}
|
||||
if (end > end_stream - 3)
|
||||
end = end_stream - 3;
|
||||
next_hash++;
|
||||
for (; next_hash < end; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & LVL0_HASH_MASK;
|
||||
last_seen[hash] = (next_hash - start_stream) & 0xFFFF;
|
||||
}
|
||||
|
||||
dist_histogram[convert_dist_to_dist_sym(dist)] += 1;
|
||||
lit_len_histogram[convert_length_to_len_sym(match_length)] +=
|
||||
1;
|
||||
current += match_length - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lit_len_histogram[literal & 0xFF] += 1;
|
||||
}
|
||||
dist_histogram[convert_dist_to_dist_sym(dist)] += 1;
|
||||
lit_len_histogram[convert_length_to_len_sym(match_length)] += 1;
|
||||
current += match_length - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lit_len_histogram[literal & 0xFF] += 1;
|
||||
}
|
||||
|
||||
for (; current < end_stream; current++)
|
||||
lit_len_histogram[*current] += 1;
|
||||
for (; current < end_stream; current++)
|
||||
lit_len_histogram[*current] += 1;
|
||||
|
||||
lit_len_histogram[256] += 1;
|
||||
return;
|
||||
lit_len_histogram[256] += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
long int file_length;
|
||||
int argi = 1;
|
||||
uint8_t *stream = NULL;
|
||||
struct isal_hufftables hufftables;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_zstream tmp_stream;
|
||||
FILE *file = NULL;
|
||||
FILE *dict_file = NULL;
|
||||
FILE *hist_file = NULL;
|
||||
long int dict_file_length = 0;
|
||||
long int hist_file_length = 0;
|
||||
uint8_t *dict_stream = NULL;
|
||||
long int file_length;
|
||||
int argi = 1;
|
||||
uint8_t *stream = NULL;
|
||||
struct isal_hufftables hufftables;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_zstream tmp_stream;
|
||||
FILE *file = NULL;
|
||||
FILE *dict_file = NULL;
|
||||
FILE *hist_file = NULL;
|
||||
long int dict_file_length = 0;
|
||||
long int hist_file_length = 0;
|
||||
uint8_t *dict_stream = NULL;
|
||||
|
||||
if (argc == 1) {
|
||||
printf("Error, no input file.\n");
|
||||
return 1;
|
||||
}
|
||||
if (argc == 1) {
|
||||
printf("Error, no input file.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 3 && argv[1][0] == '-' && argv[1][1] == 'd') {
|
||||
dict_file = fopen(argv[2], "r");
|
||||
if (dict_file == NULL) {
|
||||
printf("File \"%s\" open error!\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
if (argc > 3 && argv[1][0] == '-' && argv[1][1] == 'd') {
|
||||
dict_file = fopen(argv[2], "r");
|
||||
if (dict_file == NULL) {
|
||||
printf("File \"%s\" open error!\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(dict_file, 0, SEEK_END);
|
||||
dict_file_length = ftell(dict_file);
|
||||
fseek(dict_file, 0, SEEK_SET);
|
||||
dict_file_length -= ftell(dict_file);
|
||||
dict_stream = malloc(dict_file_length);
|
||||
if (dict_stream == NULL) {
|
||||
printf("Failed to allocate memory to read in dictionary file\n");
|
||||
fclose(dict_file);
|
||||
return 1;
|
||||
}
|
||||
if (fread(dict_stream, 1, dict_file_length, dict_file) != dict_file_length) {
|
||||
printf("Error occurred when reading dictionary file");
|
||||
fclose(dict_file);
|
||||
free(dict_stream);
|
||||
return 1;
|
||||
}
|
||||
isal_update_histogram(dict_stream, dict_file_length, &histogram);
|
||||
fseek(dict_file, 0, SEEK_END);
|
||||
dict_file_length = ftell(dict_file);
|
||||
fseek(dict_file, 0, SEEK_SET);
|
||||
dict_file_length -= ftell(dict_file);
|
||||
dict_stream = malloc(dict_file_length);
|
||||
if (dict_stream == NULL) {
|
||||
printf("Failed to allocate memory to read in dictionary file\n");
|
||||
fclose(dict_file);
|
||||
return 1;
|
||||
}
|
||||
if (fread(dict_stream, 1, dict_file_length, dict_file) != dict_file_length) {
|
||||
printf("Error occurred when reading dictionary file");
|
||||
fclose(dict_file);
|
||||
free(dict_stream);
|
||||
return 1;
|
||||
}
|
||||
isal_update_histogram(dict_stream, dict_file_length, &histogram);
|
||||
|
||||
printf("Read %ld bytes of dictionary file %s\n", dict_file_length, argv[2]);
|
||||
argi += 2;
|
||||
fclose(dict_file);
|
||||
free(dict_stream);
|
||||
}
|
||||
printf("Read %ld bytes of dictionary file %s\n", dict_file_length, argv[2]);
|
||||
argi += 2;
|
||||
fclose(dict_file);
|
||||
free(dict_stream);
|
||||
}
|
||||
|
||||
if ((argc > argi + 1) && argv[argi][0] == '-' && argv[argi][1] == 'h') {
|
||||
hist_file = fopen(argv[argi + 1], "r+");
|
||||
if (hist_file == NULL) {
|
||||
printf("File \"%s\" open error!\n", argv[argi + 1]);
|
||||
return 1;
|
||||
}
|
||||
fseek(hist_file, 0, SEEK_END);
|
||||
hist_file_length = ftell(hist_file);
|
||||
fseek(hist_file, 0, SEEK_SET);
|
||||
hist_file_length -= ftell(hist_file);
|
||||
if (hist_file_length > sizeof(histogram)) {
|
||||
printf("Histogram file too long\n");
|
||||
return 1;
|
||||
}
|
||||
if (fread(&histogram, 1, hist_file_length, hist_file) != hist_file_length) {
|
||||
printf("Error occurred when reading history file");
|
||||
fclose(hist_file);
|
||||
return 1;
|
||||
}
|
||||
fseek(hist_file, 0, SEEK_SET);
|
||||
if ((argc > argi + 1) && argv[argi][0] == '-' && argv[argi][1] == 'h') {
|
||||
hist_file = fopen(argv[argi + 1], "r+");
|
||||
if (hist_file == NULL) {
|
||||
printf("File \"%s\" open error!\n", argv[argi + 1]);
|
||||
return 1;
|
||||
}
|
||||
fseek(hist_file, 0, SEEK_END);
|
||||
hist_file_length = ftell(hist_file);
|
||||
fseek(hist_file, 0, SEEK_SET);
|
||||
hist_file_length -= ftell(hist_file);
|
||||
if (hist_file_length > sizeof(histogram)) {
|
||||
printf("Histogram file too long\n");
|
||||
return 1;
|
||||
}
|
||||
if (fread(&histogram, 1, hist_file_length, hist_file) != hist_file_length) {
|
||||
printf("Error occurred when reading history file");
|
||||
fclose(hist_file);
|
||||
return 1;
|
||||
}
|
||||
fseek(hist_file, 0, SEEK_SET);
|
||||
|
||||
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. */
|
||||
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. */
|
||||
|
||||
while (argi < argc) {
|
||||
printf("Processing %s\n", argv[argi]);
|
||||
file = fopen(argv[argi], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening file\n");
|
||||
return 1;
|
||||
}
|
||||
fseek(file, 0, SEEK_END);
|
||||
file_length = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
file_length -= ftell(file);
|
||||
stream = malloc(file_length + dict_file_length);
|
||||
if (stream == NULL) {
|
||||
printf("Failed to allocate memory to read in file\n");
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
if (dict_file_length > 0)
|
||||
memcpy(stream, dict_stream, dict_file_length);
|
||||
while (argi < argc) {
|
||||
printf("Processing %s\n", argv[argi]);
|
||||
file = fopen(argv[argi], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening file\n");
|
||||
return 1;
|
||||
}
|
||||
fseek(file, 0, SEEK_END);
|
||||
file_length = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
file_length -= ftell(file);
|
||||
stream = malloc(file_length + dict_file_length);
|
||||
if (stream == NULL) {
|
||||
printf("Failed to allocate memory to read in file\n");
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
if (dict_file_length > 0)
|
||||
memcpy(stream, dict_stream, dict_file_length);
|
||||
|
||||
if (fread(&stream[dict_file_length], 1, file_length, file) != file_length) {
|
||||
printf("Error occurred when reading file");
|
||||
fclose(file);
|
||||
free(stream);
|
||||
return 1;
|
||||
}
|
||||
if (fread(&stream[dict_file_length], 1, file_length, file) != file_length) {
|
||||
printf("Error occurred when reading file");
|
||||
fclose(file);
|
||||
free(stream);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create a histogram of frequency of symbols found in stream to
|
||||
* generate the huffman tree.*/
|
||||
if (0 == dict_file_length)
|
||||
isal_update_histogram(stream, file_length, &histogram);
|
||||
else
|
||||
isal_update_histogram_dict(stream, dict_file_length, file_length,
|
||||
&histogram);
|
||||
/* Create a histogram of frequency of symbols found in stream to
|
||||
* generate the huffman tree.*/
|
||||
if (0 == dict_file_length)
|
||||
isal_update_histogram(stream, file_length, &histogram);
|
||||
else
|
||||
isal_update_histogram_dict(stream, dict_file_length, file_length,
|
||||
&histogram);
|
||||
|
||||
fclose(file);
|
||||
free(stream);
|
||||
argi++;
|
||||
}
|
||||
fclose(file);
|
||||
free(stream);
|
||||
argi++;
|
||||
}
|
||||
|
||||
isal_create_hufftables(&hufftables, &histogram);
|
||||
isal_create_hufftables(&hufftables, &histogram);
|
||||
|
||||
file = fopen("hufftables_c.c", "w");
|
||||
if (file == NULL) {
|
||||
printf("Error creating file hufftables_c.c\n");
|
||||
return 1;
|
||||
}
|
||||
file = fopen("hufftables_c.c", "w");
|
||||
if (file == NULL) {
|
||||
printf("Error creating file hufftables_c.c\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprint_header(file);
|
||||
fprint_header(file);
|
||||
|
||||
fprintf(file, "\n");
|
||||
fprintf(file, "\n");
|
||||
|
||||
fprint_hufftables(file, "hufftables_default", &hufftables);
|
||||
fprint_hufftables(file, "hufftables_default", &hufftables);
|
||||
|
||||
fprintf(file, "\n");
|
||||
fprintf(file, "\n");
|
||||
|
||||
isal_deflate_stateless_init(&tmp_stream);
|
||||
isal_deflate_set_hufftables(&tmp_stream, NULL, IGZIP_HUFFTABLE_STATIC);
|
||||
fprint_hufftables(file, "hufftables_static", tmp_stream.hufftables);
|
||||
isal_deflate_stateless_init(&tmp_stream);
|
||||
isal_deflate_set_hufftables(&tmp_stream, NULL, IGZIP_HUFFTABLE_STATIC);
|
||||
fprint_hufftables(file, "hufftables_static", tmp_stream.hufftables);
|
||||
|
||||
fclose(file);
|
||||
fclose(file);
|
||||
|
||||
if (hist_file) {
|
||||
int len = fwrite(&histogram, 1, sizeof(histogram), hist_file);
|
||||
printf("wrote %d bytes of histogram file\n", len);
|
||||
fclose(hist_file);
|
||||
}
|
||||
return 0;
|
||||
if (hist_file) {
|
||||
int len = fwrite(&histogram, 1, sizeof(histogram), hist_file);
|
||||
printf("wrote %d bytes of histogram file\n", len);
|
||||
fclose(hist_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "igzip_lib.h"
|
||||
|
||||
#define STATIC_INFLATE_FILE "static_inflate.h"
|
||||
#define DOUBLE_SYM_THRESH (4 * 1024)
|
||||
#define DOUBLE_SYM_THRESH (4 * 1024)
|
||||
|
||||
extern struct isal_hufftables hufftables_default;
|
||||
|
||||
@ -48,26 +48,26 @@ 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);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
int i;
|
||||
fprintf(outfile, "%s", header);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 7) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%04x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,127 +79,130 @@ 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);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%08x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%08x", table[i]);
|
||||
fprintf(outfile, "%s", footer);
|
||||
int i;
|
||||
fprintf(outfile, "%s", header);
|
||||
for (i = 0; i < length - 1; i++) {
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "\n%s", begin_line);
|
||||
else
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "0x%08x,", table[i]);
|
||||
}
|
||||
|
||||
if ((i & 3) == 0)
|
||||
fprintf(outfile, "%s", begin_line);
|
||||
else
|
||||
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"
|
||||
"# define ISAL_STATIC_INFLATE_TABLE\n"
|
||||
"#else\n"
|
||||
"# warning \"Incompatible compile time defines for optimized static inflate table.\"\n"
|
||||
"#endif\n\n");
|
||||
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"
|
||||
"# define ISAL_STATIC_INFLATE_TABLE\n"
|
||||
"#else\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;
|
||||
uint8_t static_deflate_hdr = 3;
|
||||
uint8_t tmp_space[8], *in_buf;
|
||||
struct inflate_state state;
|
||||
FILE *file;
|
||||
uint8_t static_deflate_hdr = 3;
|
||||
uint8_t tmp_space[8], *in_buf;
|
||||
|
||||
if (NULL == (in_buf = malloc(DOUBLE_SYM_THRESH + 1))) {
|
||||
printf("Can not allocote memory\n");
|
||||
return 1;
|
||||
}
|
||||
if (NULL == (in_buf = malloc(DOUBLE_SYM_THRESH + 1))) {
|
||||
printf("Can not allocote memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
isal_inflate_init(&state);
|
||||
isal_inflate_init(&state);
|
||||
|
||||
memcpy(in_buf, &static_deflate_hdr, sizeof(static_deflate_hdr));
|
||||
state.next_in = in_buf;
|
||||
state.avail_in = DOUBLE_SYM_THRESH + 1;
|
||||
state.next_out = tmp_space;
|
||||
state.avail_out = sizeof(tmp_space);
|
||||
memcpy(in_buf, &static_deflate_hdr, sizeof(static_deflate_hdr));
|
||||
state.next_in = in_buf;
|
||||
state.avail_in = DOUBLE_SYM_THRESH + 1;
|
||||
state.next_out = tmp_space;
|
||||
state.avail_out = sizeof(tmp_space);
|
||||
|
||||
isal_inflate(&state);
|
||||
isal_inflate(&state);
|
||||
|
||||
file = fopen(STATIC_INFLATE_FILE, "w");
|
||||
file = fopen(STATIC_INFLATE_FILE, "w");
|
||||
|
||||
if (file == NULL) {
|
||||
printf("Error creating file hufftables_c.c\n");
|
||||
return 1;
|
||||
}
|
||||
// Add decode tables describing a type 2 static (fixed) header
|
||||
if (file == NULL) {
|
||||
printf("Error creating file hufftables_c.c\n");
|
||||
return 1;
|
||||
}
|
||||
// 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);
|
||||
fprint_header(file);
|
||||
|
||||
fprintf(file, "struct inflate_huff_code_large static_lit_huff_code = {\n");
|
||||
fprint_uint32_table(file, state.lit_huff_code.short_code_lookup,
|
||||
sizeof(state.lit_huff_code.short_code_lookup) / sizeof(uint32_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.lit_huff_code.long_code_lookup,
|
||||
sizeof(state.lit_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
fprintf(file, "struct inflate_huff_code_large static_lit_huff_code = {\n");
|
||||
fprint_uint32_table(file, state.lit_huff_code.short_code_lookup,
|
||||
sizeof(state.lit_huff_code.short_code_lookup) / sizeof(uint32_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.lit_huff_code.long_code_lookup,
|
||||
sizeof(state.lit_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
|
||||
fprintf(file, "struct inflate_huff_code_small static_dist_huff_code = {\n");
|
||||
fprint_uint16_table(file, state.dist_huff_code.short_code_lookup,
|
||||
sizeof(state.dist_huff_code.short_code_lookup) / sizeof(uint16_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.dist_huff_code.long_code_lookup,
|
||||
sizeof(state.dist_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
fprintf(file, "struct inflate_huff_code_small static_dist_huff_code = {\n");
|
||||
fprint_uint16_table(file, state.dist_huff_code.short_code_lookup,
|
||||
sizeof(state.dist_huff_code.short_code_lookup) / sizeof(uint16_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.dist_huff_code.long_code_lookup,
|
||||
sizeof(state.dist_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
|
||||
fprintf(file, "#endif\n");
|
||||
fprintf(file, "#endif\n");
|
||||
|
||||
// Add other tables for known dynamic headers - level 0
|
||||
// Add other tables for known dynamic headers - level 0
|
||||
|
||||
isal_inflate_init(&state);
|
||||
isal_inflate_init(&state);
|
||||
|
||||
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;
|
||||
state.avail_out = sizeof(tmp_space);
|
||||
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;
|
||||
state.avail_out = sizeof(tmp_space);
|
||||
|
||||
isal_inflate(&state);
|
||||
isal_inflate(&state);
|
||||
|
||||
fprintf(file, "struct inflate_huff_code_large pregen_lit_huff_code = {\n");
|
||||
fprint_uint32_table(file, state.lit_huff_code.short_code_lookup,
|
||||
sizeof(state.lit_huff_code.short_code_lookup) / sizeof(uint32_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.lit_huff_code.long_code_lookup,
|
||||
sizeof(state.lit_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
fprintf(file, "struct inflate_huff_code_large pregen_lit_huff_code = {\n");
|
||||
fprint_uint32_table(file, state.lit_huff_code.short_code_lookup,
|
||||
sizeof(state.lit_huff_code.short_code_lookup) / sizeof(uint32_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.lit_huff_code.long_code_lookup,
|
||||
sizeof(state.lit_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
|
||||
fprintf(file, "struct inflate_huff_code_small pregen_dist_huff_code = {\n");
|
||||
fprint_uint16_table(file, state.dist_huff_code.short_code_lookup,
|
||||
sizeof(state.dist_huff_code.short_code_lookup) / sizeof(uint16_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.dist_huff_code.long_code_lookup,
|
||||
sizeof(state.dist_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
fprintf(file, "struct inflate_huff_code_small pregen_dist_huff_code = {\n");
|
||||
fprint_uint16_table(file, state.dist_huff_code.short_code_lookup,
|
||||
sizeof(state.dist_huff_code.short_code_lookup) / sizeof(uint16_t),
|
||||
"\t.short_code_lookup = {", "\t},\n\n", "\t\t");
|
||||
fprint_uint16_table(file, state.dist_huff_code.long_code_lookup,
|
||||
sizeof(state.dist_huff_code.long_code_lookup) / sizeof(uint16_t),
|
||||
"\t.long_code_lookup = {", "\t}\n", "\t\t");
|
||||
fprintf(file, "};\n\n");
|
||||
|
||||
fclose(file);
|
||||
free(in_buf);
|
||||
return 0;
|
||||
fclose(file);
|
||||
free(in_buf);
|
||||
return 0;
|
||||
}
|
||||
|
2678
igzip/huff_codes.c
2678
igzip/huff_codes.c
File diff suppressed because it is too large
Load Diff
@ -36,135 +36,135 @@
|
||||
#include "igzip_lib.h"
|
||||
#include "bitbuf2.h"
|
||||
|
||||
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
|
||||
# include <immintrin.h>
|
||||
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
|
||||
#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
|
||||
|
||||
#define LIT_LEN ISAL_DEF_LIT_LEN_SYMBOLS
|
||||
#define DIST_LEN ISAL_DEF_DIST_SYMBOLS
|
||||
#define LIT_LEN ISAL_DEF_LIT_LEN_SYMBOLS
|
||||
#define DIST_LEN ISAL_DEF_DIST_SYMBOLS
|
||||
#define CODE_LEN_CODES 19
|
||||
#define HUFF_LEN 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
|
||||
#define DYN_HDR_START_LEN 17
|
||||
#define MAX_HISTHEAP_SIZE LIT_LEN
|
||||
#define MAX_HUFF_TREE_DEPTH 15
|
||||
#define D IGZIP_HIST_SIZE /* Amount of history */
|
||||
#define D IGZIP_HIST_SIZE /* Amount of history */
|
||||
|
||||
#define MAX_DEFLATE_CODE_LEN 15
|
||||
#define MAX_SAFE_LIT_CODE_LEN 13
|
||||
#define MAX_DEFLATE_CODE_LEN 15
|
||||
#define MAX_SAFE_LIT_CODE_LEN 13
|
||||
#define MAX_SAFE_DIST_CODE_LEN 12
|
||||
|
||||
#define LONG_DIST_TABLE_SIZE 8192
|
||||
#define LONG_DIST_TABLE_SIZE 8192
|
||||
#define SHORT_DIST_TABLE_SIZE 2
|
||||
#define LEN_TABLE_SIZE 256
|
||||
#define LIT_TABLE_SIZE 257
|
||||
#define LAST_BLOCK 1
|
||||
#define LEN_TABLE_SIZE 256
|
||||
#define LIT_TABLE_SIZE 257
|
||||
#define LAST_BLOCK 1
|
||||
|
||||
#define LEN_EXTRA_BITS_START 264
|
||||
#define LEN_EXTRA_BITS_INTERVAL 4
|
||||
#define DIST_EXTRA_BITS_START 3
|
||||
#define LEN_EXTRA_BITS_START 264
|
||||
#define LEN_EXTRA_BITS_INTERVAL 4
|
||||
#define DIST_EXTRA_BITS_START 3
|
||||
#define DIST_EXTRA_BITS_INTERVAL 2
|
||||
|
||||
#define INVALID_LIT_LEN_HUFFCODE 1
|
||||
#define INVALID_DIST_HUFFCODE 1
|
||||
#define INVALID_HUFFCODE 1
|
||||
#define INVALID_DIST_HUFFCODE 1
|
||||
#define INVALID_HUFFCODE 1
|
||||
|
||||
#define HASH8K_HASH_MASK (IGZIP_HASH8K_HASH_SIZE - 1)
|
||||
#define HASH_HIST_HASH_MASK (IGZIP_HASH_HIST_SIZE - 1)
|
||||
#define HASH8K_HASH_MASK (IGZIP_HASH8K_HASH_SIZE - 1)
|
||||
#define HASH_HIST_HASH_MASK (IGZIP_HASH_HIST_SIZE - 1)
|
||||
#define HASH_MAP_HASH_MASK (IGZIP_HASH_MAP_HASH_SIZE - 1)
|
||||
|
||||
#define LVL0_HASH_MASK (IGZIP_LVL0_HASH_SIZE - 1)
|
||||
#define LVL1_HASH_MASK (IGZIP_LVL1_HASH_SIZE - 1)
|
||||
#define LVL2_HASH_MASK (IGZIP_LVL2_HASH_SIZE - 1)
|
||||
#define LVL3_HASH_MASK (IGZIP_LVL3_HASH_SIZE - 1)
|
||||
#define SHORTEST_MATCH 4
|
||||
#define LVL0_HASH_MASK (IGZIP_LVL0_HASH_SIZE - 1)
|
||||
#define LVL1_HASH_MASK (IGZIP_LVL1_HASH_SIZE - 1)
|
||||
#define LVL2_HASH_MASK (IGZIP_LVL2_HASH_SIZE - 1)
|
||||
#define LVL3_HASH_MASK (IGZIP_LVL3_HASH_SIZE - 1)
|
||||
#define SHORTEST_MATCH 4
|
||||
|
||||
#define LENGTH_BITS 5
|
||||
#define FREQ_SHIFT 16
|
||||
#define FREQ_MASK_HI (0xFFFFFFFFFFFF0000)
|
||||
#define DEPTH_SHIFT 24
|
||||
#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 MAX_BL_CODE_LEN 7
|
||||
#define LENGTH_BITS 5
|
||||
#define FREQ_SHIFT 16
|
||||
#define FREQ_MASK_HI (0xFFFFFFFFFFFF0000)
|
||||
#define DEPTH_SHIFT 24
|
||||
#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 MAX_BL_CODE_LEN 7
|
||||
|
||||
/**
|
||||
* @brief Structure used to store huffman codes
|
||||
*/
|
||||
struct huff_code {
|
||||
union {
|
||||
struct {
|
||||
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
|
||||
};
|
||||
};
|
||||
|
||||
struct {
|
||||
struct {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
uint16_t code;
|
||||
uint8_t extra_bit_count;
|
||||
uint8_t length;
|
||||
uint16_t code;
|
||||
uint8_t extra_bit_count;
|
||||
uint8_t length;
|
||||
#else
|
||||
uint8_t length;
|
||||
uint8_t extra_bit_count;
|
||||
uint16_t code;
|
||||
uint8_t length;
|
||||
uint8_t extra_bit_count;
|
||||
uint16_t code;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t code_and_length;
|
||||
};
|
||||
uint32_t code_and_length;
|
||||
};
|
||||
};
|
||||
|
||||
struct tree_node {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
uint32_t child;
|
||||
uint32_t depth;
|
||||
uint32_t child;
|
||||
uint32_t depth;
|
||||
#else
|
||||
uint32_t depth;
|
||||
uint32_t child;
|
||||
uint32_t depth;
|
||||
uint32_t child;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct heap_tree {
|
||||
union {
|
||||
uint64_t heap[HEAP_TREE_SIZE];
|
||||
uint64_t code_len_count[MAX_HUFF_TREE_DEPTH + 1];
|
||||
struct tree_node tree[HEAP_TREE_SIZE];
|
||||
};
|
||||
union {
|
||||
uint64_t heap[HEAP_TREE_SIZE];
|
||||
uint64_t code_len_count[MAX_HUFF_TREE_DEPTH + 1];
|
||||
struct tree_node tree[HEAP_TREE_SIZE];
|
||||
};
|
||||
};
|
||||
|
||||
struct rl_code {
|
||||
uint8_t code;
|
||||
uint8_t extra_bits;
|
||||
uint8_t code;
|
||||
uint8_t extra_bits;
|
||||
};
|
||||
|
||||
struct hufftables_icf {
|
||||
union {
|
||||
struct {
|
||||
struct huff_code dist_lit_table[288];
|
||||
struct huff_code len_table[256];
|
||||
};
|
||||
union {
|
||||
struct {
|
||||
struct huff_code dist_lit_table[288];
|
||||
struct huff_code len_table[256];
|
||||
};
|
||||
|
||||
struct {
|
||||
struct huff_code dist_table[31];
|
||||
struct huff_code lit_len_table[513];
|
||||
};
|
||||
};
|
||||
struct {
|
||||
struct huff_code dist_table[31];
|
||||
struct huff_code lit_len_table[513];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
@ -181,6 +181,6 @@ struct hufftables_icf {
|
||||
*/
|
||||
uint64_t
|
||||
create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables,
|
||||
struct isal_mod_hist *hist, uint32_t end_of_block);
|
||||
struct isal_mod_hist *hist, uint32_t end_of_block);
|
||||
|
||||
#endif
|
||||
|
438
igzip/huffman.h
438
igzip/huffman.h
@ -33,15 +33,15 @@
|
||||
#include "igzip_lib.h"
|
||||
#include "unaligned.h"
|
||||
|
||||
#if __x86_64__ || __i386__ || _M_X64 || _M_IX86
|
||||
#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,195 +50,205 @@
|
||||
*
|
||||
* @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;
|
||||
uint32_t msb;
|
||||
#if defined(_MSC_VER)
|
||||
unsigned long ret = 0;
|
||||
if (val != 0) {
|
||||
_BitScanReverse(&ret, val);
|
||||
msb = ret + 1;
|
||||
} else
|
||||
msb = 0;
|
||||
#elif defined( __LZCNT__)
|
||||
msb = 32 - __lzcnt32(val);
|
||||
unsigned long ret = 0;
|
||||
if (val != 0) {
|
||||
_BitScanReverse(&ret, val);
|
||||
msb = ret + 1;
|
||||
} else
|
||||
msb = 0;
|
||||
#elif defined(__LZCNT__)
|
||||
msb = 32 - __lzcnt32(val);
|
||||
#elif defined(__x86_64__) || defined(__aarch64__)
|
||||
msb = (val == 0) ? 0 : 32 - __builtin_clz(val);
|
||||
msb = (val == 0) ? 0 : 32 - __builtin_clz(val);
|
||||
#else
|
||||
for (msb = 0; val > 0; val >>= 1)
|
||||
msb++;
|
||||
for (msb = 0; val > 0; val >>= 1)
|
||||
msb++;
|
||||
#endif
|
||||
return msb;
|
||||
return msb;
|
||||
}
|
||||
|
||||
static inline uint32_t tzbytecnt(uint64_t val)
|
||||
static inline uint32_t
|
||||
tzbytecnt(uint64_t val)
|
||||
{
|
||||
uint32_t cnt;
|
||||
uint32_t cnt;
|
||||
|
||||
#ifdef __BMI__
|
||||
cnt = __tzcnt_u64(val);
|
||||
cnt = cnt / 8;
|
||||
cnt = __tzcnt_u64(val);
|
||||
cnt = cnt / 8;
|
||||
#elif defined(__x86_64__) || defined(__aarch64__)
|
||||
|
||||
cnt = (val == 0) ? 64 : __builtin_ctzll(val);
|
||||
cnt = cnt / 8;
|
||||
cnt = (val == 0) ? 64 : __builtin_ctzll(val);
|
||||
cnt = cnt / 8;
|
||||
|
||||
#else
|
||||
for (cnt = 8; val > 0; val <<= 8)
|
||||
cnt -= 1;
|
||||
for (cnt = 8; val > 0; val <<= 8)
|
||||
cnt -= 1;
|
||||
#endif
|
||||
return cnt;
|
||||
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);
|
||||
assert(dist > IGZIP_DIST_TABLE_SIZE);
|
||||
|
||||
dist -= 1;
|
||||
uint32_t msb;
|
||||
uint32_t num_extra_bits;
|
||||
uint32_t extra_bits;
|
||||
uint32_t sym;
|
||||
uint32_t len;
|
||||
uint32_t code;
|
||||
dist -= 1;
|
||||
uint32_t msb;
|
||||
uint32_t num_extra_bits;
|
||||
uint32_t extra_bits;
|
||||
uint32_t sym;
|
||||
uint32_t len;
|
||||
uint32_t code;
|
||||
|
||||
msb = bsr(dist);
|
||||
assert(msb >= 2);
|
||||
num_extra_bits = msb - 2;
|
||||
extra_bits = dist & ((1 << num_extra_bits) - 1);
|
||||
dist >>= num_extra_bits;
|
||||
sym = dist + 2 * num_extra_bits;
|
||||
assert(sym < 30);
|
||||
code = hufftables->dcodes[sym - IGZIP_DECODE_OFFSET];
|
||||
len = hufftables->dcodes_sizes[sym - IGZIP_DECODE_OFFSET];
|
||||
*p_code = code | (extra_bits << len);
|
||||
*p_len = len + num_extra_bits;
|
||||
msb = bsr(dist);
|
||||
assert(msb >= 2);
|
||||
num_extra_bits = msb - 2;
|
||||
extra_bits = dist & ((1 << num_extra_bits) - 1);
|
||||
dist >>= num_extra_bits;
|
||||
sym = dist + 2 * num_extra_bits;
|
||||
assert(sym < 30);
|
||||
code = hufftables->dcodes[sym - IGZIP_DECODE_OFFSET];
|
||||
len = hufftables->dcodes_sizes[sym - IGZIP_DECODE_OFFSET];
|
||||
*p_code = code | (extra_bits << len);
|
||||
*p_len = len + num_extra_bits;
|
||||
}
|
||||
|
||||
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);
|
||||
if (dist <= IGZIP_DIST_TABLE_SIZE) {
|
||||
uint64_t code_len;
|
||||
code_len = hufftables->dist_table[dist - 1];
|
||||
*code = code_len >> 5;
|
||||
*len = code_len & 0x1F;
|
||||
} else {
|
||||
compute_dist_code(hufftables, dist, code, len);
|
||||
}
|
||||
assert(dist >= 1);
|
||||
assert(dist <= 32768);
|
||||
if (dist <= IGZIP_DIST_TABLE_SIZE) {
|
||||
uint64_t code_len;
|
||||
code_len = hufftables->dist_table[dist - 1];
|
||||
*code = code_len >> 5;
|
||||
*len = code_len & 0x1F;
|
||||
} else {
|
||||
compute_dist_code(hufftables, dist, code, len);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
assert(length >= 3);
|
||||
assert(length <= 258);
|
||||
|
||||
uint64_t code_len;
|
||||
code_len = hufftables->len_table[length - 3];
|
||||
*code = code_len >> 5;
|
||||
*len = code_len & 0x1F;
|
||||
uint64_t code_len;
|
||||
code_len = hufftables->len_table[length - 3];
|
||||
*code = code_len >> 5;
|
||||
*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);
|
||||
assert(lit <= 256);
|
||||
|
||||
*code = hufftables->lit_table[lit];
|
||||
*len = hufftables->lit_table_sizes[lit];
|
||||
*code = hufftables->lit_table[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;
|
||||
uint32_t msb;
|
||||
uint32_t num_extra_bits;
|
||||
|
||||
dist -= 1;
|
||||
msb = bsr(dist);
|
||||
assert(msb >= 2);
|
||||
num_extra_bits = msb - 2;
|
||||
*extra_bits = dist & ((1 << num_extra_bits) - 1);
|
||||
dist >>= num_extra_bits;
|
||||
*code = dist + 2 * num_extra_bits;
|
||||
assert(*code < 30);
|
||||
dist -= 1;
|
||||
msb = bsr(dist);
|
||||
assert(msb >= 2);
|
||||
num_extra_bits = msb - 2;
|
||||
*extra_bits = dist & ((1 << num_extra_bits) - 1);
|
||||
dist >>= num_extra_bits;
|
||||
*code = dist + 2 * num_extra_bits;
|
||||
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);
|
||||
if (dist <= 2) {
|
||||
*code = dist - 1;
|
||||
*extra_bits = 0;
|
||||
} else {
|
||||
compute_dist_icf_code(dist, code, extra_bits);
|
||||
}
|
||||
assert(dist >= 1);
|
||||
assert(dist <= 32768);
|
||||
if (dist <= 2) {
|
||||
*code = dist - 1;
|
||||
*extra_bits = 0;
|
||||
} else {
|
||||
compute_dist_icf_code(dist, code, extra_bits);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
assert(length >= 3);
|
||||
assert(length <= 258);
|
||||
|
||||
*code = length + 254;
|
||||
*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);
|
||||
assert(lit <= 256);
|
||||
|
||||
*code = lit;
|
||||
*code = lit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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__
|
||||
|
||||
return _mm_crc32_u32(0, data);
|
||||
return _mm_crc32_u32(0, data);
|
||||
|
||||
#else
|
||||
uint64_t hash;
|
||||
/* Use multiplication to create a hash, 0xBDD06057 is a prime number */
|
||||
hash = data;
|
||||
hash *= 0xB2D06057;
|
||||
hash >>= 16;
|
||||
hash *= 0xB2D06057;
|
||||
hash >>= 16;
|
||||
uint64_t hash;
|
||||
/* Use multiplication to create a hash, 0xBDD06057 is a prime number */
|
||||
hash = data;
|
||||
hash *= 0xB2D06057;
|
||||
hash >>= 16;
|
||||
hash *= 0xB2D06057;
|
||||
hash >>= 16;
|
||||
|
||||
return hash;
|
||||
return hash;
|
||||
|
||||
#endif /* __SSE4_2__ */
|
||||
}
|
||||
|
||||
#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;
|
||||
int16_t data_low;
|
||||
int16_t data_high;
|
||||
|
||||
data_low = data;
|
||||
data_high = data >> 16;
|
||||
data = PROD1 * data_low + PROD2 * data_high;
|
||||
data_low = data;
|
||||
data_high = data >> 16;
|
||||
data = PROD1 * data_low + PROD2 * data_high;
|
||||
|
||||
data_low = data;
|
||||
data_high = data >> 16;
|
||||
data = PROD1 * data_low + PROD2 * data_high;
|
||||
data_low = data;
|
||||
data_high = data >> 16;
|
||||
data = PROD1 * data_low + PROD2 * data_high;
|
||||
|
||||
return 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);
|
||||
return compute_hash(data >> 32) ^ compute_hash(data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,59 +257,60 @@ 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;
|
||||
uint64_t loop_length;
|
||||
uint32_t count;
|
||||
uint64_t test;
|
||||
uint64_t loop_length;
|
||||
|
||||
if (max_length > 258)
|
||||
max_length = 258;
|
||||
if (max_length > 258)
|
||||
max_length = 258;
|
||||
|
||||
loop_length = max_length & ~0x7;
|
||||
loop_length = max_length & ~0x7;
|
||||
|
||||
for (count = 0; count < loop_length; count += 8) {
|
||||
test = load_le_u64(str1);
|
||||
test ^= load_le_u64(str2);
|
||||
if (test != 0)
|
||||
return count + tzbytecnt(test);
|
||||
str1 += 8;
|
||||
str2 += 8;
|
||||
}
|
||||
for (count = 0; count < loop_length; count += 8) {
|
||||
test = load_le_u64(str1);
|
||||
test ^= load_le_u64(str2);
|
||||
if (test != 0)
|
||||
return count + tzbytecnt(test);
|
||||
str1 += 8;
|
||||
str2 += 8;
|
||||
}
|
||||
|
||||
switch (max_length % 8) {
|
||||
switch (max_length % 8) {
|
||||
|
||||
case 7:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 6:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 5:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 4:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 3:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 2:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 1:
|
||||
if (*str1 != *str2)
|
||||
return count;
|
||||
count++;
|
||||
}
|
||||
case 7:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 6:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 5:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 4:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 3:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 2:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 1:
|
||||
if (*str1 != *str2)
|
||||
return count;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -308,54 +319,55 @@ 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;
|
||||
uint64_t loop_length;
|
||||
uint32_t count;
|
||||
uint64_t test;
|
||||
uint64_t loop_length;
|
||||
|
||||
loop_length = max_length & ~0x7;
|
||||
loop_length = max_length & ~0x7;
|
||||
|
||||
for (count = 0; count < loop_length; count += 8) {
|
||||
test = load_le_u64(str1);
|
||||
test ^= load_le_u64(str2);
|
||||
if (test != 0)
|
||||
return count + tzbytecnt(test);
|
||||
str1 += 8;
|
||||
str2 += 8;
|
||||
}
|
||||
for (count = 0; count < loop_length; count += 8) {
|
||||
test = load_le_u64(str1);
|
||||
test ^= load_le_u64(str2);
|
||||
if (test != 0)
|
||||
return count + tzbytecnt(test);
|
||||
str1 += 8;
|
||||
str2 += 8;
|
||||
}
|
||||
|
||||
switch (max_length % 8) {
|
||||
switch (max_length % 8) {
|
||||
|
||||
case 7:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 6:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 5:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 4:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 3:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 2:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 1:
|
||||
if (*str1 != *str2)
|
||||
return count;
|
||||
count++;
|
||||
}
|
||||
case 7:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 6:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 5:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 4:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 3:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 2:
|
||||
if (*str1++ != *str2++)
|
||||
return count;
|
||||
count++;
|
||||
case 1:
|
||||
if (*str1 != *str2)
|
||||
return count;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
11946
igzip/hufftables_c.c
11946
igzip/hufftables_c.c
File diff suppressed because it is too large
Load Diff
3047
igzip/igzip.c
3047
igzip/igzip.c
File diff suppressed because it is too large
Load Diff
@ -6,231 +6,229 @@
|
||||
|
||||
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;
|
||||
struct isal_zstate *state = &stream->internal_state;
|
||||
uint32_t bytes_written;
|
||||
|
||||
if (next_in - start_in > 0)
|
||||
state->has_hist = IGZIP_HIST;
|
||||
if (next_in - start_in > 0)
|
||||
state->has_hist = IGZIP_HIST;
|
||||
|
||||
stream->next_in = next_in;
|
||||
stream->total_in += next_in - start_in;
|
||||
stream->avail_in = end_in - next_in;
|
||||
|
||||
bytes_written = buffer_used(&state->bitbuf);
|
||||
stream->total_out += bytes_written;
|
||||
stream->next_out += bytes_written;
|
||||
stream->avail_out -= bytes_written;
|
||||
stream->next_in = next_in;
|
||||
stream->total_in += next_in - start_in;
|
||||
stream->avail_in = end_in - next_in;
|
||||
|
||||
bytes_written = buffer_used(&state->bitbuf);
|
||||
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;
|
||||
uint16_t match_length;
|
||||
uint32_t dist;
|
||||
uint64_t code, code_len, code2, code_len2;
|
||||
struct isal_zstate *state = &stream->internal_state;
|
||||
uint16_t *last_seen = state->head;
|
||||
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
|
||||
uint32_t hist_size = state->dist_mask;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
uint32_t literal, hash;
|
||||
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
|
||||
uint16_t match_length;
|
||||
uint32_t dist;
|
||||
uint64_t code, code_len, code2, code_len2;
|
||||
struct isal_zstate *state = &stream->internal_state;
|
||||
uint16_t *last_seen = state->head;
|
||||
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
|
||||
uint32_t hist_size = state->dist_mask;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
return;
|
||||
}
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
return;
|
||||
}
|
||||
|
||||
set_buf(&state->bitbuf, stream->next_out, stream->avail_out);
|
||||
set_buf(&state->bitbuf, stream->next_out, stream->avail_out);
|
||||
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
|
||||
while (next_in + ISAL_LOOK_AHEAD < end_in) {
|
||||
while (next_in + ISAL_LOOK_AHEAD < end_in) {
|
||||
|
||||
if (is_full(&state->bitbuf)) {
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
return;
|
||||
}
|
||||
if (is_full(&state->bitbuf)) {
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
return;
|
||||
}
|
||||
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
|
||||
/* The -1 are to handle the case when dist = 0 */
|
||||
if (dist - 1 < hist_size) {
|
||||
assert(dist != 0);
|
||||
/* The -1 are to handle the case when dist = 0 */
|
||||
if (dist - 1 < hist_size) {
|
||||
assert(dist != 0);
|
||||
|
||||
match_length = compare258(next_in - dist, next_in, 258);
|
||||
match_length = compare258(next_in - dist, next_in, 258);
|
||||
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
#ifdef ISAL_LIMIT_HASH_UPDATE
|
||||
end = next_hash + 3;
|
||||
end = next_hash + 3;
|
||||
#else
|
||||
end = next_hash + match_length;
|
||||
end = next_hash + match_length;
|
||||
#endif
|
||||
next_hash++;
|
||||
next_hash++;
|
||||
|
||||
for (; next_hash < end; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
for (; next_hash < end; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
|
||||
get_len_code(stream->hufftables, match_length, &code,
|
||||
&code_len);
|
||||
get_dist_code(stream->hufftables, dist, &code2, &code_len2);
|
||||
get_len_code(stream->hufftables, match_length, &code, &code_len);
|
||||
get_dist_code(stream->hufftables, dist, &code2, &code_len2);
|
||||
|
||||
code |= code2 << code_len;
|
||||
code_len += code_len2;
|
||||
code |= code2 << code_len;
|
||||
code_len += code_len2;
|
||||
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
|
||||
next_in += match_length;
|
||||
next_in += match_length;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
next_in++;
|
||||
}
|
||||
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
next_in++;
|
||||
}
|
||||
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
|
||||
assert(stream->avail_in <= ISAL_LOOK_AHEAD);
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
|
||||
return;
|
||||
assert(stream->avail_in <= ISAL_LOOK_AHEAD);
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
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;
|
||||
uint16_t match_length;
|
||||
uint32_t dist;
|
||||
uint64_t code, code_len, code2, code_len2;
|
||||
struct isal_zstate *state = &stream->internal_state;
|
||||
uint16_t *last_seen = state->head;
|
||||
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
|
||||
uint32_t hist_size = state->dist_mask;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
uint32_t literal = 0, hash;
|
||||
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
|
||||
uint16_t match_length;
|
||||
uint32_t dist;
|
||||
uint64_t code, code_len, code2, code_len2;
|
||||
struct isal_zstate *state = &stream->internal_state;
|
||||
uint16_t *last_seen = state->head;
|
||||
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
|
||||
uint32_t hist_size = state->dist_mask;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
|
||||
set_buf(&state->bitbuf, stream->next_out, stream->avail_out);
|
||||
set_buf(&state->bitbuf, stream->next_out, stream->avail_out);
|
||||
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
|
||||
if (stream->avail_in != 0) {
|
||||
while (next_in + 3 < end_in) {
|
||||
if (is_full(&state->bitbuf)) {
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
return;
|
||||
}
|
||||
if (stream->avail_in != 0) {
|
||||
while (next_in + 3 < end_in) {
|
||||
if (is_full(&state->bitbuf)) {
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
return;
|
||||
}
|
||||
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
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 */
|
||||
match_length =
|
||||
compare258(next_in - dist, next_in, end_in - next_in);
|
||||
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);
|
||||
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
#ifdef ISAL_LIMIT_HASH_UPDATE
|
||||
end = next_hash + 3;
|
||||
end = next_hash + 3;
|
||||
#else
|
||||
end = next_hash + match_length;
|
||||
end = next_hash + match_length;
|
||||
#endif
|
||||
next_hash++;
|
||||
next_hash++;
|
||||
|
||||
for (; next_hash < end - 3; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] =
|
||||
(uint64_t) (next_hash - file_start);
|
||||
}
|
||||
for (; next_hash < end - 3; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] =
|
||||
(uint64_t) (next_hash - file_start);
|
||||
}
|
||||
|
||||
get_len_code(stream->hufftables, match_length, &code,
|
||||
&code_len);
|
||||
get_dist_code(stream->hufftables, dist, &code2,
|
||||
&code_len2);
|
||||
get_len_code(stream->hufftables, match_length, &code,
|
||||
&code_len);
|
||||
get_dist_code(stream->hufftables, dist, &code2, &code_len2);
|
||||
|
||||
code |= code2 << code_len;
|
||||
code_len += code_len2;
|
||||
code |= code2 << code_len;
|
||||
code_len += code_len2;
|
||||
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
|
||||
next_in += match_length;
|
||||
next_in += match_length;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
next_in++;
|
||||
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
next_in++;
|
||||
}
|
||||
|
||||
}
|
||||
while (next_in < end_in) {
|
||||
if (is_full(&state->bitbuf)) {
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
return;
|
||||
}
|
||||
|
||||
while (next_in < end_in) {
|
||||
if (is_full(&state->bitbuf)) {
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
return;
|
||||
}
|
||||
literal = *next_in;
|
||||
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
next_in++;
|
||||
}
|
||||
}
|
||||
|
||||
literal = *next_in;
|
||||
get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
next_in++;
|
||||
if (!is_full(&state->bitbuf)) {
|
||||
get_lit_code(stream->hufftables, 256, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
state->has_eob = 1;
|
||||
|
||||
}
|
||||
}
|
||||
if (stream->end_of_stream == 1)
|
||||
state->state = ZSTATE_TRL;
|
||||
else
|
||||
state->state = ZSTATE_SYNC_FLUSH;
|
||||
}
|
||||
|
||||
if (!is_full(&state->bitbuf)) {
|
||||
get_lit_code(stream->hufftables, 256, &code, &code_len);
|
||||
write_bits(&state->bitbuf, code, code_len);
|
||||
state->has_eob = 1;
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
|
||||
if (stream->end_of_stream == 1)
|
||||
state->state = ZSTATE_TRL;
|
||||
else
|
||||
state->state = ZSTATE_SYNC_FLUSH;
|
||||
}
|
||||
|
||||
update_state(stream, start_in, next_in, end_in);
|
||||
|
||||
return;
|
||||
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;
|
||||
uint32_t literal;
|
||||
uint32_t hash;
|
||||
uint16_t index = current_index - dict_len;
|
||||
uint8_t *next_in = dict;
|
||||
uint8_t *end_in = dict + dict_len - SHORTEST_MATCH;
|
||||
uint32_t literal;
|
||||
uint32_t hash;
|
||||
uint16_t index = current_index - dict_len;
|
||||
|
||||
while (next_in <= end_in) {
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
hash_table[hash] = index;
|
||||
index++;
|
||||
next_in++;
|
||||
}
|
||||
while (next_in <= end_in) {
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
hash_table[hash] = index;
|
||||
index++;
|
||||
next_in++;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
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 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);
|
||||
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 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);
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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 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)
|
||||
{
|
||||
return encode_deflate_icf_base(next_in, end_in, bb, 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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
gen_icf_map_h1_base(stream, matches_icf_lookup, input_size);
|
||||
}
|
||||
|
@ -7,34 +7,37 @@
|
||||
#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++) {
|
||||
data[i] = rand() % 256;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
data[i] = rand() % 256;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int time = BENCHMARK_TIME;
|
||||
struct isal_zstream stream;
|
||||
uint8_t dict[DICT_LEN];
|
||||
uint32_t dict_len = DICT_LEN;
|
||||
int time = BENCHMARK_TIME;
|
||||
struct isal_zstream stream;
|
||||
uint8_t dict[DICT_LEN];
|
||||
uint32_t dict_len = DICT_LEN;
|
||||
|
||||
stream.level = 0;
|
||||
stream.internal_state.hash_mask = LVL0_HASH_MASK;
|
||||
create_rand_data(dict, dict_len);
|
||||
stream.level = 0;
|
||||
stream.internal_state.hash_mask = LVL0_HASH_MASK;
|
||||
create_rand_data(dict, dict_len);
|
||||
|
||||
struct perf start;
|
||||
BENCHMARK(&start, time, isal_deflate_hash(&stream, dict, dict_len));
|
||||
struct perf start;
|
||||
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);
|
||||
printf("igzip_build_hash_table_perf: in_size=%u ", dict_len);
|
||||
perf_print(start, (long long) dict_len);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,9 +4,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_ADLER_BUF (1 << 28)
|
||||
#define ADLER_MOD 65521
|
||||
#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
|
||||
|
@ -33,69 +33,70 @@
|
||||
|
||||
#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;
|
||||
uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE];
|
||||
FILE *in, *out;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: igzip_example infile outfile\n");
|
||||
exit(0);
|
||||
}
|
||||
in = fopen(argv[1], "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
out = fopen(argv[2], "wb");
|
||||
if (!out) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", argv[2]);
|
||||
exit(0);
|
||||
}
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: igzip_example infile outfile\n");
|
||||
exit(0);
|
||||
}
|
||||
in = fopen(argv[1], "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
out = fopen(argv[2], "wb");
|
||||
if (!out) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", argv[2]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("igzip_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
fflush(0);
|
||||
printf("igzip_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
fflush(0);
|
||||
|
||||
isal_deflate_init(&stream);
|
||||
stream.end_of_stream = 0;
|
||||
stream.flush = NO_FLUSH;
|
||||
isal_deflate_init(&stream);
|
||||
stream.end_of_stream = 0;
|
||||
stream.flush = NO_FLUSH;
|
||||
|
||||
if (LEVEL == 1) {
|
||||
stream.level = 1;
|
||||
stream.level_buf = malloc(ISAL_DEF_LVL1_DEFAULT);
|
||||
stream.level_buf_size = ISAL_DEF_LVL1_DEFAULT;
|
||||
if (stream.level_buf == 0) {
|
||||
printf("Failed to allocate level compression buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
if (LEVEL == 1) {
|
||||
stream.level = 1;
|
||||
stream.level_buf = malloc(ISAL_DEF_LVL1_DEFAULT);
|
||||
stream.level_buf_size = ISAL_DEF_LVL1_DEFAULT;
|
||||
if (stream.level_buf == 0) {
|
||||
printf("Failed to allocate level compression buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, BUF_SIZE, in);
|
||||
stream.end_of_stream = feof(in) ? 1 : 0;
|
||||
stream.next_in = inbuf;
|
||||
do {
|
||||
stream.avail_out = BUF_SIZE;
|
||||
stream.next_out = outbuf;
|
||||
do {
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, BUF_SIZE, in);
|
||||
stream.end_of_stream = feof(in) ? 1 : 0;
|
||||
stream.next_in = inbuf;
|
||||
do {
|
||||
stream.avail_out = BUF_SIZE;
|
||||
stream.next_out = outbuf;
|
||||
|
||||
isal_deflate(&stream);
|
||||
isal_deflate(&stream);
|
||||
|
||||
fwrite(outbuf, 1, BUF_SIZE - stream.avail_out, out);
|
||||
} while (stream.avail_out == 0);
|
||||
fwrite(outbuf, 1, BUF_SIZE - stream.avail_out, out);
|
||||
} while (stream.avail_out == 0);
|
||||
|
||||
assert(stream.avail_in == 0);
|
||||
} while (stream.internal_state.state != ZSTATE_END);
|
||||
assert(stream.avail_in == 0);
|
||||
} while (stream.internal_state.state != ZSTATE_END);
|
||||
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
|
||||
printf("End of igzip_example\n\n");
|
||||
return 0;
|
||||
printf("End of igzip_example\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -40,309 +40,309 @@
|
||||
|
||||
int level_size_buf[10] = {
|
||||
#ifdef ISAL_DEF_LVL0_DEFAULT
|
||||
ISAL_DEF_LVL0_DEFAULT,
|
||||
ISAL_DEF_LVL0_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL1_DEFAULT
|
||||
ISAL_DEF_LVL1_DEFAULT,
|
||||
ISAL_DEF_LVL1_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL2_DEFAULT
|
||||
ISAL_DEF_LVL2_DEFAULT,
|
||||
ISAL_DEF_LVL2_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL3_DEFAULT
|
||||
ISAL_DEF_LVL3_DEFAULT,
|
||||
ISAL_DEF_LVL3_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL4_DEFAULT
|
||||
ISAL_DEF_LVL4_DEFAULT,
|
||||
ISAL_DEF_LVL4_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL5_DEFAULT
|
||||
ISAL_DEF_LVL5_DEFAULT,
|
||||
ISAL_DEF_LVL5_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL6_DEFAULT
|
||||
ISAL_DEF_LVL6_DEFAULT,
|
||||
ISAL_DEF_LVL6_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL7_DEFAULT
|
||||
ISAL_DEF_LVL7_DEFAULT,
|
||||
ISAL_DEF_LVL7_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL8_DEFAULT
|
||||
ISAL_DEF_LVL8_DEFAULT,
|
||||
ISAL_DEF_LVL8_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
#ifdef ISAL_DEF_LVL9_DEFAULT
|
||||
ISAL_DEF_LVL9_DEFAULT,
|
||||
ISAL_DEF_LVL9_DEFAULT,
|
||||
#else
|
||||
0,
|
||||
0,
|
||||
#endif
|
||||
};
|
||||
|
||||
int usage(void)
|
||||
int
|
||||
usage(void)
|
||||
{
|
||||
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"
|
||||
" -i <time> time in seconds to benchmark (at least 0)\n"
|
||||
" -o <file> output file for compressed data\n"
|
||||
" -d <file> dictionary file used by compression\n"
|
||||
" -w <size> log base 2 size of history window, between 8 and 15\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"
|
||||
" -i <time> time in seconds to benchmark (at least 0)\n"
|
||||
" -o <file> output file for compressed data\n"
|
||||
" -d <file> dictionary file used by compression\n"
|
||||
" -w <size> log base 2 size of history window, between 8 and 15\n");
|
||||
|
||||
exit(0);
|
||||
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,
|
||||
struct isal_hufftables *hufftables_custom)
|
||||
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;
|
||||
isal_deflate_init(stream);
|
||||
stream->level = level;
|
||||
stream->level_buf = level_buf;
|
||||
stream->level_buf_size = level_size;
|
||||
int avail_in;
|
||||
isal_deflate_init(stream);
|
||||
stream->level = level;
|
||||
stream->level_buf = level_buf;
|
||||
stream->level_buf_size = level_size;
|
||||
|
||||
if (COMP_OK != isal_deflate_reset_dict(stream, dict_str))
|
||||
if (dictbuf != NULL)
|
||||
isal_deflate_set_dict(stream, dictbuf, dictfile_size);
|
||||
if (COMP_OK != isal_deflate_reset_dict(stream, dict_str))
|
||||
if (dictbuf != NULL)
|
||||
isal_deflate_set_dict(stream, dictbuf, dictfile_size);
|
||||
|
||||
stream->end_of_stream = 0;
|
||||
stream->flush = NO_FLUSH;
|
||||
stream->next_out = outbuf;
|
||||
stream->avail_out = outbuf_size;
|
||||
stream->next_in = inbuf;
|
||||
if (hufftables_custom != NULL)
|
||||
stream->hufftables = hufftables_custom;
|
||||
stream->hist_bits = hist_bits;
|
||||
avail_in = infile_size;
|
||||
stream->end_of_stream = 0;
|
||||
stream->flush = NO_FLUSH;
|
||||
stream->next_out = outbuf;
|
||||
stream->avail_out = outbuf_size;
|
||||
stream->next_in = inbuf;
|
||||
if (hufftables_custom != NULL)
|
||||
stream->hufftables = hufftables_custom;
|
||||
stream->hist_bits = hist_bits;
|
||||
avail_in = infile_size;
|
||||
|
||||
while (avail_in > 0) {
|
||||
stream->avail_in = avail_in >= inbuf_size ? inbuf_size : avail_in;
|
||||
avail_in -= inbuf_size;
|
||||
while (avail_in > 0) {
|
||||
stream->avail_in = avail_in >= inbuf_size ? inbuf_size : avail_in;
|
||||
avail_in -= inbuf_size;
|
||||
|
||||
if (avail_in <= 0)
|
||||
stream->end_of_stream = 1;
|
||||
if (avail_in <= 0)
|
||||
stream->end_of_stream = 1;
|
||||
|
||||
isal_deflate(stream);
|
||||
isal_deflate(stream);
|
||||
|
||||
if (stream->avail_in != 0)
|
||||
break;
|
||||
}
|
||||
if (stream->avail_in != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
int c, time = BENCHMARK_TIME, inbuf_size = 0;
|
||||
size_t infile_size, outbuf_size, dictfile_size;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_hufftables hufftables_custom;
|
||||
int level = 0, level_size = 0;
|
||||
char *in_file_name = NULL, *out_file_name = NULL, *dict_file_name = NULL;
|
||||
uint32_t hist_bits = 0;
|
||||
struct isal_zstream stream;
|
||||
FILE *in = NULL, *out = NULL, *dict = NULL;
|
||||
unsigned char *inbuf, *outbuf, *level_buf = NULL, *dictbuf = NULL;
|
||||
int c, time = BENCHMARK_TIME, inbuf_size = 0;
|
||||
size_t infile_size, outbuf_size, dictfile_size;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_hufftables hufftables_custom;
|
||||
int level = 0, level_size = 0;
|
||||
char *in_file_name = NULL, *out_file_name = NULL, *dict_file_name = NULL;
|
||||
uint32_t hist_bits = 0;
|
||||
struct isal_zstream stream;
|
||||
|
||||
while ((c = getopt(argc, argv, "h0123456789i:b:o:d:w:")) != -1) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (c > '0' + ISAL_DEF_MAX_LEVEL)
|
||||
usage();
|
||||
else {
|
||||
level = c - '0';
|
||||
level_size = level_size_buf[level];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
while ((c = getopt(argc, argv, "h0123456789i:b:o:d:w:")) != -1) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (c > '0' + ISAL_DEF_MAX_LEVEL)
|
||||
usage();
|
||||
else {
|
||||
level = c - '0';
|
||||
level_size = level_size_buf[level];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'o':
|
||||
out_file_name = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
dict_file_name = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
time = atoi(optarg);
|
||||
if (time < 0)
|
||||
usage();
|
||||
break;
|
||||
case 'b':
|
||||
inbuf_size = atoi(optarg);
|
||||
break;
|
||||
case 'w':
|
||||
hist_bits = atoi(optarg);
|
||||
if (hist_bits > 15 || hist_bits < 8)
|
||||
usage();
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (c) {
|
||||
case 'o':
|
||||
out_file_name = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
dict_file_name = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
time = atoi(optarg);
|
||||
if (time < 0)
|
||||
usage();
|
||||
break;
|
||||
case 'b':
|
||||
inbuf_size = atoi(optarg);
|
||||
break;
|
||||
case 'w':
|
||||
hist_bits = atoi(optarg);
|
||||
if (hist_bits > 15 || hist_bits < 8)
|
||||
usage();
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
in_file_name = argv[optind];
|
||||
in = fopen(in_file_name, "rb");
|
||||
} else
|
||||
usage();
|
||||
if (optind < argc) {
|
||||
in_file_name = argv[optind];
|
||||
in = fopen(in_file_name, "rb");
|
||||
} else
|
||||
usage();
|
||||
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", in_file_name);
|
||||
exit(0);
|
||||
}
|
||||
if (out_file_name != NULL) {
|
||||
out = fopen(out_file_name, "wb");
|
||||
if (!out) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", out_file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf("outfile=%s\n", out_file_name);
|
||||
}
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", in_file_name);
|
||||
exit(0);
|
||||
}
|
||||
if (out_file_name != NULL) {
|
||||
out = fopen(out_file_name, "wb");
|
||||
if (!out) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", out_file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf("outfile=%s\n", out_file_name);
|
||||
}
|
||||
|
||||
if (dict_file_name != NULL) {
|
||||
dict = fopen(dict_file_name, "rb");
|
||||
if (!dict) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", dict_file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf("outfile=%s\n", dict_file_name);
|
||||
}
|
||||
if (dict_file_name != NULL) {
|
||||
dict = fopen(dict_file_name, "rb");
|
||||
if (!dict) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", dict_file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf("outfile=%s\n", dict_file_name);
|
||||
}
|
||||
|
||||
if (hist_bits == 0)
|
||||
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
if (hist_bits == 0)
|
||||
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
|
||||
else if (hist_bits < 10)
|
||||
printf("Window Size: %.2f K\n", 1.0 * (1 << hist_bits) / 1024);
|
||||
else
|
||||
printf("Window Size: %d K\n", (1 << hist_bits) / 1024);
|
||||
else if (hist_bits < 10)
|
||||
printf("Window Size: %.2f K\n", 1.0 * (1 << hist_bits) / 1024);
|
||||
else
|
||||
printf("Window Size: %d K\n", (1 << hist_bits) / 1024);
|
||||
|
||||
printf("igzip_file_perf: \n");
|
||||
fflush(0);
|
||||
printf("igzip_file_perf: \n");
|
||||
fflush(0);
|
||||
|
||||
/* Allocate space for entire input file and output
|
||||
* (assuming some possible expansion on output size)
|
||||
*/
|
||||
infile_size = get_filesize(in);
|
||||
/* Allocate space for entire input file and output
|
||||
* (assuming some possible expansion on output size)
|
||||
*/
|
||||
infile_size = get_filesize(in);
|
||||
|
||||
outbuf_size = 2 * infile_size + BUF_SIZE;
|
||||
outbuf_size = 2 * infile_size + BUF_SIZE;
|
||||
|
||||
dictfile_size = (dict_file_name != NULL) ? get_filesize(dict) : 0;
|
||||
dictfile_size = (dict_file_name != NULL) ? get_filesize(dict) : 0;
|
||||
|
||||
inbuf = malloc(infile_size);
|
||||
if (inbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate input buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
outbuf = malloc(outbuf_size);
|
||||
if (outbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate output buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
inbuf = malloc(infile_size);
|
||||
if (inbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate input buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
outbuf = malloc(outbuf_size);
|
||||
if (outbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate output buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (dictfile_size != 0) {
|
||||
dictbuf = malloc(dictfile_size);
|
||||
if (dictbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate dictionary buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
if (dictfile_size != 0) {
|
||||
dictbuf = malloc(dictfile_size);
|
||||
if (dictbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate dictionary buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (level_size != 0) {
|
||||
level_buf = malloc(level_size);
|
||||
if (level_buf == NULL) {
|
||||
fprintf(stderr, "Can't allocate level buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
if (level_size != 0) {
|
||||
level_buf = malloc(level_size);
|
||||
if (level_buf == NULL) {
|
||||
fprintf(stderr, "Can't allocate level buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
inbuf_size = inbuf_size ? inbuf_size : infile_size;
|
||||
inbuf_size = inbuf_size ? inbuf_size : infile_size;
|
||||
|
||||
printf("igzip_file_perf: %s\n", in_file_name);
|
||||
printf("igzip_file_perf: %s\n", in_file_name);
|
||||
|
||||
/* Read complete input file into buffer */
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in);
|
||||
if (stream.avail_in != infile_size) {
|
||||
fprintf(stderr, "Couldn't fit all of input file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
/* Read complete input file into buffer */
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in);
|
||||
if (stream.avail_in != infile_size) {
|
||||
fprintf(stderr, "Couldn't fit all of input file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Read complete dictionary into buffer */
|
||||
if ((dictfile_size != 0) && (dictfile_size != fread(dictbuf, 1, dictfile_size, dict))) {
|
||||
fprintf(stderr, "Couldn't fit all of dictionary file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
/* Read complete dictionary into buffer */
|
||||
if ((dictfile_size != 0) && (dictfile_size != fread(dictbuf, 1, dictfile_size, dict))) {
|
||||
fprintf(stderr, "Couldn't fit all of dictionary file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
struct isal_dict dict_str;
|
||||
stream.level = level;
|
||||
isal_deflate_process_dict(&stream, &dict_str, dictbuf, dictfile_size);
|
||||
struct isal_dict dict_str;
|
||||
stream.level = level;
|
||||
isal_deflate_process_dict(&stream, &dict_str, dictbuf, dictfile_size);
|
||||
|
||||
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);
|
||||
}
|
||||
if (stream.avail_in != 0) {
|
||||
fprintf(stderr, "Could not compress all of inbuf\n");
|
||||
exit(0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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));
|
||||
if (level == 0) {
|
||||
memset(&histogram, 0, sizeof(histogram));
|
||||
|
||||
isal_update_histogram(inbuf, infile_size, &histogram);
|
||||
isal_create_hufftables(&hufftables_custom, &histogram);
|
||||
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);
|
||||
}
|
||||
printf("\n");
|
||||
printf(" ratio_custom=%3.1f%%", 100.0 * stream.total_out / infile_size);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (stream.avail_in != 0) {
|
||||
fprintf(stderr, "Could not compress all of inbuf\n");
|
||||
exit(0);
|
||||
}
|
||||
if (stream.avail_in != 0) {
|
||||
fprintf(stderr, "Could not compress all of inbuf\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("igzip_file: ");
|
||||
perf_print(start, (long long)infile_size);
|
||||
printf("igzip_file: ");
|
||||
perf_print(start, (long long) infile_size);
|
||||
|
||||
if (argc > 2 && out) {
|
||||
printf("writing %s\n", out_file_name);
|
||||
fwrite(outbuf, 1, stream.total_out, out);
|
||||
fclose(out);
|
||||
}
|
||||
if (argc > 2 && out) {
|
||||
printf("writing %s\n", out_file_name);
|
||||
fwrite(outbuf, 1, stream.total_out, out);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
printf("End of igzip_file_perf\n\n");
|
||||
fflush(0);
|
||||
return 0;
|
||||
fclose(in);
|
||||
printf("End of igzip_file_perf\n\n");
|
||||
fflush(0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,95 +35,96 @@
|
||||
#include "igzip_lib.h"
|
||||
#include "test.h"
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
#define MIN_TEST_LOOPS 8
|
||||
#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");
|
||||
for (i = 0; i < ISAL_DEF_LIT_LEN_SYMBOLS; i++) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(", ");
|
||||
printf("%4lu", histogram->lit_len_histogram[i]);
|
||||
}
|
||||
printf("\n");
|
||||
int i;
|
||||
printf("Lit Len histogram");
|
||||
for (i = 0; i < ISAL_DEF_LIT_LEN_SYMBOLS; i++) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(", ");
|
||||
printf("%4lu", histogram->lit_len_histogram[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Dist histogram");
|
||||
for (i = 0; i < ISAL_DEF_DIST_SYMBOLS; i++) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(", ");
|
||||
printf("%4lu", histogram->dist_histogram[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("Dist histogram");
|
||||
for (i = 0; i < ISAL_DEF_DIST_SYMBOLS; i++) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(", ");
|
||||
printf("%4lu", histogram->dist_histogram[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in;
|
||||
unsigned char *inbuf;
|
||||
int iterations, avail_in;
|
||||
uint64_t infile_size;
|
||||
struct isal_huff_histogram histogram1, histogram2;
|
||||
FILE *in;
|
||||
unsigned char *inbuf;
|
||||
int iterations, avail_in;
|
||||
uint64_t infile_size;
|
||||
struct isal_huff_histogram histogram1, histogram2;
|
||||
|
||||
memset(&histogram1, 0, sizeof(histogram1));
|
||||
memset(&histogram2, 0, sizeof(histogram2));
|
||||
memset(&histogram1, 0, sizeof(histogram1));
|
||||
memset(&histogram2, 0, sizeof(histogram2));
|
||||
|
||||
if (argc > 3 || argc < 2) {
|
||||
fprintf(stderr, "Usage: igzip_file_perf infile [outfile]\n"
|
||||
"\t - Runs multiple iterations of igzip on a file to "
|
||||
"get more accurate time results.\n");
|
||||
exit(0);
|
||||
}
|
||||
in = fopen(argv[1], "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
if (argc > 3 || argc < 2) {
|
||||
fprintf(stderr, "Usage: igzip_file_perf infile [outfile]\n"
|
||||
"\t - Runs multiple iterations of igzip on a file to "
|
||||
"get more accurate time results.\n");
|
||||
exit(0);
|
||||
}
|
||||
in = fopen(argv[1], "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Allocate space for entire input file and output
|
||||
* (assuming some possible expansion on output size)
|
||||
*/
|
||||
infile_size = get_filesize(in);
|
||||
/* Allocate space for entire input file and output
|
||||
* (assuming some possible expansion on output size)
|
||||
*/
|
||||
infile_size = get_filesize(in);
|
||||
|
||||
if (infile_size != 0)
|
||||
iterations = RUN_MEM_SIZE / infile_size;
|
||||
else
|
||||
iterations = MIN_TEST_LOOPS;
|
||||
if (infile_size != 0)
|
||||
iterations = RUN_MEM_SIZE / infile_size;
|
||||
else
|
||||
iterations = MIN_TEST_LOOPS;
|
||||
|
||||
if (iterations < MIN_TEST_LOOPS)
|
||||
iterations = MIN_TEST_LOOPS;
|
||||
if (iterations < MIN_TEST_LOOPS)
|
||||
iterations = MIN_TEST_LOOPS;
|
||||
|
||||
inbuf = malloc(infile_size);
|
||||
if (inbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate input buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
inbuf = malloc(infile_size);
|
||||
if (inbuf == NULL) {
|
||||
fprintf(stderr, "Can't allocate input buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
avail_in = fread(inbuf, 1, infile_size, in);
|
||||
if (avail_in != infile_size) {
|
||||
free(inbuf);
|
||||
fprintf(stderr, "Couldn't fit all of input file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
avail_in = fread(inbuf, 1, infile_size, in);
|
||||
if (avail_in != infile_size) {
|
||||
free(inbuf);
|
||||
fprintf(stderr, "Couldn't fit all of input file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
struct perf start;
|
||||
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);
|
||||
struct perf start;
|
||||
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);
|
||||
|
||||
fclose(in);
|
||||
fflush(0);
|
||||
free(inbuf);
|
||||
fclose(in);
|
||||
fflush(0);
|
||||
free(inbuf);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,365 +6,363 @@
|
||||
#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;
|
||||
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,
|
||||
struct deflate_icf *start_out, struct deflate_icf *next_out,
|
||||
struct deflate_icf *end_out)
|
||||
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;
|
||||
if (next_in - start_in > 0)
|
||||
stream->internal_state.has_hist = IGZIP_HIST;
|
||||
|
||||
stream->next_in = next_in;
|
||||
stream->total_in += next_in - start_in;
|
||||
stream->internal_state.block_end = stream->total_in;
|
||||
stream->avail_in = end_in - next_in;
|
||||
stream->next_in = next_in;
|
||||
stream->total_in += next_in - start_in;
|
||||
stream->internal_state.block_end = stream->total_in;
|
||||
stream->avail_in = end_in - next_in;
|
||||
|
||||
level_buf->icf_buf_next = next_out;
|
||||
level_buf->icf_buf_avail_out = end_out - next_out;
|
||||
level_buf->icf_buf_next = next_out;
|
||||
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;
|
||||
struct deflate_icf *start_out, *next_out, *end_out;
|
||||
uint16_t match_length;
|
||||
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;
|
||||
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;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
uint32_t literal, hash;
|
||||
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
|
||||
struct deflate_icf *start_out, *next_out, *end_out;
|
||||
uint16_t match_length;
|
||||
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;
|
||||
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;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
return;
|
||||
}
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
return;
|
||||
}
|
||||
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
start_in = stream->next_in;
|
||||
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 /
|
||||
sizeof(struct deflate_icf);
|
||||
next_out = start_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;
|
||||
|
||||
while (next_in + ISAL_LOOK_AHEAD < end_in) {
|
||||
while (next_in + ISAL_LOOK_AHEAD < end_in) {
|
||||
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
|
||||
/* The -1 are to handle the case when dist = 0 */
|
||||
if (dist - 1 < hist_size) {
|
||||
assert(dist != 0);
|
||||
/* The -1 are to handle the case when dist = 0 */
|
||||
if (dist - 1 < hist_size) {
|
||||
assert(dist != 0);
|
||||
|
||||
match_length = compare258(next_in - dist, next_in, 258);
|
||||
match_length = compare258(next_in - dist, next_in, 258);
|
||||
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
#ifdef ISAL_LIMIT_HASH_UPDATE
|
||||
end = next_hash + 3;
|
||||
end = next_hash + 3;
|
||||
#else
|
||||
end = next_hash + match_length;
|
||||
end = next_hash + match_length;
|
||||
#endif
|
||||
next_hash++;
|
||||
next_hash++;
|
||||
|
||||
for (; next_hash < end; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
for (; next_hash < end; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
|
||||
get_len_icf_code(match_length, &code);
|
||||
get_dist_icf_code(dist, &code2, &extra_bits);
|
||||
get_len_icf_code(match_length, &code);
|
||||
get_dist_icf_code(dist, &code2, &extra_bits);
|
||||
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
level_buf->hist.d_hist[code2]++;
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
level_buf->hist.d_hist[code2]++;
|
||||
|
||||
write_deflate_icf(next_out, code, code2, extra_bits);
|
||||
next_out++;
|
||||
next_in += match_length;
|
||||
write_deflate_icf(next_out, code, code2, extra_bits);
|
||||
next_out++;
|
||||
next_in += match_length;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
}
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
}
|
||||
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out, end_out);
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out, end_out);
|
||||
|
||||
assert(stream->avail_in <= ISAL_LOOK_AHEAD);
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
|
||||
return;
|
||||
assert(stream->avail_in <= ISAL_LOOK_AHEAD);
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
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;
|
||||
struct deflate_icf *start_out, *next_out, *end_out;
|
||||
uint16_t match_length;
|
||||
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;
|
||||
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;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
uint32_t literal = 0, hash;
|
||||
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
|
||||
struct deflate_icf *start_out, *next_out, *end_out;
|
||||
uint16_t match_length;
|
||||
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;
|
||||
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;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
start_in = stream->next_in;
|
||||
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 /
|
||||
sizeof(struct deflate_icf);
|
||||
next_out = start_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;
|
||||
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
return;
|
||||
}
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
return;
|
||||
}
|
||||
|
||||
while (next_in + 3 < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
while (next_in + 3 < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
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 */
|
||||
match_length = compare258(next_in - dist, next_in, end_in - next_in);
|
||||
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);
|
||||
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
#ifdef ISAL_LIMIT_HASH_UPDATE
|
||||
end = next_hash + 3;
|
||||
end = next_hash + 3;
|
||||
#else
|
||||
end = next_hash + match_length;
|
||||
end = next_hash + match_length;
|
||||
#endif
|
||||
next_hash++;
|
||||
next_hash++;
|
||||
|
||||
for (; next_hash < end - 3; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
for (; next_hash < end - 3; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
|
||||
get_len_icf_code(match_length, &code);
|
||||
get_dist_icf_code(dist, &code2, &extra_bits);
|
||||
get_len_icf_code(match_length, &code);
|
||||
get_dist_icf_code(dist, &code2, &extra_bits);
|
||||
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
level_buf->hist.d_hist[code2]++;
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
level_buf->hist.d_hist[code2]++;
|
||||
|
||||
write_deflate_icf(next_out, code, code2, extra_bits);
|
||||
write_deflate_icf(next_out, code, code2, extra_bits);
|
||||
|
||||
next_out++;
|
||||
next_in += match_length;
|
||||
next_out++;
|
||||
next_in += match_length;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
}
|
||||
|
||||
}
|
||||
while (next_in < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
|
||||
while (next_in < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
literal = *next_in;
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
}
|
||||
|
||||
literal = *next_in;
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
if (next_in == end_in) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
}
|
||||
|
||||
}
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out, end_out);
|
||||
|
||||
if (next_in == end_in) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
}
|
||||
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out, end_out);
|
||||
|
||||
return;
|
||||
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;
|
||||
struct deflate_icf *start_out, *next_out, *end_out;
|
||||
uint16_t match_length;
|
||||
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;
|
||||
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;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
uint32_t literal = 0, hash;
|
||||
uint8_t *start_in, *next_in, *end_in, *end, *next_hash;
|
||||
struct deflate_icf *start_out, *next_out, *end_out;
|
||||
uint16_t match_length;
|
||||
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;
|
||||
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;
|
||||
uint32_t hash_mask = state->hash_mask;
|
||||
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
start_in = stream->next_in;
|
||||
end_in = start_in + stream->avail_in;
|
||||
next_in = start_in;
|
||||
|
||||
start_out = level_buf->icf_buf_next;
|
||||
end_out = start_out + level_buf->icf_buf_avail_out / sizeof(struct deflate_icf);
|
||||
next_out = start_out;
|
||||
start_out = level_buf->icf_buf_next;
|
||||
end_out = start_out + level_buf->icf_buf_avail_out / sizeof(struct deflate_icf);
|
||||
next_out = start_out;
|
||||
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
return;
|
||||
}
|
||||
if (stream->avail_in == 0) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
return;
|
||||
}
|
||||
|
||||
while (next_in + 3 < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
while (next_in + 3 < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash_mad(literal) & hash_mask;
|
||||
dist = (next_in - file_start - last_seen[hash]) & 0xFFFF;
|
||||
last_seen[hash] = (uint64_t) (next_in - file_start);
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash_mad(literal) & hash_mask;
|
||||
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 */
|
||||
match_length = compare258(next_in - dist, next_in, end_in - next_in);
|
||||
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);
|
||||
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
if (match_length >= SHORTEST_MATCH) {
|
||||
next_hash = next_in;
|
||||
#ifdef ISAL_LIMIT_HASH_UPDATE
|
||||
end = next_hash + 3;
|
||||
end = next_hash + 3;
|
||||
#else
|
||||
end = next_hash + match_length;
|
||||
end = next_hash + match_length;
|
||||
#endif
|
||||
next_hash++;
|
||||
next_hash++;
|
||||
|
||||
for (; next_hash < end - 3; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash_mad(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
for (; next_hash < end - 3; next_hash++) {
|
||||
literal = load_le_u32(next_hash);
|
||||
hash = compute_hash_mad(literal) & hash_mask;
|
||||
last_seen[hash] = (uint64_t) (next_hash - file_start);
|
||||
}
|
||||
|
||||
get_len_icf_code(match_length, &code);
|
||||
get_dist_icf_code(dist, &code2, &extra_bits);
|
||||
get_len_icf_code(match_length, &code);
|
||||
get_dist_icf_code(dist, &code2, &extra_bits);
|
||||
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
level_buf->hist.d_hist[code2]++;
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
level_buf->hist.d_hist[code2]++;
|
||||
|
||||
write_deflate_icf(next_out, code, code2, extra_bits);
|
||||
write_deflate_icf(next_out, code, code2, extra_bits);
|
||||
|
||||
next_out++;
|
||||
next_in += match_length;
|
||||
next_out++;
|
||||
next_in += match_length;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
}
|
||||
|
||||
}
|
||||
while (next_in < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
|
||||
while (next_in < end_in) {
|
||||
if (next_out >= end_out) {
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out,
|
||||
end_out);
|
||||
return;
|
||||
}
|
||||
literal = *next_in;
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
}
|
||||
|
||||
literal = *next_in;
|
||||
get_lit_icf_code(literal & 0xFF, &code);
|
||||
level_buf->hist.ll_hist[code]++;
|
||||
write_deflate_icf(next_out, code, NULL_DIST_SYM, 0);
|
||||
next_out++;
|
||||
next_in++;
|
||||
if (next_in == end_in) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
}
|
||||
|
||||
}
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out, end_out);
|
||||
|
||||
if (next_in == end_in) {
|
||||
if (stream->end_of_stream || stream->flush != NO_FLUSH)
|
||||
state->state = ZSTATE_CREATE_HDR;
|
||||
}
|
||||
|
||||
update_state(stream, start_in, next_in, end_in, start_out, next_out, end_out);
|
||||
|
||||
return;
|
||||
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;
|
||||
uint32_t literal;
|
||||
uint32_t hash;
|
||||
uint16_t index = current_index - dict_len;
|
||||
uint8_t *next_in = dict;
|
||||
uint8_t *end_in = dict + dict_len - SHORTEST_MATCH;
|
||||
uint32_t literal;
|
||||
uint32_t hash;
|
||||
uint16_t index = current_index - dict_len;
|
||||
|
||||
while (next_in <= end_in) {
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash_mad(literal) & hash_mask;
|
||||
hash_table[hash] = index;
|
||||
index++;
|
||||
next_in++;
|
||||
}
|
||||
while (next_in <= end_in) {
|
||||
literal = load_le_u32(next_in);
|
||||
hash = compute_hash_mad(literal) & hash_mask;
|
||||
hash_table[hash] = index;
|
||||
index++;
|
||||
next_in++;
|
||||
}
|
||||
}
|
||||
|
@ -3,335 +3,344 @@
|
||||
#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; */
|
||||
/* 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,
|
||||
struct deflate_icf *match_lookup)
|
||||
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,
|
||||
0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
|
||||
0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
|
||||
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000
|
||||
};
|
||||
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,
|
||||
0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
|
||||
0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
|
||||
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 };
|
||||
|
||||
if (end_in > end_processed + ISAL_LOOK_AHEAD)
|
||||
end_in = end_processed + ISAL_LOOK_AHEAD;
|
||||
if (end_in > end_processed + ISAL_LOOK_AHEAD)
|
||||
end_in = end_processed + ISAL_LOOK_AHEAD;
|
||||
|
||||
while (next_in < end_processed) {
|
||||
dist_code = match_lookup->lit_dist;
|
||||
dist_extra = match_lookup->dist_extra;
|
||||
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;
|
||||
while (next_in < end_processed) {
|
||||
dist_code = match_lookup->lit_dist;
|
||||
dist_extra = match_lookup->dist_extra;
|
||||
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;
|
||||
|
||||
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);
|
||||
match_lookup++;
|
||||
next_in++;
|
||||
match_len--;
|
||||
}
|
||||
}
|
||||
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);
|
||||
match_lookup++;
|
||||
next_in++;
|
||||
match_len--;
|
||||
}
|
||||
}
|
||||
|
||||
match_lookup++;
|
||||
next_in++;
|
||||
}
|
||||
match_lookup++;
|
||||
next_in++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*************************************************************
|
||||
* 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;
|
||||
uint8_t *next_in = stream->next_in, *end_in = stream->next_in + input_size;
|
||||
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
|
||||
uint32_t hash;
|
||||
uint64_t next_bytes, match_bytes;
|
||||
uint64_t match;
|
||||
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;
|
||||
uint32_t dist, len, extra_bits;
|
||||
uint8_t *next_in = stream->next_in, *end_in = stream->next_in + input_size;
|
||||
uint8_t *file_start = (uint8_t *) ((uintptr_t) stream->next_in - stream->total_in);
|
||||
uint32_t hash;
|
||||
uint64_t next_bytes, match_bytes;
|
||||
uint64_t match;
|
||||
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;
|
||||
|
||||
if (input_size < ISAL_LOOK_AHEAD)
|
||||
return 0;
|
||||
if (input_size < ISAL_LOOK_AHEAD)
|
||||
return 0;
|
||||
|
||||
if (stream->internal_state.has_hist == IGZIP_NO_HIST) {
|
||||
matches_icf_lookup->lit_len = *next_in;
|
||||
matches_icf_lookup->lit_dist = 0x1e;
|
||||
matches_icf_lookup->dist_extra = 0;
|
||||
if (stream->internal_state.has_hist == IGZIP_NO_HIST) {
|
||||
matches_icf_lookup->lit_len = *next_in;
|
||||
matches_icf_lookup->lit_dist = 0x1e;
|
||||
matches_icf_lookup->dist_extra = 0;
|
||||
|
||||
hash = compute_hash(load_le_u32(next_in)) & hash_mask;
|
||||
hash_table[hash] = (uint64_t) (next_in - file_start);
|
||||
hash = compute_hash(load_le_u32(next_in)) & hash_mask;
|
||||
hash_table[hash] = (uint64_t) (next_in - file_start);
|
||||
|
||||
next_in++;
|
||||
matches_icf_lookup++;
|
||||
stream->internal_state.has_hist = IGZIP_HIST;
|
||||
}
|
||||
next_in++;
|
||||
matches_icf_lookup++;
|
||||
stream->internal_state.has_hist = IGZIP_HIST;
|
||||
}
|
||||
|
||||
while (next_in < end_in - ISAL_LOOK_AHEAD) {
|
||||
hash = compute_hash(load_le_u32(next_in)) & hash_mask;
|
||||
dist = (next_in - file_start - hash_table[hash]);
|
||||
dist = ((dist - 1) & hist_size) + 1;
|
||||
hash_table[hash] = (uint64_t) (next_in - file_start);
|
||||
while (next_in < end_in - ISAL_LOOK_AHEAD) {
|
||||
hash = compute_hash(load_le_u32(next_in)) & hash_mask;
|
||||
dist = (next_in - file_start - hash_table[hash]);
|
||||
dist = ((dist - 1) & hist_size) + 1;
|
||||
hash_table[hash] = (uint64_t) (next_in - file_start);
|
||||
|
||||
match_bytes = load_le_u64(next_in - dist);
|
||||
next_bytes = load_le_u64(next_in);
|
||||
match = next_bytes ^ match_bytes;
|
||||
match_bytes = load_le_u64(next_in - dist);
|
||||
next_bytes = load_le_u64(next_in);
|
||||
match = next_bytes ^ match_bytes;
|
||||
|
||||
len = tzbytecnt(match);
|
||||
len = tzbytecnt(match);
|
||||
|
||||
if (len >= SHORTEST_MATCH) {
|
||||
len += LEN_OFFSET;
|
||||
get_dist_icf_code(dist, &dist, &extra_bits);
|
||||
write_deflate_icf(matches_icf_lookup, len, dist, extra_bits);
|
||||
} else {
|
||||
write_deflate_icf(matches_icf_lookup, *next_in, 0x1e, 0);
|
||||
}
|
||||
if (len >= SHORTEST_MATCH) {
|
||||
len += LEN_OFFSET;
|
||||
get_dist_icf_code(dist, &dist, &extra_bits);
|
||||
write_deflate_icf(matches_icf_lookup, len, dist, extra_bits);
|
||||
} else {
|
||||
write_deflate_icf(matches_icf_lookup, *next_in, 0x1e, 0);
|
||||
}
|
||||
|
||||
next_in++;
|
||||
matches_icf_lookup++;
|
||||
}
|
||||
return next_in - stream->next_in;
|
||||
next_in++;
|
||||
matches_icf_lookup++;
|
||||
}
|
||||
return next_in - stream->next_in;
|
||||
}
|
||||
|
||||
/*
|
||||
*************************************************************
|
||||
* 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,
|
||||
struct deflate_icf *matches_end)
|
||||
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 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);
|
||||
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 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);
|
||||
|
||||
while (matches_next + 1 < matches_end && level_buf->icf_buf_next + 1 < icf_buf_end) {
|
||||
while (matches_next + 1 < matches_end && level_buf->icf_buf_next + 1 < icf_buf_end) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
code = load_native_u64((uint8_t *) matches_next);
|
||||
code = load_native_u64((uint8_t *) matches_next);
|
||||
#else
|
||||
code = load_native_u32((uint8_t *) matches_next) |
|
||||
((uint64_t) load_native_u32((uint8_t *) (matches_next + 1)) << 32);
|
||||
code = load_native_u32((uint8_t *) matches_next) |
|
||||
((uint64_t) load_native_u32((uint8_t *) (matches_next + 1)) << 32);
|
||||
#endif
|
||||
lit_len = code & LIT_LEN_MASK;
|
||||
lit_len2 = (code >> ICF_CODE_LEN) & LIT_LEN_MASK;
|
||||
level_buf->hist.ll_hist[lit_len]++;
|
||||
lit_len = code & LIT_LEN_MASK;
|
||||
lit_len2 = (code >> ICF_CODE_LEN) & LIT_LEN_MASK;
|
||||
level_buf->hist.ll_hist[lit_len]++;
|
||||
|
||||
if (lit_len >= LEN_START) {
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, code);
|
||||
level_buf->icf_buf_next++;
|
||||
if (lit_len >= LEN_START) {
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, code);
|
||||
level_buf->icf_buf_next++;
|
||||
|
||||
dist = (code >> ICF_DIST_OFFSET) & DIST_LIT_MASK;
|
||||
level_buf->hist.d_hist[dist]++;
|
||||
lit_len -= LEN_OFFSET;
|
||||
matches_next += lit_len;
|
||||
dist = (code >> ICF_DIST_OFFSET) & DIST_LIT_MASK;
|
||||
level_buf->hist.d_hist[dist]++;
|
||||
lit_len -= LEN_OFFSET;
|
||||
matches_next += lit_len;
|
||||
|
||||
} else if (lit_len2 >= LEN_START) {
|
||||
} else if (lit_len2 >= LEN_START) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
store_native_u64((uint8_t *) level_buf->icf_buf_next, code);
|
||||
store_native_u64((uint8_t *) level_buf->icf_buf_next, code);
|
||||
#else
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, (uint32_t) code);
|
||||
store_native_u32((uint8_t *) (level_buf->icf_buf_next + 1),
|
||||
(uint32_t) (code >> 32));
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, (uint32_t) code);
|
||||
store_native_u32((uint8_t *) (level_buf->icf_buf_next + 1),
|
||||
(uint32_t) (code >> 32));
|
||||
#endif
|
||||
level_buf->icf_buf_next += 2;
|
||||
level_buf->icf_buf_next += 2;
|
||||
|
||||
level_buf->hist.ll_hist[lit_len2]++;
|
||||
level_buf->hist.ll_hist[lit_len2]++;
|
||||
|
||||
dist = (code >> (ICF_CODE_LEN + ICF_DIST_OFFSET)) & DIST_LIT_MASK;
|
||||
level_buf->hist.d_hist[dist]++;
|
||||
lit_len2 -= LEN_OFFSET - 1;
|
||||
matches_next += lit_len2;
|
||||
dist = (code >> (ICF_CODE_LEN + ICF_DIST_OFFSET)) & DIST_LIT_MASK;
|
||||
level_buf->hist.d_hist[dist]++;
|
||||
lit_len2 -= LEN_OFFSET - 1;
|
||||
matches_next += lit_len2;
|
||||
|
||||
} else {
|
||||
code = ((lit_len2 + LIT_START) << ICF_DIST_OFFSET) | lit_len;
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, code);
|
||||
level_buf->icf_buf_next++;
|
||||
} else {
|
||||
code = ((lit_len2 + LIT_START) << ICF_DIST_OFFSET) | lit_len;
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, code);
|
||||
level_buf->icf_buf_next++;
|
||||
|
||||
level_buf->hist.ll_hist[lit_len2]++;
|
||||
level_buf->hist.ll_hist[lit_len2]++;
|
||||
|
||||
matches_next += 2;
|
||||
}
|
||||
}
|
||||
matches_next += 2;
|
||||
}
|
||||
}
|
||||
|
||||
while (matches_next < matches_end && level_buf->icf_buf_next < icf_buf_end) {
|
||||
code = load_native_u32((uint8_t *) matches_next);
|
||||
lit_len = code & LIT_LEN_MASK;
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, code);
|
||||
level_buf->icf_buf_next++;
|
||||
while (matches_next < matches_end && level_buf->icf_buf_next < icf_buf_end) {
|
||||
code = load_native_u32((uint8_t *) matches_next);
|
||||
lit_len = code & LIT_LEN_MASK;
|
||||
store_native_u32((uint8_t *) level_buf->icf_buf_next, code);
|
||||
level_buf->icf_buf_next++;
|
||||
|
||||
level_buf->hist.ll_hist[lit_len]++;
|
||||
if (lit_len >= LEN_START) {
|
||||
dist = (code >> 10) & 0x1ff;
|
||||
level_buf->hist.d_hist[dist]++;
|
||||
lit_len -= LEN_OFFSET;
|
||||
matches_next += lit_len;
|
||||
} else {
|
||||
matches_next++;
|
||||
}
|
||||
}
|
||||
level_buf->hist.ll_hist[lit_len]++;
|
||||
if (lit_len >= LEN_START) {
|
||||
dist = (code >> 10) & 0x1ff;
|
||||
level_buf->hist.d_hist[dist]++;
|
||||
lit_len -= LEN_OFFSET;
|
||||
matches_next += lit_len;
|
||||
} else {
|
||||
matches_next++;
|
||||
}
|
||||
}
|
||||
|
||||
level_buf->icf_buf_avail_out =
|
||||
(icf_buf_end - level_buf->icf_buf_next) * sizeof(struct deflate_icf);
|
||||
level_buf->icf_buf_avail_out =
|
||||
(icf_buf_end - level_buf->icf_buf_next) * sizeof(struct deflate_icf);
|
||||
|
||||
state->block_end += matches_next - matches_start;
|
||||
if (matches_next > matches_end && matches_start < matches_end) {
|
||||
stream->next_in += matches_next - matches_end;
|
||||
stream->avail_in -= matches_next - matches_end;
|
||||
stream->total_in += matches_next - matches_end;
|
||||
}
|
||||
|
||||
return matches_next;
|
||||
state->block_end += matches_next - matches_start;
|
||||
if (matches_next > matches_end && matches_start < matches_end) {
|
||||
stream->next_in += matches_next - matches_end;
|
||||
stream->avail_in -= matches_next - matches_end;
|
||||
stream->total_in += matches_next - matches_end;
|
||||
}
|
||||
|
||||
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 isal_zstate *state = &stream->internal_state;
|
||||
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;
|
||||
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))
|
||||
state->state = ZSTATE_FLUSH_READ_BUFFER;
|
||||
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;
|
||||
uint32_t input_size, processed;
|
||||
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;
|
||||
uint32_t input_size, processed;
|
||||
|
||||
matches_icf = level_buf->hash_map.matches;
|
||||
matches_icf_lookup = matches_icf;
|
||||
matches_next_icf = level_buf->hash_map.matches_next;
|
||||
matches_end_icf = level_buf->hash_map.matches_end;
|
||||
matches_icf = level_buf->hash_map.matches;
|
||||
matches_icf_lookup = matches_icf;
|
||||
matches_next_icf = level_buf->hash_map.matches_next;
|
||||
matches_end_icf = level_buf->hash_map.matches_end;
|
||||
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_next_icf, matches_end_icf);
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_next_icf, matches_end_icf);
|
||||
|
||||
while (matches_next_icf >= matches_end_icf) {
|
||||
input_size = MATCH_BUF_SIZE;
|
||||
input_size = (input_size > stream->avail_in) ? stream->avail_in : input_size;
|
||||
while (matches_next_icf >= matches_end_icf) {
|
||||
input_size = MATCH_BUF_SIZE;
|
||||
input_size = (input_size > stream->avail_in) ? stream->avail_in : input_size;
|
||||
|
||||
if (input_size <= ISAL_LOOK_AHEAD)
|
||||
break;
|
||||
if (input_size <= ISAL_LOOK_AHEAD)
|
||||
break;
|
||||
|
||||
processed = gen_icf_map_h1_base(stream, matches_icf_lookup, input_size);
|
||||
processed = gen_icf_map_h1_base(stream, matches_icf_lookup, input_size);
|
||||
|
||||
set_long_icf_fg(stream->next_in, processed, input_size, matches_icf_lookup);
|
||||
set_long_icf_fg(stream->next_in, processed, input_size, matches_icf_lookup);
|
||||
|
||||
stream->next_in += processed;
|
||||
stream->avail_in -= processed;
|
||||
stream->total_in += processed;
|
||||
stream->next_in += processed;
|
||||
stream->avail_in -= processed;
|
||||
stream->total_in += processed;
|
||||
|
||||
matches_end_icf = matches_icf + processed;
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_icf, matches_end_icf);
|
||||
}
|
||||
matches_end_icf = matches_icf + processed;
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_icf, matches_end_icf);
|
||||
}
|
||||
|
||||
level_buf->hash_map.matches_next = matches_next_icf;
|
||||
level_buf->hash_map.matches_end = matches_end_icf;
|
||||
level_buf->hash_map.matches_next = matches_next_icf;
|
||||
level_buf->hash_map.matches_end = matches_end_icf;
|
||||
|
||||
icf_body_next_state(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;
|
||||
uint32_t input_size, processed;
|
||||
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;
|
||||
uint32_t input_size, processed;
|
||||
|
||||
matches_icf = level_buf->hash_map.matches;
|
||||
matches_icf_lookup = matches_icf;
|
||||
matches_next_icf = level_buf->hash_map.matches_next;
|
||||
matches_end_icf = level_buf->hash_map.matches_end;
|
||||
matches_icf = level_buf->hash_map.matches;
|
||||
matches_icf_lookup = matches_icf;
|
||||
matches_next_icf = level_buf->hash_map.matches_next;
|
||||
matches_end_icf = level_buf->hash_map.matches_end;
|
||||
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_next_icf, matches_end_icf);
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_next_icf, matches_end_icf);
|
||||
|
||||
while (matches_next_icf >= matches_end_icf) {
|
||||
input_size = MATCH_BUF_SIZE;
|
||||
input_size = (input_size > stream->avail_in) ? stream->avail_in : input_size;
|
||||
while (matches_next_icf >= matches_end_icf) {
|
||||
input_size = MATCH_BUF_SIZE;
|
||||
input_size = (input_size > stream->avail_in) ? stream->avail_in : input_size;
|
||||
|
||||
if (input_size <= ISAL_LOOK_AHEAD)
|
||||
break;
|
||||
if (input_size <= ISAL_LOOK_AHEAD)
|
||||
break;
|
||||
|
||||
processed = gen_icf_map_lh1(stream, matches_icf_lookup, input_size);
|
||||
processed = gen_icf_map_lh1(stream, matches_icf_lookup, input_size);
|
||||
|
||||
set_long_icf_fg(stream->next_in, processed, input_size, matches_icf_lookup);
|
||||
set_long_icf_fg(stream->next_in, processed, input_size, matches_icf_lookup);
|
||||
|
||||
stream->next_in += processed;
|
||||
stream->avail_in -= processed;
|
||||
stream->total_in += processed;
|
||||
stream->next_in += processed;
|
||||
stream->avail_in -= processed;
|
||||
stream->total_in += processed;
|
||||
|
||||
matches_end_icf = matches_icf + processed;
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_icf, matches_end_icf);
|
||||
}
|
||||
matches_end_icf = matches_icf + processed;
|
||||
matches_next_icf = compress_icf_map_g(stream, matches_icf, matches_end_icf);
|
||||
}
|
||||
|
||||
level_buf->hash_map.matches_next = matches_next_icf;
|
||||
level_buf->hash_map.matches_end = matches_end_icf;
|
||||
level_buf->hash_map.matches_next = matches_next_icf;
|
||||
level_buf->hash_map.matches_end = matches_end_icf;
|
||||
|
||||
icf_body_next_state(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:
|
||||
isal_deflate_icf_body_lvl3(stream);
|
||||
break;
|
||||
case 2:
|
||||
isal_deflate_icf_body_lvl2(stream);
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
isal_deflate_icf_body_lvl1(stream);
|
||||
}
|
||||
switch (stream->level) {
|
||||
case 3:
|
||||
isal_deflate_icf_body_lvl3(stream);
|
||||
break;
|
||||
case 2:
|
||||
isal_deflate_icf_body_lvl2(stream);
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
isal_deflate_icf_body_lvl1(stream);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -39,272 +39,270 @@
|
||||
/*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;
|
||||
uint8_t *comp_tmp = NULL, *uncomp_tmp = NULL;
|
||||
uint32_t comp_tmp_size = 0, uncomp_tmp_size = 0;
|
||||
uint32_t comp_processed = 0, uncomp_processed = 0;
|
||||
struct inflate_state *state = NULL;
|
||||
int ret = 0;
|
||||
uint8_t *comp_tmp = NULL, *uncomp_tmp = NULL;
|
||||
uint32_t comp_tmp_size = 0, uncomp_tmp_size = 0;
|
||||
uint32_t comp_processed = 0, uncomp_processed = 0;
|
||||
|
||||
state = malloc(sizeof(struct inflate_state));
|
||||
if (state == NULL) {
|
||||
printf("Failed to allocate memory\n");
|
||||
exit(0);
|
||||
}
|
||||
state = malloc(sizeof(struct inflate_state));
|
||||
if (state == NULL) {
|
||||
printf("Failed to allocate memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
isal_inflate_init(state);
|
||||
isal_inflate_init(state);
|
||||
|
||||
state->next_in = NULL;
|
||||
state->next_out = NULL;
|
||||
state->avail_in = 0;
|
||||
state->avail_out = 0;
|
||||
state->next_in = NULL;
|
||||
state->next_out = NULL;
|
||||
state->avail_in = 0;
|
||||
state->avail_out = 0;
|
||||
|
||||
while (1) {
|
||||
if (state->avail_in == 0) {
|
||||
comp_tmp_size = rand() % (compress_len + 1);
|
||||
while (1) {
|
||||
if (state->avail_in == 0) {
|
||||
comp_tmp_size = rand() % (compress_len + 1);
|
||||
|
||||
if (comp_tmp_size >= compress_len - comp_processed)
|
||||
comp_tmp_size = compress_len - comp_processed;
|
||||
if (comp_tmp_size >= compress_len - comp_processed)
|
||||
comp_tmp_size = compress_len - comp_processed;
|
||||
|
||||
if (comp_tmp_size != 0) {
|
||||
if (comp_tmp != NULL)
|
||||
free(comp_tmp);
|
||||
if (comp_tmp_size != 0) {
|
||||
if (comp_tmp != NULL)
|
||||
free(comp_tmp);
|
||||
|
||||
comp_tmp = malloc(comp_tmp_size);
|
||||
comp_tmp = malloc(comp_tmp_size);
|
||||
|
||||
if (comp_tmp == NULL) {
|
||||
printf("Failed to allocate memory\n");
|
||||
exit(0);
|
||||
}
|
||||
if (comp_tmp == NULL) {
|
||||
printf("Failed to allocate memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
memcpy(comp_tmp, compress_buf + comp_processed, comp_tmp_size);
|
||||
comp_processed += comp_tmp_size;
|
||||
memcpy(comp_tmp, compress_buf + comp_processed, comp_tmp_size);
|
||||
comp_processed += comp_tmp_size;
|
||||
|
||||
state->next_in = comp_tmp;
|
||||
state->avail_in = comp_tmp_size;
|
||||
}
|
||||
}
|
||||
state->next_in = comp_tmp;
|
||||
state->avail_in = comp_tmp_size;
|
||||
}
|
||||
}
|
||||
|
||||
if (state->avail_out == 0) {
|
||||
/* Save uncompressed data into uncompress_buf */
|
||||
if (uncomp_tmp != NULL) {
|
||||
memcpy(uncompress_buf + uncomp_processed, uncomp_tmp,
|
||||
uncomp_tmp_size);
|
||||
uncomp_processed += uncomp_tmp_size;
|
||||
}
|
||||
if (state->avail_out == 0) {
|
||||
/* Save uncompressed data into uncompress_buf */
|
||||
if (uncomp_tmp != NULL) {
|
||||
memcpy(uncompress_buf + uncomp_processed, uncomp_tmp,
|
||||
uncomp_tmp_size);
|
||||
uncomp_processed += uncomp_tmp_size;
|
||||
}
|
||||
|
||||
uncomp_tmp_size = rand() % (*uncompress_len + 1);
|
||||
uncomp_tmp_size = rand() % (*uncompress_len + 1);
|
||||
|
||||
/* Limit size of buffer to be smaller than maximum */
|
||||
if (uncomp_tmp_size > *uncompress_len - uncomp_processed)
|
||||
uncomp_tmp_size = *uncompress_len - uncomp_processed;
|
||||
/* Limit size of buffer to be smaller than maximum */
|
||||
if (uncomp_tmp_size > *uncompress_len - uncomp_processed)
|
||||
uncomp_tmp_size = *uncompress_len - uncomp_processed;
|
||||
|
||||
if (uncomp_tmp_size != 0) {
|
||||
if (uncomp_tmp_size != 0) {
|
||||
|
||||
if (uncomp_tmp != NULL) {
|
||||
fflush(0);
|
||||
free(uncomp_tmp);
|
||||
}
|
||||
if (uncomp_tmp != NULL) {
|
||||
fflush(0);
|
||||
free(uncomp_tmp);
|
||||
}
|
||||
|
||||
uncomp_tmp = malloc(uncomp_tmp_size);
|
||||
if (uncomp_tmp == NULL) {
|
||||
printf("Failed to allocate memory\n");
|
||||
exit(0);
|
||||
}
|
||||
uncomp_tmp = malloc(uncomp_tmp_size);
|
||||
if (uncomp_tmp == NULL) {
|
||||
printf("Failed to allocate memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
state->avail_out = uncomp_tmp_size;
|
||||
state->next_out = uncomp_tmp;
|
||||
}
|
||||
}
|
||||
state->avail_out = uncomp_tmp_size;
|
||||
state->next_out = uncomp_tmp;
|
||||
}
|
||||
}
|
||||
|
||||
ret = isal_inflate(state);
|
||||
ret = isal_inflate(state);
|
||||
|
||||
if (state->block_state == ISAL_BLOCK_FINISH || ret != 0) {
|
||||
memcpy(uncompress_buf + uncomp_processed, uncomp_tmp, uncomp_tmp_size);
|
||||
*uncompress_len = state->total_out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state->block_state == ISAL_BLOCK_FINISH || ret != 0) {
|
||||
memcpy(uncompress_buf + uncomp_processed, uncomp_tmp, uncomp_tmp_size);
|
||||
*uncompress_len = state->total_out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (comp_tmp != NULL) {
|
||||
free(comp_tmp);
|
||||
comp_tmp = NULL;
|
||||
}
|
||||
if (uncomp_tmp != NULL) {
|
||||
free(uncomp_tmp);
|
||||
uncomp_tmp = NULL;
|
||||
}
|
||||
if (comp_tmp != NULL) {
|
||||
free(comp_tmp);
|
||||
comp_tmp = NULL;
|
||||
}
|
||||
if (uncomp_tmp != NULL) {
|
||||
free(uncomp_tmp);
|
||||
uncomp_tmp = NULL;
|
||||
}
|
||||
|
||||
free(state);
|
||||
return ret;
|
||||
free(state);
|
||||
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);
|
||||
if (ret) {
|
||||
printf("Failed compressing input with exit code %d", ret);
|
||||
return ret;
|
||||
}
|
||||
int ret;
|
||||
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,
|
||||
uncompressed_test_stream, &uncompressed_test_stream_length);
|
||||
switch (ret) {
|
||||
case 0:
|
||||
break;
|
||||
case ISAL_END_INPUT:
|
||||
printf(" did not decompress all input\n");
|
||||
return ISAL_END_INPUT;
|
||||
break;
|
||||
case ISAL_INVALID_BLOCK:
|
||||
printf(" invalid header\n");
|
||||
return ISAL_INVALID_BLOCK;
|
||||
break;
|
||||
case ISAL_INVALID_SYMBOL:
|
||||
printf(" invalid symbol\n");
|
||||
return ISAL_INVALID_SYMBOL;
|
||||
break;
|
||||
case ISAL_OUT_OVERFLOW:
|
||||
printf(" out buffer overflow\n");
|
||||
return ISAL_OUT_OVERFLOW;
|
||||
break;
|
||||
case ISAL_INVALID_LOOKBACK:
|
||||
printf("Invalid lookback distance");
|
||||
return ISAL_INVALID_LOOKBACK;
|
||||
break;
|
||||
default:
|
||||
printf(" error\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
ret = inflate_multi_pass(compressed_stream + 2, *compressed_length - 2 - 4,
|
||||
uncompressed_test_stream, &uncompressed_test_stream_length);
|
||||
switch (ret) {
|
||||
case 0:
|
||||
break;
|
||||
case ISAL_END_INPUT:
|
||||
printf(" did not decompress all input\n");
|
||||
return ISAL_END_INPUT;
|
||||
break;
|
||||
case ISAL_INVALID_BLOCK:
|
||||
printf(" invalid header\n");
|
||||
return ISAL_INVALID_BLOCK;
|
||||
break;
|
||||
case ISAL_INVALID_SYMBOL:
|
||||
printf(" invalid symbol\n");
|
||||
return ISAL_INVALID_SYMBOL;
|
||||
break;
|
||||
case ISAL_OUT_OVERFLOW:
|
||||
printf(" out buffer overflow\n");
|
||||
return ISAL_OUT_OVERFLOW;
|
||||
break;
|
||||
case ISAL_INVALID_LOOKBACK:
|
||||
printf("Invalid lookback distance");
|
||||
return ISAL_INVALID_LOOKBACK;
|
||||
break;
|
||||
default:
|
||||
printf(" error\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
if (memcmp(uncompressed_stream, uncompressed_test_stream, uncompressed_length)) {
|
||||
int i;
|
||||
for (i = 0; i < uncompressed_length; i++) {
|
||||
if (uncompressed_stream[i] != uncompressed_test_stream[i]) {
|
||||
printf("first error at %d, 0x%x != 0x%x\n", i,
|
||||
uncompressed_stream[i], uncompressed_test_stream[i]);
|
||||
}
|
||||
}
|
||||
printf(" decompressed data is not the same as the compressed data\n");
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
if (memcmp(uncompressed_stream, uncompressed_test_stream, uncompressed_length)) {
|
||||
int i;
|
||||
for (i = 0; i < uncompressed_length; i++) {
|
||||
if (uncompressed_stream[i] != uncompressed_test_stream[i]) {
|
||||
printf("first error at %d, 0x%x != 0x%x\n", i,
|
||||
uncompressed_stream[i], uncompressed_test_stream[i]);
|
||||
}
|
||||
}
|
||||
printf(" decompressed data is not the same as the compressed data\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
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;
|
||||
uint64_t compressed_length, file_length;
|
||||
uint64_t uncompressed_length, uncompressed_test_stream_length;
|
||||
uint8_t *uncompressed_stream = NULL;
|
||||
uint8_t *compressed_stream = NULL;
|
||||
uint8_t *uncompressed_test_stream = NULL;
|
||||
int i, j, ret = 0, fin_ret = 0;
|
||||
FILE *file = NULL;
|
||||
uint64_t compressed_length, file_length;
|
||||
uint64_t uncompressed_length, uncompressed_test_stream_length;
|
||||
uint8_t *uncompressed_stream = NULL;
|
||||
uint8_t *compressed_stream = NULL;
|
||||
uint8_t *uncompressed_test_stream = NULL;
|
||||
|
||||
if (argc == 1)
|
||||
printf("Error, no input file\n");
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argc == 1)
|
||||
printf("Error, no input file\n");
|
||||
for (i = 1; i < argc; i++) {
|
||||
|
||||
file = NULL;
|
||||
uncompressed_stream = NULL;
|
||||
compressed_stream = NULL;
|
||||
uncompressed_test_stream = NULL;
|
||||
file = NULL;
|
||||
uncompressed_stream = NULL;
|
||||
compressed_stream = NULL;
|
||||
uncompressed_test_stream = NULL;
|
||||
|
||||
file = fopen(argv[i], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening file %s\n", argv[i]);
|
||||
return 1;
|
||||
} else
|
||||
printf("Starting file %s", argv[i]);
|
||||
fflush(0);
|
||||
file_length = get_filesize(file);
|
||||
if (file_length > MAX_INPUT_FILE_SIZE) {
|
||||
printf("\nFile too large to run on this test,"
|
||||
" Max 512MB for 32bit OS, 2GB for 64bit OS.\n");
|
||||
printf(" ... Fail\n");
|
||||
fclose(file);
|
||||
continue;
|
||||
}
|
||||
file = fopen(argv[i], "r");
|
||||
if (file == NULL) {
|
||||
printf("Error opening file %s\n", argv[i]);
|
||||
return 1;
|
||||
} else
|
||||
printf("Starting file %s", argv[i]);
|
||||
fflush(0);
|
||||
file_length = get_filesize(file);
|
||||
if (file_length > MAX_INPUT_FILE_SIZE) {
|
||||
printf("\nFile too large to run on this test,"
|
||||
" Max 512MB for 32bit OS, 2GB for 64bit OS.\n");
|
||||
printf(" ... Fail\n");
|
||||
fclose(file);
|
||||
continue;
|
||||
}
|
||||
|
||||
compressed_length = compressBound(file_length);
|
||||
compressed_length = compressBound(file_length);
|
||||
|
||||
if (file_length != 0) {
|
||||
uncompressed_stream = malloc(file_length);
|
||||
uncompressed_test_stream = malloc(file_length);
|
||||
}
|
||||
if (file_length != 0) {
|
||||
uncompressed_stream = malloc(file_length);
|
||||
uncompressed_test_stream = malloc(file_length);
|
||||
}
|
||||
|
||||
compressed_stream = malloc(compressed_length);
|
||||
if (uncompressed_stream == NULL && file_length != 0) {
|
||||
printf("\nFailed to allocate input memory\n");
|
||||
exit(0);
|
||||
}
|
||||
compressed_stream = malloc(compressed_length);
|
||||
if (uncompressed_stream == NULL && file_length != 0) {
|
||||
printf("\nFailed to allocate input memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (compressed_stream == NULL) {
|
||||
printf("\nFailed to allocate output memory\n");
|
||||
exit(0);
|
||||
}
|
||||
if (compressed_stream == NULL) {
|
||||
printf("\nFailed to allocate output memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (uncompressed_test_stream == NULL && file_length != 0) {
|
||||
printf("\nFailed to allocate decompressed memory\n");
|
||||
exit(0);
|
||||
}
|
||||
if (uncompressed_test_stream == NULL && file_length != 0) {
|
||||
printf("\nFailed to allocate decompressed memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
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,
|
||||
uncompressed_length, uncompressed_test_stream,
|
||||
uncompressed_test_stream_length);
|
||||
if (ret) {
|
||||
for (j = 0; j < compressed_length; j++) {
|
||||
if ((j & 31) == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
printf("0x%02x,", compressed_stream[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
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,
|
||||
uncompressed_length, uncompressed_test_stream,
|
||||
uncompressed_test_stream_length);
|
||||
if (ret) {
|
||||
for (j = 0; j < compressed_length; j++) {
|
||||
if ((j & 31) == 0)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
printf("0x%02x,", compressed_stream[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
fflush(0);
|
||||
fclose(file);
|
||||
if (compressed_stream != NULL)
|
||||
free(compressed_stream);
|
||||
if (uncompressed_stream != NULL)
|
||||
free(uncompressed_stream);
|
||||
if (uncompressed_test_stream != NULL)
|
||||
free(uncompressed_test_stream);
|
||||
if (ret) {
|
||||
printf(" ... Fail with exit code %d\n", ret);
|
||||
return ret;
|
||||
} else
|
||||
printf(" ... Pass\n");
|
||||
fin_ret |= ret;
|
||||
}
|
||||
return fin_ret;
|
||||
fflush(0);
|
||||
fclose(file);
|
||||
if (compressed_stream != NULL)
|
||||
free(compressed_stream);
|
||||
if (uncompressed_stream != NULL)
|
||||
free(uncompressed_stream);
|
||||
if (uncompressed_test_stream != NULL)
|
||||
free(uncompressed_test_stream);
|
||||
if (ret) {
|
||||
printf(" ... Fail with exit code %d\n", ret);
|
||||
return ret;
|
||||
} else
|
||||
printf(" ... Pass\n");
|
||||
fin_ret |= ret;
|
||||
}
|
||||
return fin_ret;
|
||||
}
|
||||
|
@ -8,41 +8,41 @@
|
||||
#define MATCH_BUF_SIZE (4 * 1024)
|
||||
|
||||
struct hash8k_buf {
|
||||
uint16_t hash_table[IGZIP_HASH8K_HASH_SIZE];
|
||||
uint16_t hash_table[IGZIP_HASH8K_HASH_SIZE];
|
||||
};
|
||||
|
||||
struct hash_hist_buf {
|
||||
uint16_t hash_table[IGZIP_HASH_HIST_SIZE];
|
||||
uint16_t hash_table[IGZIP_HASH_HIST_SIZE];
|
||||
};
|
||||
|
||||
struct hash_map_buf {
|
||||
uint16_t hash_table[IGZIP_HASH_MAP_HASH_SIZE];
|
||||
struct deflate_icf *matches_next;
|
||||
struct deflate_icf *matches_end;
|
||||
struct deflate_icf matches[MATCH_BUF_SIZE];
|
||||
struct deflate_icf overflow[ISAL_LOOK_AHEAD];
|
||||
uint16_t hash_table[IGZIP_HASH_MAP_HASH_SIZE];
|
||||
struct deflate_icf *matches_next;
|
||||
struct deflate_icf *matches_end;
|
||||
struct deflate_icf matches[MATCH_BUF_SIZE];
|
||||
struct deflate_icf overflow[ISAL_LOOK_AHEAD];
|
||||
};
|
||||
|
||||
#define MAX_LVL_BUF_SIZE sizeof(struct hash_map_buf)
|
||||
|
||||
struct level_buf {
|
||||
struct hufftables_icf encode_tables;
|
||||
struct isal_mod_hist hist;
|
||||
uint32_t deflate_hdr_count;
|
||||
uint32_t deflate_hdr_extra_bits;
|
||||
uint8_t deflate_hdr[ISAL_DEF_MAX_HDR_SIZE];
|
||||
struct deflate_icf *icf_buf_next;
|
||||
uint64_t icf_buf_avail_out;
|
||||
struct deflate_icf *icf_buf_start;
|
||||
union {
|
||||
struct hash8k_buf hash8k;
|
||||
struct hash_hist_buf hash_hist;
|
||||
struct hash_map_buf hash_map;
|
||||
struct hufftables_icf encode_tables;
|
||||
struct isal_mod_hist hist;
|
||||
uint32_t deflate_hdr_count;
|
||||
uint32_t deflate_hdr_extra_bits;
|
||||
uint8_t deflate_hdr[ISAL_DEF_MAX_HDR_SIZE];
|
||||
struct deflate_icf *icf_buf_next;
|
||||
uint64_t icf_buf_avail_out;
|
||||
struct deflate_icf *icf_buf_start;
|
||||
union {
|
||||
struct hash8k_buf hash8k;
|
||||
struct hash_hist_buf hash_hist;
|
||||
struct hash_map_buf hash_map;
|
||||
|
||||
struct hash8k_buf lvl1;
|
||||
struct hash_hist_buf lvl2;
|
||||
struct hash_map_buf lvl3;
|
||||
};
|
||||
struct hash8k_buf lvl1;
|
||||
struct hash_hist_buf lvl2;
|
||||
struct hash_map_buf lvl3;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
1379
igzip/igzip_perf.c
1379
igzip/igzip_perf.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -35,300 +35,303 @@
|
||||
#include "igzip_lib.h"
|
||||
#include "test.h"
|
||||
|
||||
#define MIN_BUF_SIZE (4 * 1024)
|
||||
#define MIN_TEST_LOOPS 10
|
||||
#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"
|
||||
" -h help\n"
|
||||
" -v (don't) validate output by inflate and compare\n"
|
||||
" -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);
|
||||
exit(0);
|
||||
fprintf(stderr,
|
||||
"Usage: igzip_semi_dynamic [options] <infile>\n"
|
||||
" -h help\n"
|
||||
" -v (don't) validate output by inflate and compare\n"
|
||||
" -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);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int str_to_i(char *s)
|
||||
int
|
||||
str_to_i(char *s)
|
||||
{
|
||||
#define ARG_MAX 32
|
||||
|
||||
int i = atoi(s);
|
||||
int len = strnlen(s, ARG_MAX);
|
||||
if (len < 2 || len == ARG_MAX)
|
||||
return i;
|
||||
int i = atoi(s);
|
||||
int len = strnlen(s, ARG_MAX);
|
||||
if (len < 2 || len == ARG_MAX)
|
||||
return i;
|
||||
|
||||
switch (s[len - 1]) {
|
||||
case 'k':
|
||||
i *= 1024;
|
||||
break;
|
||||
case 'K':
|
||||
i *= 1000;
|
||||
break;
|
||||
case 'm':
|
||||
i *= (1024 * 1024);
|
||||
break;
|
||||
case 'M':
|
||||
i *= (1000 * 1000);
|
||||
break;
|
||||
case 'g':
|
||||
i *= (1024 * 1024 * 1024);
|
||||
break;
|
||||
case 'G':
|
||||
i *= (1000 * 1000 * 1000);
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
switch (s[len - 1]) {
|
||||
case 'k':
|
||||
i *= 1024;
|
||||
break;
|
||||
case 'K':
|
||||
i *= 1000;
|
||||
break;
|
||||
case 'm':
|
||||
i *= (1024 * 1024);
|
||||
break;
|
||||
case 'M':
|
||||
i *= (1000 * 1000);
|
||||
break;
|
||||
case 'g':
|
||||
i *= (1024 * 1024 * 1024);
|
||||
break;
|
||||
case 'G':
|
||||
i *= (1000 * 1000 * 1000);
|
||||
break;
|
||||
}
|
||||
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;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_hufftables hufftable;
|
||||
|
||||
isal_deflate_stateless_init(stream);
|
||||
stream->end_of_stream = 0;
|
||||
stream->flush = FULL_FLUSH;
|
||||
stream->next_in = inbuf;
|
||||
stream->next_out = outbuf;
|
||||
int remaining = infile_size;
|
||||
int chunk_size = segment_size;
|
||||
isal_deflate_stateless_init(stream);
|
||||
stream->end_of_stream = 0;
|
||||
stream->flush = FULL_FLUSH;
|
||||
stream->next_in = inbuf;
|
||||
stream->next_out = outbuf;
|
||||
int remaining = infile_size;
|
||||
int chunk_size = segment_size;
|
||||
|
||||
while (remaining > 0) {
|
||||
// Generate custom hufftables on sample
|
||||
memset(&histogram, 0, sizeof(struct isal_huff_histogram));
|
||||
if (remaining < segment_size * 2) {
|
||||
chunk_size = remaining;
|
||||
stream->end_of_stream = 1;
|
||||
}
|
||||
int hist_rem = (hist_size > chunk_size) ? chunk_size : hist_size;
|
||||
isal_update_histogram(stream->next_in, hist_rem, &histogram);
|
||||
while (remaining > 0) {
|
||||
// Generate custom hufftables on sample
|
||||
memset(&histogram, 0, sizeof(struct isal_huff_histogram));
|
||||
if (remaining < segment_size * 2) {
|
||||
chunk_size = remaining;
|
||||
stream->end_of_stream = 1;
|
||||
}
|
||||
int hist_rem = (hist_size > chunk_size) ? chunk_size : hist_size;
|
||||
isal_update_histogram(stream->next_in, hist_rem, &histogram);
|
||||
|
||||
if (hist_rem == chunk_size)
|
||||
isal_create_hufftables_subset(&hufftable, &histogram);
|
||||
else
|
||||
isal_create_hufftables(&hufftable, &histogram);
|
||||
if (hist_rem == chunk_size)
|
||||
isal_create_hufftables_subset(&hufftable, &histogram);
|
||||
else
|
||||
isal_create_hufftables(&hufftable, &histogram);
|
||||
|
||||
// Compress with custom table
|
||||
stream->avail_in = chunk_size;
|
||||
stream->avail_out = chunk_size + 8 * (1 + (chunk_size >> 16));
|
||||
stream->hufftables = &hufftable;
|
||||
remaining -= chunk_size;
|
||||
isal_deflate_stateless(stream);
|
||||
if (stream->avail_in != 0)
|
||||
break;
|
||||
}
|
||||
// Compress with custom table
|
||||
stream->avail_in = chunk_size;
|
||||
stream->avail_out = chunk_size + 8 * (1 + (chunk_size >> 16));
|
||||
stream->hufftables = &hufftable;
|
||||
remaining -= chunk_size;
|
||||
isal_deflate_stateless(stream);
|
||||
if (stream->avail_in != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_hufftables hufftable;
|
||||
|
||||
isal_deflate_init(stream);
|
||||
stream->end_of_stream = 0;
|
||||
stream->flush = SYNC_FLUSH;
|
||||
stream->next_in = inbuf;
|
||||
stream->next_out = outbuf;
|
||||
stream->avail_out = outbuf_size;
|
||||
int remaining = infile_size;
|
||||
int chunk_size = segment_size;
|
||||
isal_deflate_init(stream);
|
||||
stream->end_of_stream = 0;
|
||||
stream->flush = SYNC_FLUSH;
|
||||
stream->next_in = inbuf;
|
||||
stream->next_out = outbuf;
|
||||
stream->avail_out = outbuf_size;
|
||||
int remaining = infile_size;
|
||||
int chunk_size = segment_size;
|
||||
|
||||
while (remaining > 0) {
|
||||
// Generate custom hufftables on sample
|
||||
memset(&histogram, 0, sizeof(struct isal_huff_histogram));
|
||||
if (remaining < segment_size * 2) {
|
||||
chunk_size = remaining;
|
||||
stream->end_of_stream = 1;
|
||||
}
|
||||
int hist_rem = (hist_size > chunk_size) ? chunk_size : hist_size;
|
||||
isal_update_histogram(stream->next_in, hist_rem, &histogram);
|
||||
while (remaining > 0) {
|
||||
// Generate custom hufftables on sample
|
||||
memset(&histogram, 0, sizeof(struct isal_huff_histogram));
|
||||
if (remaining < segment_size * 2) {
|
||||
chunk_size = remaining;
|
||||
stream->end_of_stream = 1;
|
||||
}
|
||||
int hist_rem = (hist_size > chunk_size) ? chunk_size : hist_size;
|
||||
isal_update_histogram(stream->next_in, hist_rem, &histogram);
|
||||
|
||||
if (hist_rem == chunk_size)
|
||||
isal_create_hufftables_subset(&hufftable, &histogram);
|
||||
else
|
||||
isal_create_hufftables(&hufftable, &histogram);
|
||||
if (hist_rem == chunk_size)
|
||||
isal_create_hufftables_subset(&hufftable, &histogram);
|
||||
else
|
||||
isal_create_hufftables(&hufftable, &histogram);
|
||||
|
||||
// Compress with custom table
|
||||
stream->avail_in = chunk_size;
|
||||
stream->hufftables = &hufftable;
|
||||
remaining -= chunk_size;
|
||||
isal_deflate(stream);
|
||||
if (stream->internal_state.state != ZSTATE_NEW_HDR)
|
||||
break;
|
||||
}
|
||||
// Compress with custom table
|
||||
stream->avail_in = chunk_size;
|
||||
stream->hufftables = &hufftable;
|
||||
remaining -= chunk_size;
|
||||
isal_deflate(stream);
|
||||
if (stream->internal_state.state != ZSTATE_NEW_HDR)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in = stdin, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf;
|
||||
int i = 0, c;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
int segment_size = DEFAULT_SEG_SIZE;
|
||||
int sample_size = DEFAULT_SAMPLE_SIZE;
|
||||
int check_output = 1;
|
||||
int do_stateless = 0, do_stateful = 1;
|
||||
int ret = 0;
|
||||
char *out_file_name = NULL;
|
||||
struct isal_zstream stream;
|
||||
FILE *in = stdin, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf;
|
||||
int i = 0, c;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
int segment_size = DEFAULT_SEG_SIZE;
|
||||
int sample_size = DEFAULT_SAMPLE_SIZE;
|
||||
int check_output = 1;
|
||||
int do_stateless = 0, do_stateful = 1;
|
||||
int ret = 0;
|
||||
char *out_file_name = NULL;
|
||||
struct isal_zstream stream;
|
||||
|
||||
while ((c = getopt(argc, argv, "vht:c:s:o:")) != -1) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
check_output ^= 1;
|
||||
break;
|
||||
case 't':
|
||||
if (atoi(optarg) == 1) {
|
||||
do_stateful = 0;
|
||||
do_stateless = 1;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
segment_size = str_to_i(optarg);
|
||||
break;
|
||||
case 's':
|
||||
sample_size = str_to_i(optarg);
|
||||
break;
|
||||
case 'o':
|
||||
out_file_name = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ((c = getopt(argc, argv, "vht:c:s:o:")) != -1) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
check_output ^= 1;
|
||||
break;
|
||||
case 't':
|
||||
if (atoi(optarg) == 1) {
|
||||
do_stateful = 0;
|
||||
do_stateless = 1;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
segment_size = str_to_i(optarg);
|
||||
break;
|
||||
case 's':
|
||||
sample_size = str_to_i(optarg);
|
||||
break;
|
||||
case 'o':
|
||||
out_file_name = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Open input file
|
||||
if (optind < argc) {
|
||||
if (!(in = fopen(argv[optind], "rb"))) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[optind]);
|
||||
exit(1);
|
||||
}
|
||||
} else
|
||||
usage();
|
||||
// Open input file
|
||||
if (optind < argc) {
|
||||
if (!(in = fopen(argv[optind], "rb"))) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[optind]);
|
||||
exit(1);
|
||||
}
|
||||
} else
|
||||
usage();
|
||||
|
||||
// Optionally open output file
|
||||
if (out_file_name != NULL) {
|
||||
if (!(out = fopen(out_file_name, "wb"))) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", out_file_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
// Optionally open output file
|
||||
if (out_file_name != NULL) {
|
||||
if (!(out = fopen(out_file_name, "wb"))) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", out_file_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
|
||||
/*
|
||||
* Allocate space for entire input file and output
|
||||
* (assuming some possible expansion on output size)
|
||||
*/
|
||||
infile_size = get_filesize(in);
|
||||
if (infile_size == 0) {
|
||||
printf("Input file has zero length\n");
|
||||
usage();
|
||||
}
|
||||
/*
|
||||
* Allocate space for entire input file and output
|
||||
* (assuming some possible expansion on output size)
|
||||
*/
|
||||
infile_size = get_filesize(in);
|
||||
if (infile_size == 0) {
|
||||
printf("Input file has zero length\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
outbuf_size = infile_size * 1.30 > MIN_BUF_SIZE ? infile_size * 1.30 : MIN_BUF_SIZE;
|
||||
outbuf_size = infile_size * 1.30 > MIN_BUF_SIZE ? infile_size * 1.30 : MIN_BUF_SIZE;
|
||||
|
||||
if (NULL == (inbuf = malloc(infile_size))) {
|
||||
fprintf(stderr, "Can't allocate input buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
if (NULL == (outbuf = malloc(outbuf_size))) {
|
||||
fprintf(stderr, "Can't allocate output buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
if (NULL == (inbuf = malloc(infile_size))) {
|
||||
fprintf(stderr, "Can't allocate input buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
if (NULL == (outbuf = malloc(outbuf_size))) {
|
||||
fprintf(stderr, "Can't allocate output buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int hist_size = sample_size > segment_size ? segment_size : sample_size;
|
||||
int hist_size = sample_size > segment_size ? segment_size : sample_size;
|
||||
|
||||
printf("semi-dynamic sample=%d segment=%d %s\n", hist_size, segment_size,
|
||||
do_stateful ? "stateful" : "stateless");
|
||||
printf("igzip_file_perf: %s\n", argv[optind]);
|
||||
printf("semi-dynamic sample=%d segment=%d %s\n", hist_size, segment_size,
|
||||
do_stateful ? "stateful" : "stateless");
|
||||
printf("igzip_file_perf: %s\n", argv[optind]);
|
||||
|
||||
// Read complete input file into buffer
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in);
|
||||
if (stream.avail_in != infile_size) {
|
||||
fprintf(stderr, "Couldn't fit all of input file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
// Read complete input file into buffer
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in);
|
||||
if (stream.avail_in != infile_size) {
|
||||
fprintf(stderr, "Couldn't fit all of input file into buffer\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
struct perf start;
|
||||
struct perf start;
|
||||
|
||||
if (do_stateful) {
|
||||
BENCHMARK(&start, BENCHMARK_TIME,
|
||||
semi_dyn_stateful_perf(&stream, inbuf, infile_size, outbuf,
|
||||
outbuf_size, segment_size, hist_size)
|
||||
);
|
||||
}
|
||||
if (do_stateful) {
|
||||
BENCHMARK(&start, BENCHMARK_TIME,
|
||||
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));
|
||||
}
|
||||
if (do_stateless) {
|
||||
BENCHMARK(&start, BENCHMARK_TIME,
|
||||
semi_dyn_stateless_perf(&stream, inbuf, infile_size, outbuf, outbuf_size,
|
||||
segment_size, hist_size));
|
||||
}
|
||||
|
||||
if (stream.avail_in != 0) {
|
||||
printf("Could not compress all of inbuf\n");
|
||||
ret = 1;
|
||||
}
|
||||
if (stream.avail_in != 0) {
|
||||
printf("Could not compress all of inbuf\n");
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%\n", argv[optind],
|
||||
infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%\n", argv[optind],
|
||||
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);
|
||||
printf("igzip_semi_dyn_file: ");
|
||||
perf_print(start, (long long) infile_size);
|
||||
|
||||
if (out != NULL) {
|
||||
printf("writing %s\n", out_file_name);
|
||||
fwrite(outbuf, 1, stream.total_out, out);
|
||||
fclose(out);
|
||||
}
|
||||
if (out != NULL) {
|
||||
printf("writing %s\n", out_file_name);
|
||||
fwrite(outbuf, 1, stream.total_out, out);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(in);
|
||||
|
||||
if (check_output) {
|
||||
unsigned char *inflate_buf;
|
||||
struct inflate_state istate;
|
||||
if (check_output) {
|
||||
unsigned char *inflate_buf;
|
||||
struct inflate_state istate;
|
||||
|
||||
if (NULL == (inflate_buf = malloc(infile_size))) {
|
||||
fprintf(stderr, "Can't allocate reconstruct buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
isal_inflate_init(&istate);
|
||||
istate.next_in = outbuf;
|
||||
istate.avail_in = stream.total_out;
|
||||
istate.next_out = inflate_buf;
|
||||
istate.avail_out = infile_size;
|
||||
int check = isal_inflate(&istate);
|
||||
if (NULL == (inflate_buf = malloc(infile_size))) {
|
||||
fprintf(stderr, "Can't allocate reconstruct buffer memory\n");
|
||||
exit(0);
|
||||
}
|
||||
isal_inflate_init(&istate);
|
||||
istate.next_in = outbuf;
|
||||
istate.avail_in = stream.total_out;
|
||||
istate.next_out = inflate_buf;
|
||||
istate.avail_out = infile_size;
|
||||
int check = isal_inflate(&istate);
|
||||
|
||||
if (memcmp(inflate_buf, inbuf, infile_size)) {
|
||||
printf("inflate check Fail\n");
|
||||
printf(" ret %d total_inflate=%d\n", check, istate.total_out);
|
||||
for (i = 0; i < infile_size; i++) {
|
||||
if (inbuf[i] != inflate_buf[i]) {
|
||||
printf(" first diff at offset=%d\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
} else
|
||||
printf("inflate check Pass\n");
|
||||
free(inflate_buf);
|
||||
}
|
||||
if (memcmp(inflate_buf, inbuf, infile_size)) {
|
||||
printf("inflate check Fail\n");
|
||||
printf(" ret %d total_inflate=%d\n", check, istate.total_out);
|
||||
for (i = 0; i < infile_size; i++) {
|
||||
if (inbuf[i] != inflate_buf[i]) {
|
||||
printf(" first diff at offset=%d\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
} else
|
||||
printf("inflate check Pass\n");
|
||||
free(inflate_buf);
|
||||
}
|
||||
|
||||
printf("End of igzip_semi_dyn_file_perf\n\n");
|
||||
return ret;
|
||||
printf("End of igzip_semi_dyn_file_perf\n\n");
|
||||
return ret;
|
||||
}
|
||||
|
@ -36,51 +36,52 @@
|
||||
|
||||
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;
|
||||
uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE];
|
||||
FILE *in, *out;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: igzip_sync_flush_example infile outfile\n");
|
||||
exit(0);
|
||||
}
|
||||
in = fopen(argv[1], "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
out = fopen(argv[2], "wb");
|
||||
if (!out) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", argv[2]);
|
||||
exit(0);
|
||||
}
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: igzip_sync_flush_example infile outfile\n");
|
||||
exit(0);
|
||||
}
|
||||
in = fopen(argv[1], "rb");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
|
||||
exit(0);
|
||||
}
|
||||
out = fopen(argv[2], "wb");
|
||||
if (!out) {
|
||||
fprintf(stderr, "Can't open %s for writing\n", argv[2]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("igzip_sync_flush_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
fflush(0);
|
||||
printf("igzip_sync_flush_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024);
|
||||
fflush(0);
|
||||
|
||||
isal_deflate_init(&stream);
|
||||
stream.end_of_stream = 0;
|
||||
stream.flush = SYNC_FLUSH;
|
||||
isal_deflate_init(&stream);
|
||||
stream.end_of_stream = 0;
|
||||
stream.flush = SYNC_FLUSH;
|
||||
|
||||
do {
|
||||
if (stream.internal_state.state == ZSTATE_NEW_HDR) {
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, BUF_SIZE, in);
|
||||
stream.end_of_stream = feof(in) ? 1 : 0;
|
||||
stream.next_in = inbuf;
|
||||
}
|
||||
do {
|
||||
stream.avail_out = BUF_SIZE;
|
||||
stream.next_out = outbuf;
|
||||
isal_deflate(&stream);
|
||||
fwrite(outbuf, 1, BUF_SIZE - stream.avail_out, out);
|
||||
} while (stream.avail_out == 0);
|
||||
do {
|
||||
if (stream.internal_state.state == ZSTATE_NEW_HDR) {
|
||||
stream.avail_in = (uint32_t) fread(inbuf, 1, BUF_SIZE, in);
|
||||
stream.end_of_stream = feof(in) ? 1 : 0;
|
||||
stream.next_in = inbuf;
|
||||
}
|
||||
do {
|
||||
stream.avail_out = BUF_SIZE;
|
||||
stream.next_out = outbuf;
|
||||
isal_deflate(&stream);
|
||||
fwrite(outbuf, 1, BUF_SIZE - stream.avail_out, out);
|
||||
} while (stream.avail_out == 0);
|
||||
|
||||
} while (stream.internal_state.state != ZSTATE_END);
|
||||
} while (stream.internal_state.state != ZSTATE_END);
|
||||
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
|
||||
printf("End of igzip_sync_flush_example\n\n");
|
||||
return 0;
|
||||
printf("End of igzip_sync_flush_example\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,22 +31,22 @@
|
||||
|
||||
#define DEFLATE_METHOD 8
|
||||
#define ZLIB_DICT_FLAG (1 << 5)
|
||||
#define TEXT_FLAG (1 << 0)
|
||||
#define HCRC_FLAG (1 << 1)
|
||||
#define EXTRA_FLAG (1 << 2)
|
||||
#define NAME_FLAG (1 << 3)
|
||||
#define COMMENT_FLAG (1 << 4)
|
||||
#define TEXT_FLAG (1 << 0)
|
||||
#define HCRC_FLAG (1 << 1)
|
||||
#define EXTRA_FLAG (1 << 2)
|
||||
#define NAME_FLAG (1 << 3)
|
||||
#define COMMENT_FLAG (1 << 4)
|
||||
#define UNDEFINED_FLAG (-1)
|
||||
|
||||
#define GZIP_HDR_BASE 10
|
||||
#define GZIP_EXTRA_LEN 2
|
||||
#define GZIP_HCRC_LEN 2
|
||||
#define GZIP_HDR_BASE 10
|
||||
#define GZIP_EXTRA_LEN 2
|
||||
#define GZIP_HCRC_LEN 2
|
||||
#define GZIP_TRAILER_LEN 8
|
||||
|
||||
#define ZLIB_HDR_BASE 2
|
||||
#define ZLIB_DICT_LEN 4
|
||||
#define ZLIB_INFO_OFFSET 4
|
||||
#define ZLIB_HDR_BASE 2
|
||||
#define ZLIB_DICT_LEN 4
|
||||
#define ZLIB_INFO_OFFSET 4
|
||||
#define ZLIB_LEVEL_OFFSET 6
|
||||
#define ZLIB_TRAILER_LEN 4
|
||||
#define ZLIB_TRAILER_LEN 4
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -31,55 +31,56 @@
|
||||
#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) {
|
||||
child = (heap[child] <= heap[child + 1]) ? child : child + 1;
|
||||
uint64_t child = 2 * index, tmp;
|
||||
while (child <= heap_size) {
|
||||
child = (heap[child] <= heap[child + 1]) ? child : child + 1;
|
||||
|
||||
if (heap[index] > heap[child]) {
|
||||
tmp = heap[index];
|
||||
heap[index] = heap[child];
|
||||
heap[child] = tmp;
|
||||
index = child;
|
||||
child = 2 * index;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (heap[index] > heap[child]) {
|
||||
tmp = heap[index];
|
||||
heap[index] = heap[child];
|
||||
heap[child] = tmp;
|
||||
index = child;
|
||||
child = 2 * index;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
uint64_t *heap = (uint64_t *) heap_space;
|
||||
uint64_t h1, h2;
|
||||
|
||||
while (heap_size > 1) {
|
||||
h1 = heap[1];
|
||||
heap[1] = heap[heap_size];
|
||||
heap[heap_size--] = -1;
|
||||
while (heap_size > 1) {
|
||||
h1 = heap[1];
|
||||
heap[1] = heap[heap_size];
|
||||
heap[heap_size--] = -1;
|
||||
|
||||
heapify(heap, heap_size, 1);
|
||||
heapify(heap, heap_size, 1);
|
||||
|
||||
h2 = heap[1];
|
||||
heap[1] = ((h1 + h2) & ~0xFFFFull) | node_ptr;
|
||||
h2 = heap[1];
|
||||
heap[1] = ((h1 + h2) & ~0xFFFFull) | node_ptr;
|
||||
|
||||
heapify(heap, heap_size, 1);
|
||||
heapify(heap, heap_size, 1);
|
||||
|
||||
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);
|
||||
return node_ptr;
|
||||
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);
|
||||
return node_ptr;
|
||||
}
|
||||
|
@ -30,25 +30,25 @@
|
||||
#define _IGZIP_REPEATED_8K_CHAR_RESULT_H_
|
||||
|
||||
/* The code for the literal being encoded */
|
||||
#define CODE_LIT 0x1
|
||||
#define CODE_LIT 0x1
|
||||
#define CODE_LIT_LENGTH 0x2
|
||||
|
||||
/* The code for repeat 10. The Length includes the distance code length*/
|
||||
#define CODE_10 0x3
|
||||
#define CODE_10_LENGTH 0x4
|
||||
#define CODE_10 0x3
|
||||
#define CODE_10_LENGTH 0x4
|
||||
|
||||
/* The code for repeat 115-130. The Length includes the distance code length*/
|
||||
#define CODE_280 0x0f
|
||||
#define CODE_280_LENGTH 0x4
|
||||
#define CODE_280 0x0f
|
||||
#define CODE_280_LENGTH 0x4
|
||||
#define CODE_280_TOTAL_LENGTH CODE_280_LENGTH + 4 + 1
|
||||
|
||||
/* Code representing the end of block. */
|
||||
#define END_OF_BLOCK 0x7
|
||||
#define END_OF_BLOCK 0x7
|
||||
#define END_OF_BLOCK_LEN 0x4
|
||||
|
||||
/* 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
Loading…
Reference in New Issue
Block a user