mirror of
				https://github.com/intel/isa-l.git
				synced 2025-10-29 20:59:43 +01:00 
			
		
		
		
	igzip: reformat using new code style
Signed-off-by: Marcel Cornu <marcel.d.cornu@intel.com>
This commit is contained in:
		 Marcel Cornu
					Marcel Cornu
				
			
				
					committed by
					
						 Pablo de Lara
						Pablo de Lara
					
				
			
			
				
	
			
			
			 Pablo de Lara
						Pablo de Lara
					
				
			
						parent
						
							9d99f8215d
						
					
				
				
					commit
					55fbfabfc6
				
			| @@ -38,7 +38,6 @@ DEFINE_INTERFACE_DISPATCHER(isal_adler32) | |||||||
|         return PROVIDER_INFO(adler32_neon); |         return PROVIDER_INFO(adler32_neon); | ||||||
| #endif | #endif | ||||||
|         return PROVIDER_BASIC(adler32); |         return PROVIDER_BASIC(adler32); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| DEFINE_INTERFACE_DISPATCHER(isal_deflate_body) | DEFINE_INTERFACE_DISPATCHER(isal_deflate_body) | ||||||
| @@ -53,7 +52,6 @@ DEFINE_INTERFACE_DISPATCHER(isal_deflate_body) | |||||||
|                 return PROVIDER_INFO(isal_deflate_body_aarch64); |                 return PROVIDER_INFO(isal_deflate_body_aarch64); | ||||||
| #endif | #endif | ||||||
|         return PROVIDER_BASIC(isal_deflate_body); |         return PROVIDER_BASIC(isal_deflate_body); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| DEFINE_INTERFACE_DISPATCHER(isal_deflate_finish) | DEFINE_INTERFACE_DISPATCHER(isal_deflate_finish) | ||||||
| @@ -67,7 +65,6 @@ DEFINE_INTERFACE_DISPATCHER(isal_deflate_finish) | |||||||
|                 return PROVIDER_INFO(isal_deflate_finish_aarch64); |                 return PROVIDER_INFO(isal_deflate_finish_aarch64); | ||||||
| #endif | #endif | ||||||
|         return PROVIDER_BASIC(isal_deflate_finish); |         return PROVIDER_BASIC(isal_deflate_finish); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_body_lvl1) | DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_body_lvl1) | ||||||
| @@ -148,10 +145,7 @@ DEFINE_INTERFACE_DISPATCHER(isal_deflate_icf_finish_lvl3) | |||||||
|         return PROVIDER_BASIC(isal_deflate_icf_finish_hash_map); |         return PROVIDER_BASIC(isal_deflate_icf_finish_hash_map); | ||||||
| } | } | ||||||
|  |  | ||||||
| DEFINE_INTERFACE_DISPATCHER(set_long_icf_fg) | DEFINE_INTERFACE_DISPATCHER(set_long_icf_fg) { return PROVIDER_INFO(set_long_icf_fg_aarch64); } | ||||||
| { |  | ||||||
| 	return PROVIDER_INFO(set_long_icf_fg_aarch64); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| DEFINE_INTERFACE_DISPATCHER(encode_deflate_icf) | DEFINE_INTERFACE_DISPATCHER(encode_deflate_icf) | ||||||
| { | { | ||||||
|   | |||||||
| @@ -30,7 +30,8 @@ | |||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| #include "igzip_checksums.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; |         uint8_t *end, *next = start; | ||||||
|         uint64_t A, B; |         uint64_t A, B; | ||||||
|   | |||||||
| @@ -52,7 +52,8 @@ | |||||||
| #define TEST_SEED 0x1234 | #define TEST_SEED 0x1234 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         void *buf; |         void *buf; | ||||||
|         uint32_t checksum = 0; |         uint32_t checksum = 0; | ||||||
|   | |||||||
| @@ -41,40 +41,47 @@ | |||||||
|  * state that is possible at the exit of write_bits */ |  * state that is possible at the exit of write_bits */ | ||||||
| #define MAX_BITBUF_BIT_WRITE 56 | #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_bits = 0; | ||||||
|         me->m_bit_count = 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; |         unsigned int slop = 8; | ||||||
|         me->m_out_buf = me->m_out_start = buf; |         me->m_out_buf = me->m_out_start = buf; | ||||||
|         me->m_out_end = buf + len - slop; |         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; |         uint32_t bits; | ||||||
|         store_le_u64(me->m_out_buf, me->m_bits); |         store_le_u64(me->m_out_buf, me->m_bits); | ||||||
| @@ -82,11 +89,11 @@ static inline void flush_bits(struct BitBuf2 *me) | |||||||
|         me->m_bit_count -= bits; |         me->m_bit_count -= bits; | ||||||
|         me->m_out_buf += bits / 8; |         me->m_out_buf += bits / 8; | ||||||
|         me->m_bits >>= bits; |         me->m_bits >>= bits; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Can write up to 8 bytes to output buffer */ | /* 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; |         uint32_t bytes; | ||||||
|         if (me->m_bit_count) { |         if (me->m_bit_count) { | ||||||
| @@ -98,7 +105,8 @@ static inline void flush(struct BitBuf2 *me) | |||||||
|         me->m_bit_count = 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 |         /* Checks if bitbuf has num_bits extra space and flushes the bytes in | ||||||
|          * the bitbuf if it doesn't. */ |          * the bitbuf if it doesn't. */ | ||||||
| @@ -106,20 +114,23 @@ static inline void check_space(struct BitBuf2 *me, uint32_t num_bits) | |||||||
|                 flush_bits(me); |                 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_bits |= code << me->m_bit_count; | ||||||
|         me->m_bit_count += count; |         me->m_bit_count += count; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count) | static inline void | ||||||
|  | write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count) | ||||||
| { /* Assumes there is space to fit code into m_bits. */ | { /* Assumes there is space to fit code into m_bits. */ | ||||||
|         me->m_bits |= code << me->m_bit_count; |         me->m_bits |= code << me->m_bit_count; | ||||||
|         me->m_bit_count += count; |         me->m_bit_count += count; | ||||||
|         flush_bits(me); |         flush_bits(me); | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count) | static inline void | ||||||
|  | write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count) | ||||||
| { /* Assumes there is space to fit code into m_bits. */ | { /* Assumes there is space to fit code into m_bits. */ | ||||||
|         me->m_bits |= code << me->m_bit_count; |         me->m_bits |= code << me->m_bit_count; | ||||||
|         me->m_bit_count += count; |         me->m_bit_count += count; | ||||||
|   | |||||||
| @@ -56,7 +56,8 @@ func_case_t test_funcs[] = { | |||||||
|  |  | ||||||
| // Generates pseudo-random data | // Generates pseudo-random data | ||||||
|  |  | ||||||
| void rand_buffer(unsigned char *buf, long buffer_size) | void | ||||||
|  | rand_buffer(unsigned char *buf, long buffer_size) | ||||||
| { | { | ||||||
|         long i; |         long i; | ||||||
|         for (i = 0; i < buffer_size; i++) |         for (i = 0; i < buffer_size; i++) | ||||||
| @@ -64,16 +65,23 @@ void rand_buffer(unsigned char *buf, long buffer_size) | |||||||
| } | } | ||||||
|  |  | ||||||
| // Test cases | // Test cases | ||||||
| int zeros_test(func_case_t * test_func); | int | ||||||
| int simple_pattern_test(func_case_t * test_func); | zeros_test(func_case_t *test_func); | ||||||
| int seeds_sizes_test(func_case_t * test_func); | int | ||||||
| int eob_test(func_case_t * test_func); | simple_pattern_test(func_case_t *test_func); | ||||||
| int update_test(func_case_t * test_func); | int | ||||||
| int update_over_mod_test(func_case_t * test_func); | 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; | void *buf_alloc = NULL; | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         int fail = 0, fail_case; |         int fail = 0, fail_case; | ||||||
|         int i, ret; |         int i, ret; | ||||||
| @@ -115,7 +123,8 @@ int main(int argc, char *argv[]) | |||||||
| } | } | ||||||
|  |  | ||||||
| // Test of all zeros | // 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; |         uint32_t c_dut, c_ref; | ||||||
|         int fail = 0; |         int fail = 0; | ||||||
| @@ -141,7 +150,8 @@ int zeros_test(func_case_t * test_func) | |||||||
| } | } | ||||||
|  |  | ||||||
| // Another simple test pattern | // 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; |         uint32_t c_dut, c_ref; | ||||||
|         int fail = 0; |         int fail = 0; | ||||||
| @@ -163,7 +173,8 @@ int simple_pattern_test(func_case_t * test_func) | |||||||
|         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; |         uint32_t c_dut, c_ref; | ||||||
|         int fail = 0; |         int fail = 0; | ||||||
| @@ -223,8 +234,7 @@ int seeds_sizes_test(func_case_t * test_func) | |||||||
|                         c_ref = test_func->checksum32_ref_call(r, buf, MAX_BUF); |                         c_ref = test_func->checksum32_ref_call(r, buf, MAX_BUF); | ||||||
|                         if (c_dut != c_ref) { |                         if (c_dut != c_ref) { | ||||||
|                                 fail++; |                                 fail++; | ||||||
| 				printf("fail checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, |                                 printf("fail checksum rand%3d = 0x%8x 0x%8x\n", i, c_dut, c_ref); | ||||||
| 				       c_ref); |  | ||||||
|                         } |                         } | ||||||
| #ifdef TEST_VERBOSE | #ifdef TEST_VERBOSE | ||||||
|                         else |                         else | ||||||
| @@ -238,7 +248,8 @@ int seeds_sizes_test(func_case_t * test_func) | |||||||
| } | } | ||||||
|  |  | ||||||
| // Run tests at end of buffer | // 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; |         uint32_t c_dut, c_ref; | ||||||
|         int fail = 0; |         int fail = 0; | ||||||
| @@ -263,7 +274,8 @@ int eob_test(func_case_t * test_func) | |||||||
|         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; |         uint32_t c_dut, c_ref; | ||||||
|         int fail = 0; |         int fail = 0; | ||||||
| @@ -295,7 +307,8 @@ int update_test(func_case_t * test_func) | |||||||
|         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; |         uint32_t c_dut, c_ref; | ||||||
|         int fail = 0; |         int fail = 0; | ||||||
|   | |||||||
| @@ -8,73 +8,47 @@ | |||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|  |  | ||||||
| uint32_t inflate_crc_table[256] = { | uint32_t inflate_crc_table[256] = { | ||||||
| 	0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |         0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, | ||||||
| 	0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |         0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, | ||||||
| 	0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |         0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, | ||||||
| 	0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |         0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, | ||||||
| 	0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |         0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | ||||||
| 	0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |         0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, | ||||||
| 	0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |         0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, | ||||||
| 	0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |         0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, | ||||||
| 	0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |         0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, | ||||||
| 	0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |         0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | ||||||
| 	0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |         0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, | ||||||
| 	0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |         0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, | ||||||
| 	0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |         0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, | ||||||
| 	0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |         0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, | ||||||
| 	0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |         0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | ||||||
| 	0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |         0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, | ||||||
| 	0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |         0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, | ||||||
| 	0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |         0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, | ||||||
| 	0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |         0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, | ||||||
| 	0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |         0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | ||||||
| 	0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |         0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, | ||||||
| 	0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |         0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, | ||||||
| 	0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |         0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, | ||||||
| 	0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |         0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, | ||||||
| 	0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |         0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | ||||||
| 	0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |         0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, | ||||||
| 	0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |         0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, | ||||||
| 	0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |         0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, | ||||||
| 	0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |         0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, | ||||||
| 	0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |         0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | ||||||
| 	0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |         0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, | ||||||
| 	0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |         0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, | ||||||
| 	0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |         0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, | ||||||
| 	0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |         0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, | ||||||
| 	0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |         0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | ||||||
| 	0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |         0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, | ||||||
| 	0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |         0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d | ||||||
| 	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 | ||||||
| uint32_t crc32_gzip_refl_ref(uint32_t crc, const unsigned char *buf, uint64_t len) | crc32_gzip_refl_ref(uint32_t crc, const unsigned char *buf, uint64_t len) | ||||||
| { | { | ||||||
|         uint64_t i; |         uint64_t i; | ||||||
|         crc = ~crc; |         crc = ~crc; | ||||||
| @@ -85,8 +59,8 @@ uint32_t crc32_gzip_refl_ref(uint32_t crc, const unsigned char *buf, uint64_t le | |||||||
|  |  | ||||||
| #define ADLER_MOD 65521 | #define ADLER_MOD 65521 | ||||||
|  |  | ||||||
|  | uint32_t | ||||||
| uint32_t adler_ref(uint32_t init, const unsigned char *buf, uint64_t len) | adler_ref(uint32_t init, const unsigned char *buf, uint64_t len) | ||||||
| { | { | ||||||
|         uint64_t i; |         uint64_t i; | ||||||
|         uint32_t a = init & 0xffff; |         uint32_t a = init & 0xffff; | ||||||
|   | |||||||
| @@ -15,8 +15,8 @@ | |||||||
| #include "encode_df.h" | #include "encode_df.h" | ||||||
| #include "bitbuf2.h" | #include "bitbuf2.h" | ||||||
|  |  | ||||||
| struct deflate_icf *encode_deflate_icf_base(struct deflate_icf *next_in, | struct deflate_icf * | ||||||
| 					    struct deflate_icf *end_in, struct BitBuf2 *bb, | encode_deflate_icf_base(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb, | ||||||
|                         struct hufftables_icf *hufftables) |                         struct hufftables_icf *hufftables) | ||||||
| { | { | ||||||
|         struct huff_code lsym, dsym; |         struct huff_code lsym, dsym; | ||||||
|   | |||||||
| @@ -31,6 +31,7 @@ struct deflate_icf { | |||||||
| #endif | #endif | ||||||
| }; | }; | ||||||
|  |  | ||||||
| struct deflate_icf *encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in, | struct deflate_icf * | ||||||
| 				       struct BitBuf2 *bb, struct hufftables_icf *hufftables); | encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb, | ||||||
|  |                    struct hufftables_icf *hufftables); | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -4,7 +4,8 @@ | |||||||
|  |  | ||||||
| #include "flatten_ll.h" | #include "flatten_ll.h" | ||||||
|  |  | ||||||
| void flatten_ll(uint32_t * ll_hist) | void | ||||||
|  | flatten_ll(uint32_t *ll_hist) | ||||||
| { | { | ||||||
|         uint32_t i, j; |         uint32_t i, j; | ||||||
|         uint32_t *s = ll_hist, x, *p; |         uint32_t *s = ll_hist, x, *p; | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|  |  | ||||||
| void flatten_ll(uint32_t *ll_hist); | void | ||||||
|  | flatten_ll(uint32_t *ll_hist); | ||||||
|   | |||||||
| @@ -86,8 +86,9 @@ | |||||||
|  * @param footer: footer to append at the end of the table. |  * @param footer: footer to append at the end of the table. | ||||||
|  * @param begin_line: string printed at beginning of new line |  * @param begin_line: string printed at beginning of new line | ||||||
|  */ |  */ | ||||||
| void fprint_uint8_table(FILE * outfile, uint8_t * table, uint64_t length, char *header, | void | ||||||
| 			char *footer, char *begin_line) | fprint_uint8_table(FILE *outfile, uint8_t *table, uint64_t length, char *header, char *footer, | ||||||
|  |                    char *begin_line) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         fprintf(outfile, "%s", header); |         fprintf(outfile, "%s", header); | ||||||
| @@ -105,7 +106,6 @@ void fprint_uint8_table(FILE * outfile, uint8_t * table, uint64_t length, char * | |||||||
|                 fprintf(outfile, " "); |                 fprintf(outfile, " "); | ||||||
|         fprintf(outfile, "0x%02x", table[i]); |         fprintf(outfile, "0x%02x", table[i]); | ||||||
|         fprintf(outfile, "%s", footer); |         fprintf(outfile, "%s", footer); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -117,8 +117,9 @@ void fprint_uint8_table(FILE * outfile, uint8_t * table, uint64_t length, char * | |||||||
|  * @param footer: footer to append at the end of the table. |  * @param footer: footer to append at the end of the table. | ||||||
|  * @param begin_line: string printed at beginning of new line |  * @param begin_line: string printed at beginning of new line | ||||||
|  */ |  */ | ||||||
| void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char *header, | void | ||||||
| 			 char *footer, char *begin_line) | fprint_uint16_table(FILE *outfile, uint16_t *table, uint64_t length, char *header, char *footer, | ||||||
|  |                     char *begin_line) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         fprintf(outfile, "%s", header); |         fprintf(outfile, "%s", header); | ||||||
| @@ -136,7 +137,6 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char | |||||||
|                 fprintf(outfile, " "); |                 fprintf(outfile, " "); | ||||||
|         fprintf(outfile, "0x%04x", table[i]); |         fprintf(outfile, "0x%04x", table[i]); | ||||||
|         fprintf(outfile, "%s", footer); |         fprintf(outfile, "%s", footer); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -148,8 +148,9 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char | |||||||
|  * @param footer: footer to append at the end of the table. |  * @param footer: footer to append at the end of the table. | ||||||
|  * @param begin_line: string printed at beginning of new line |  * @param begin_line: string printed at beginning of new line | ||||||
|  */ |  */ | ||||||
| void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char *header, | void | ||||||
| 			 char *footer, char *begin_line) | fprint_uint32_table(FILE *outfile, uint32_t *table, uint64_t length, char *header, char *footer, | ||||||
|  |                     char *begin_line) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         fprintf(outfile, "%s", header); |         fprintf(outfile, "%s", header); | ||||||
| @@ -167,11 +168,10 @@ void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char | |||||||
|                 fprintf(outfile, " "); |                 fprintf(outfile, " "); | ||||||
|         fprintf(outfile, "0x%08x", table[i]); |         fprintf(outfile, "0x%08x", table[i]); | ||||||
|         fprintf(outfile, "%s", footer); |         fprintf(outfile, "%s", footer); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void fprint_hufftables(FILE * output_file, char *hufftables_name, | void | ||||||
| 		       struct isal_hufftables *hufftables) | 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); | ||||||
|  |  | ||||||
| @@ -196,37 +196,43 @@ void fprint_hufftables(FILE * output_file, char *hufftables_name, | |||||||
|                            "\t.lit_table_sizes = {", "},\n\n", "\t\t"); |                            "\t.lit_table_sizes = {", "},\n\n", "\t\t"); | ||||||
|  |  | ||||||
|         fprint_uint16_table(output_file, hufftables->dcodes, |         fprint_uint16_table(output_file, hufftables->dcodes, | ||||||
| 			    ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET, |                             ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET, "\t.dcodes = {", "},\n\n", | ||||||
| 			    "\t.dcodes = {", "},\n\n", "\t\t"); |                             "\t\t"); | ||||||
|         fprint_uint8_table(output_file, hufftables->dcodes_sizes, |         fprint_uint8_table(output_file, hufftables->dcodes_sizes, | ||||||
| 			   ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET, |                            ISAL_DEF_DIST_SYMBOLS - IGZIP_DECODE_OFFSET, "\t.dcodes_sizes = {", | ||||||
| 			   "\t.dcodes_sizes = {", "}\n", "\t\t"); |                            "}\n", "\t\t"); | ||||||
|         fprintf(output_file, "};\n"); |         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 <stdint.h>\n"); | ||||||
|         fprintf(output_file, "#include <igzip_lib.h>\n\n"); |         fprintf(output_file, "#include <igzip_lib.h>\n\n"); | ||||||
|  |  | ||||||
| 	fprintf(output_file, "#if IGZIP_HIST_SIZE > %d\n" |         fprintf(output_file, | ||||||
|  |                 "#if IGZIP_HIST_SIZE > %d\n" | ||||||
|                 "# error \"Invalid history size for the custom hufftable\"\n" |                 "# error \"Invalid history size for the custom hufftable\"\n" | ||||||
| 		"#endif\n", IGZIP_HIST_SIZE); |                 "#endif\n", | ||||||
|  |                 IGZIP_HIST_SIZE); | ||||||
|  |  | ||||||
| #ifdef LONGER_HUFFTABLE | #ifdef LONGER_HUFFTABLE | ||||||
| 	fprintf(output_file, "#ifndef LONGER_HUFFTABLE\n" |         fprintf(output_file, | ||||||
|  |                 "#ifndef LONGER_HUFFTABLE\n" | ||||||
|                 "# error \"Custom hufftable requires LONGER_HUFFTABLE to be defined \"\n" |                 "# error \"Custom hufftable requires LONGER_HUFFTABLE to be defined \"\n" | ||||||
|                 "#endif\n"); |                 "#endif\n"); | ||||||
| #else | #else | ||||||
| 	fprintf(output_file, "#ifdef LONGER_HUFFTABLE\n" |         fprintf(output_file, | ||||||
|  |                 "#ifdef LONGER_HUFFTABLE\n" | ||||||
|                 "# error \"Custom hufftable requires LONGER_HUFFTABLE to not be defined \"\n" |                 "# error \"Custom hufftable requires LONGER_HUFFTABLE to not be defined \"\n" | ||||||
|                 "#endif\n"); |                 "#endif\n"); | ||||||
| #endif | #endif | ||||||
|         fprintf(output_file, "\n"); |         fprintf(output_file, "\n"); | ||||||
|  |  | ||||||
|         fprintf(output_file, "const uint8_t gzip_hdr[] = {\n" |         fprintf(output_file, "const uint8_t gzip_hdr[] = {\n" | ||||||
| 		"\t0x1f, 0x8b, 0x08, 0x00, 0x00,\n" "\t0x00, 0x00, 0x00, 0x00, 0xff\t};\n\n"); |                              "\t0x1f, 0x8b, 0x08, 0x00, 0x00,\n" | ||||||
|  |                              "\t0x00, 0x00, 0x00, 0x00, 0xff\t};\n\n"); | ||||||
|  |  | ||||||
|         fprintf(output_file, "const uint32_t gzip_hdr_bytes = %d;\n", GZIP_HEADER_SIZE); |         fprintf(output_file, "const uint32_t gzip_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_trl_bytes = %d;\n\n", GZIP_TRAILER_SIZE); | ||||||
| @@ -236,7 +242,8 @@ void fprint_header(FILE * output_file) | |||||||
|         fprintf(output_file, "const uint32_t zlib_trl_bytes = %d;\n", ZLIB_TRAILER_SIZE); |         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); |         assert(dist <= 32768 && dist > 0); | ||||||
|         if (dist <= 32768) { |         if (dist <= 32768) { | ||||||
| @@ -250,7 +257,8 @@ static uint32_t convert_dist_to_dist_sym(uint32_t dist) | |||||||
| /** | /** | ||||||
|  * @brief  Returns the deflate symbol value for a repeat length. |  * @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); | ||||||
|  |  | ||||||
| @@ -271,7 +279,8 @@ static uint32_t convert_length_to_len_sym(uint32_t length) | |||||||
|                 return 285; |                 return 285; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int length, | void | ||||||
|  | isal_update_histogram_dict(uint8_t *start_stream, int dict_length, int length, | ||||||
|                            struct isal_huff_histogram *histogram) |                            struct isal_huff_histogram *histogram) | ||||||
| { | { | ||||||
|         uint32_t literal = 0, hash; |         uint32_t literal = 0, hash; | ||||||
| @@ -304,8 +313,7 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len | |||||||
|                 dist = (current - start_stream - seen) & 0xFFFF; |                 dist = (current - start_stream - seen) & 0xFFFF; | ||||||
|                 if (dist - 1 < D - 1) { |                 if (dist - 1 < D - 1) { | ||||||
|                         assert(start_stream <= current - dist); |                         assert(start_stream <= current - dist); | ||||||
| 			match_length = |                         match_length = compare258(current - dist, current, end_stream - current); | ||||||
| 			    compare258(current - dist, current, end_stream - current); |  | ||||||
|                         if (match_length >= SHORTEST_MATCH) { |                         if (match_length >= SHORTEST_MATCH) { | ||||||
|                                 next_hash = current; |                                 next_hash = current; | ||||||
| #ifdef ISAL_LIMIT_HASH_UPDATE | #ifdef ISAL_LIMIT_HASH_UPDATE | ||||||
| @@ -323,8 +331,7 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len | |||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|                                 dist_histogram[convert_dist_to_dist_sym(dist)] += 1; |                                 dist_histogram[convert_dist_to_dist_sym(dist)] += 1; | ||||||
| 				lit_len_histogram[convert_length_to_len_sym(match_length)] += |                                 lit_len_histogram[convert_length_to_len_sym(match_length)] += 1; | ||||||
| 				    1; |  | ||||||
|                                 current += match_length - 1; |                                 current += match_length - 1; | ||||||
|                                 continue; |                                 continue; | ||||||
|                         } |                         } | ||||||
| @@ -339,7 +346,8 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         long int file_length; |         long int file_length; | ||||||
|         int argi = 1; |         int argi = 1; | ||||||
| @@ -411,8 +419,7 @@ int main(int argc, char *argv[]) | |||||||
|                 } |                 } | ||||||
|                 fseek(hist_file, 0, SEEK_SET); |                 fseek(hist_file, 0, SEEK_SET); | ||||||
|  |  | ||||||
| 		printf("Read %ld bytes of history file %s\n", hist_file_length, |                 printf("Read %ld bytes of history file %s\n", hist_file_length, argv[argi + 1]); | ||||||
| 		       argv[argi + 1]); |  | ||||||
|                 argi += 2; |                 argi += 2; | ||||||
|         } else |         } else | ||||||
|                 memset(&histogram, 0, sizeof(histogram)); /* Initialize histograms. */ |                 memset(&histogram, 0, sizeof(histogram)); /* Initialize histograms. */ | ||||||
|   | |||||||
| @@ -48,8 +48,9 @@ extern struct isal_hufftables hufftables_default; | |||||||
|  * @param footer: footer to append at the end of the table. |  * @param footer: footer to append at the end of the table. | ||||||
|  * @param begin_line: string printed at beginning of new line |  * @param begin_line: string printed at beginning of new line | ||||||
|  */ |  */ | ||||||
| void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char *header, | void | ||||||
| 			 char *footer, char *begin_line) | fprint_uint16_table(FILE *outfile, uint16_t *table, uint64_t length, char *header, char *footer, | ||||||
|  |                     char *begin_line) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         fprintf(outfile, "%s", header); |         fprintf(outfile, "%s", header); | ||||||
| @@ -67,7 +68,6 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char | |||||||
|                 fprintf(outfile, " "); |                 fprintf(outfile, " "); | ||||||
|         fprintf(outfile, "0x%04x", table[i]); |         fprintf(outfile, "0x%04x", table[i]); | ||||||
|         fprintf(outfile, "%s", footer); |         fprintf(outfile, "%s", footer); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -79,8 +79,9 @@ void fprint_uint16_table(FILE * outfile, uint16_t * table, uint64_t length, char | |||||||
|  * @param footer: footer to append at the end of the table. |  * @param footer: footer to append at the end of the table. | ||||||
|  * @param begin_line: string printed at beginning of new line |  * @param begin_line: string printed at beginning of new line | ||||||
|  */ |  */ | ||||||
| void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char *header, | void | ||||||
| 			 char *footer, char *begin_line) | fprint_uint32_table(FILE *outfile, uint32_t *table, uint64_t length, char *header, char *footer, | ||||||
|  |                     char *begin_line) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         fprintf(outfile, "%s", header); |         fprintf(outfile, "%s", header); | ||||||
| @@ -98,23 +99,25 @@ void fprint_uint32_table(FILE * outfile, uint32_t * table, uint64_t length, char | |||||||
|                 fprintf(outfile, " "); |                 fprintf(outfile, " "); | ||||||
|         fprintf(outfile, "0x%08x", table[i]); |         fprintf(outfile, "0x%08x", table[i]); | ||||||
|         fprintf(outfile, "%s", footer); |         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, "#include \"igzip_lib.h\"\n\n"); | ||||||
|         fprintf(output_file, "#define LONG_BITS_CHECK %d\n", ISAL_DECODE_LONG_BITS); |         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, "#define SHORT_BITS_CHECK %d\n", ISAL_DECODE_SHORT_BITS); | ||||||
| 	fprintf(output_file, |         fprintf(output_file, "#if (LONG_BITS_CHECK == ISAL_DECODE_LONG_BITS) && (SHORT_BITS_CHECK " | ||||||
| 		"#if (LONG_BITS_CHECK == ISAL_DECODE_LONG_BITS) && (SHORT_BITS_CHECK == ISAL_DECODE_SHORT_BITS)\n" |                              "== ISAL_DECODE_SHORT_BITS)\n" | ||||||
|                              "# define ISAL_STATIC_INFLATE_TABLE\n" |                              "# define ISAL_STATIC_INFLATE_TABLE\n" | ||||||
|                              "#else\n" |                              "#else\n" | ||||||
| 		"# warning \"Incompatible compile time defines for optimized static inflate table.\"\n" |                              "# warning \"Incompatible compile time defines for optimized static " | ||||||
|  |                              "inflate table.\"\n" | ||||||
|                              "#endif\n\n"); |                              "#endif\n\n"); | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         struct inflate_state state; |         struct inflate_state state; | ||||||
|         FILE *file; |         FILE *file; | ||||||
| @@ -144,7 +147,8 @@ int main(int argc, char *argv[]) | |||||||
|         } |         } | ||||||
|         // Add decode tables describing a type 2 static (fixed) header |         // 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); | ||||||
|  |  | ||||||
| @@ -172,8 +176,7 @@ int main(int argc, char *argv[]) | |||||||
|  |  | ||||||
|         isal_inflate_init(&state); |         isal_inflate_init(&state); | ||||||
|  |  | ||||||
| 	memcpy(in_buf, &hufftables_default.deflate_hdr, |         memcpy(in_buf, &hufftables_default.deflate_hdr, sizeof(hufftables_default.deflate_hdr)); | ||||||
| 	       sizeof(hufftables_default.deflate_hdr)); |  | ||||||
|         state.next_in = in_buf; |         state.next_in = in_buf; | ||||||
|         state.avail_in = DOUBLE_SYM_THRESH + 1; |         state.avail_in = DOUBLE_SYM_THRESH + 1; | ||||||
|         state.next_out = tmp_space; |         state.next_out = tmp_space; | ||||||
|   | |||||||
| @@ -33,26 +33,19 @@ | |||||||
|  |  | ||||||
| /* The order code length codes are written in the dynamic code header. This is | /* The order code length codes are written in the dynamic code header. This is | ||||||
|  * defined in RFC 1951 page 13 */ |  * defined in RFC 1951 page 13 */ | ||||||
| static const uint8_t code_length_code_order[] = | static const uint8_t code_length_code_order[] = { 16, 17, 18, 0, 8,  7, 9,  6, 10, 5, | ||||||
|     { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; |                                                   11, 4,  12, 3, 13, 2, 14, 1, 15 }; | ||||||
|  |  | ||||||
| static const uint32_t len_code_extra_bits[] = { | static const uint32_t len_code_extra_bits[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, | ||||||
| 	0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |                                                 0x1, 0x1, 0x2, 0x2, 0x2, 0x2, 0x3, 0x3, 0x3, 0x3, | ||||||
| 	0x1, 0x1, 0x1, 0x1, 0x2, 0x2, 0x2, 0x2, |                                                 0x4, 0x4, 0x4, 0x4, 0x5, 0x5, 0x5, 0x5, 0x0 }; | ||||||
| 	0x3, 0x3, 0x3, 0x3, 0x4, 0x4, 0x4, 0x4, |  | ||||||
| 	0x5, 0x5, 0x5, 0x5, 0x0 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| static const uint32_t dist_code_extra_bits[] = { | static const uint32_t dist_code_extra_bits[] = { 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x2, 0x2, 0x3, 0x3, | ||||||
| 	0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x2, 0x2, |                                                  0x4, 0x4, 0x5, 0x5, 0x6, 0x6, 0x7, 0x7, 0x8, 0x8, | ||||||
| 	0x3, 0x3, 0x4, 0x4, 0x5, 0x5, 0x6, 0x6, |                                                  0x9, 0x9, 0xa, 0xa, 0xb, 0xb, 0xc, 0xc, 0xd, 0xd }; | ||||||
| 	0x7, 0x7, 0x8, 0x8, 0x9, 0x9, 0xa, 0xa, |  | ||||||
| 	0xb, 0xb, 0xc, 0xc, 0xd, 0xd |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| static struct hufftables_icf static_hufftables = { | static struct hufftables_icf static_hufftables = { | ||||||
| 	.lit_len_table = { |         .lit_len_table = { { { { .code_and_extra = 0x00c, .length2 = 0x8 } } }, | ||||||
| 			  {{{.code_and_extra = 0x00c,.length2 = 0x8}}}, |  | ||||||
|                            { { { .code_and_extra = 0x08c, .length2 = 0x8 } } }, |                            { { { .code_and_extra = 0x08c, .length2 = 0x8 } } }, | ||||||
|                            { { { .code_and_extra = 0x04c, .length2 = 0x8 } } }, |                            { { { .code_and_extra = 0x04c, .length2 = 0x8 } } }, | ||||||
|                            { { { .code_and_extra = 0x0cc, .length2 = 0x8 } } }, |                            { { { .code_and_extra = 0x0cc, .length2 = 0x8 } } }, | ||||||
| @@ -565,8 +558,7 @@ static struct hufftables_icf static_hufftables = { | |||||||
|                            { { { .code_and_extra = 0x000, .length2 = 0x0 } } }, |                            { { { .code_and_extra = 0x000, .length2 = 0x0 } } }, | ||||||
|                            { { { .code_and_extra = 0x000, .length2 = 0x0 } } }, |                            { { { .code_and_extra = 0x000, .length2 = 0x0 } } }, | ||||||
|                            { { { .code_and_extra = 0x000, .length2 = 0x0 } } } }, |                            { { { .code_and_extra = 0x000, .length2 = 0x0 } } } }, | ||||||
| 	.dist_table = { |         .dist_table = { { { { .code_and_extra = 0x000, .length2 = 0x5 } } }, | ||||||
| 		       {{{.code_and_extra = 0x000,.length2 = 0x5}}}, |  | ||||||
|                         { { { .code_and_extra = 0x010, .length2 = 0x5 } } }, |                         { { { .code_and_extra = 0x010, .length2 = 0x5 } } }, | ||||||
|                         { { { .code_and_extra = 0x008, .length2 = 0x5 } } }, |                         { { { .code_and_extra = 0x008, .length2 = 0x5 } } }, | ||||||
|                         { { { .code_and_extra = 0x018, .length2 = 0x5 } } }, |                         { { { .code_and_extra = 0x018, .length2 = 0x5 } } }, | ||||||
| @@ -599,56 +591,47 @@ static struct hufftables_icf static_hufftables = { | |||||||
|                         { { { .code_and_extra = 0x000, .length2 = 0x0 } } } } |                         { { { .code_and_extra = 0x000, .length2 = 0x0 } } } } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| extern uint32_t build_huff_tree(struct heap_tree *heap, uint64_t heap_size, uint64_t node_ptr); | extern uint32_t | ||||||
| extern void build_heap(uint64_t * heap, uint64_t heap_size); | build_huff_tree(struct heap_tree *heap, uint64_t heap_size, uint64_t node_ptr); | ||||||
|  | extern void | ||||||
|  | build_heap(uint64_t *heap, uint64_t heap_size); | ||||||
|  |  | ||||||
| static uint32_t convert_dist_to_dist_sym(uint32_t dist); | static uint32_t | ||||||
| static uint32_t convert_length_to_len_sym(uint32_t length); | convert_dist_to_dist_sym(uint32_t dist); | ||||||
|  | static uint32_t | ||||||
|  | convert_length_to_len_sym(uint32_t length); | ||||||
|  |  | ||||||
| static const uint8_t bitrev8[0x100] = { | static const uint8_t bitrev8[0x100] = { | ||||||
| 	0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, |         0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, | ||||||
| 	0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, |         0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, | ||||||
| 	0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, |         0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, | ||||||
| 	0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, |         0xB4, 0x74, 0xF4, 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, | ||||||
| 	0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, |         0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, | ||||||
| 	0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, |         0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, | ||||||
| 	0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, |         0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, | ||||||
| 	0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, |         0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, | ||||||
| 	0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, |         0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, | ||||||
| 	0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, |         0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, | ||||||
| 	0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, |         0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, | ||||||
| 	0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, |         0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD, | ||||||
| 	0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, |         0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, 0x03, 0x83, 0x43, | ||||||
| 	0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, |         0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, | ||||||
| 	0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, |         0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, | ||||||
| 	0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, |         0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, | ||||||
| 	0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, |         0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, | ||||||
| 	0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, |         0xFF | ||||||
| 	0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, |  | ||||||
| 	0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, |  | ||||||
| 	0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, |  | ||||||
| 	0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, |  | ||||||
| 	0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, |  | ||||||
| 	0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, |  | ||||||
| 	0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, |  | ||||||
| 	0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, |  | ||||||
| 	0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, |  | ||||||
| 	0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, |  | ||||||
| 	0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, |  | ||||||
| 	0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, |  | ||||||
| 	0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, |  | ||||||
| 	0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // bit reverse low order LENGTH bits in code, and return result in low order bits | // bit reverse low order LENGTH bits in code, and return result in low order bits | ||||||
| static inline uint16_t bit_reverse(uint16_t code, uint32_t length) | static inline uint16_t | ||||||
|  | bit_reverse(uint16_t code, uint32_t length) | ||||||
| { | { | ||||||
|         code = (bitrev8[code & 0x00FF] << 8) | (bitrev8[code >> 8]); |         code = (bitrev8[code & 0x00FF] << 8) | (bitrev8[code >> 8]); | ||||||
|         return (code >> (16 - length)); |         return (code >> (16 - length)); | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_update_histogram_base(uint8_t * start_stream, int length, | void | ||||||
| 				struct isal_huff_histogram *histogram) | isal_update_histogram_base(uint8_t *start_stream, int length, struct isal_huff_histogram *histogram) | ||||||
| { | { | ||||||
|         uint32_t literal = 0, hash; |         uint32_t literal = 0, hash; | ||||||
|         uint16_t seen, *last_seen = histogram->hash_table; |         uint16_t seen, *last_seen = histogram->hash_table; | ||||||
| @@ -671,8 +654,7 @@ void isal_update_histogram_base(uint8_t * start_stream, int length, | |||||||
|                 dist = (current - start_stream - seen) & 0xFFFF; |                 dist = (current - start_stream - seen) & 0xFFFF; | ||||||
|                 if (dist - 1 < D - 1) { |                 if (dist - 1 < D - 1) { | ||||||
|                         assert(start_stream <= current - dist); |                         assert(start_stream <= current - dist); | ||||||
| 			match_length = |                         match_length = compare258(current - dist, current, end_stream - current); | ||||||
| 			    compare258(current - dist, current, end_stream - current); |  | ||||||
|                         if (match_length >= SHORTEST_MATCH) { |                         if (match_length >= SHORTEST_MATCH) { | ||||||
|                                 next_hash = current; |                                 next_hash = current; | ||||||
| #ifdef ISAL_LIMIT_HASH_UPDATE | #ifdef ISAL_LIMIT_HASH_UPDATE | ||||||
| @@ -690,8 +672,7 @@ void isal_update_histogram_base(uint8_t * start_stream, int length, | |||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|                                 dist_histogram[convert_dist_to_dist_sym(dist)] += 1; |                                 dist_histogram[convert_dist_to_dist_sym(dist)] += 1; | ||||||
| 				lit_len_histogram[convert_length_to_len_sym(match_length)] += |                                 lit_len_histogram[convert_length_to_len_sym(match_length)] += 1; | ||||||
| 				    1; |  | ||||||
|                                 current += match_length - 1; |                                 current += match_length - 1; | ||||||
|                                 continue; |                                 continue; | ||||||
|                         } |                         } | ||||||
| @@ -709,7 +690,8 @@ void isal_update_histogram_base(uint8_t * start_stream, int length, | |||||||
| /** | /** | ||||||
|  * @brief  Returns the deflate symbol value for a look back distance. |  * @brief  Returns the deflate symbol value for a look back distance. | ||||||
|  */ |  */ | ||||||
| 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); |         assert(dist <= 32768 && dist > 0); | ||||||
|         if (dist <= 32768) { |         if (dist <= 32768) { | ||||||
| @@ -723,7 +705,8 @@ static uint32_t convert_dist_to_dist_sym(uint32_t dist) | |||||||
| /** | /** | ||||||
|  * @brief  Returns the deflate symbol value for a repeat length. |  * @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); | ||||||
|  |  | ||||||
| @@ -748,8 +731,8 @@ static uint32_t convert_length_to_len_sym(uint32_t length) | |||||||
| // and bl_count is the count of the lengths | // and bl_count is the count of the lengths | ||||||
|  |  | ||||||
| /* Init heap with the histogram, and return the histogram size */ | /* Init heap with the histogram, and return the histogram size */ | ||||||
| static inline uint32_t init_heap32(struct heap_tree *heap_space, uint32_t * histogram, | static inline uint32_t | ||||||
| 				   uint32_t hist_size) | init_heap32(struct heap_tree *heap_space, uint32_t *histogram, uint32_t hist_size) | ||||||
| { | { | ||||||
|         uint32_t heap_size, i; |         uint32_t heap_size, i; | ||||||
|  |  | ||||||
| @@ -783,8 +766,8 @@ static inline uint32_t init_heap32(struct heap_tree *heap_space, uint32_t * hist | |||||||
|         return heap_size; |         return heap_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t init_heap64(struct heap_tree *heap_space, uint64_t * histogram, | static inline uint32_t | ||||||
| 				   uint64_t hist_size) | init_heap64(struct heap_tree *heap_space, uint64_t *histogram, uint64_t hist_size) | ||||||
| { | { | ||||||
|         uint32_t heap_size, i; |         uint32_t heap_size, i; | ||||||
|  |  | ||||||
| @@ -817,8 +800,8 @@ static inline uint32_t init_heap64(struct heap_tree *heap_space, uint64_t * hist | |||||||
|         return heap_size; |         return heap_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t init_heap64_semi_complete(struct heap_tree *heap_space, | static inline uint32_t | ||||||
| 						 uint64_t * histogram, uint64_t hist_size, | init_heap64_semi_complete(struct heap_tree *heap_space, uint64_t *histogram, uint64_t hist_size, | ||||||
|                           uint64_t complete_start) |                           uint64_t complete_start) | ||||||
| { | { | ||||||
|         uint32_t heap_size, i; |         uint32_t heap_size, i; | ||||||
| @@ -855,8 +838,8 @@ static inline uint32_t init_heap64_semi_complete(struct heap_tree *heap_space, | |||||||
|         return heap_size; |         return heap_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t init_heap64_complete(struct heap_tree *heap_space, uint64_t * histogram, | static inline uint32_t | ||||||
| 					    uint64_t hist_size) | init_heap64_complete(struct heap_tree *heap_space, uint64_t *histogram, uint64_t hist_size) | ||||||
| { | { | ||||||
|         uint32_t heap_size, i; |         uint32_t heap_size, i; | ||||||
|  |  | ||||||
| @@ -871,8 +854,9 @@ static inline uint32_t init_heap64_complete(struct heap_tree *heap_space, uint64 | |||||||
|         return heap_size; |         return heap_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t fix_code_lens(struct heap_tree *heap_space, uint32_t root_node, | static inline uint32_t | ||||||
| 				     uint32_t * bl_count, uint32_t max_code_len) | fix_code_lens(struct heap_tree *heap_space, uint32_t root_node, uint32_t *bl_count, | ||||||
|  |               uint32_t max_code_len) | ||||||
| { | { | ||||||
|         struct tree_node *tree = heap_space->tree; |         struct tree_node *tree = heap_space->tree; | ||||||
|         uint64_t *code_len_count = heap_space->code_len_count; |         uint64_t *code_len_count = heap_space->code_len_count; | ||||||
| @@ -920,11 +904,13 @@ static inline uint32_t fix_code_lens(struct heap_tree *heap_space, uint32_t root | |||||||
|                 for (; i <= max_code_len; i++) |                 for (; i <= max_code_len; i++) | ||||||
|                         bl_count[i] = 0; |                         bl_count[i] = 0; | ||||||
|  |  | ||||||
| 		for (k = 1; code_len_count[k] == 0; k++) ; |                 for (k = 1; code_len_count[k] == 0; k++) | ||||||
|  |                         ; | ||||||
|                 for (i = root_node; i < j; i++) { |                 for (i = root_node; i < j; i++) { | ||||||
|                         tree[i].depth = k; |                         tree[i].depth = k; | ||||||
|                         code_len_count[k]--; |                         code_len_count[k]--; | ||||||
| 			for (; code_len_count[k] == 0; k++) ; |                         for (; code_len_count[k] == 0; k++) | ||||||
|  |                                 ; | ||||||
|                 } |                 } | ||||||
|         } else { |         } else { | ||||||
|                 bl_count[0] = 0; |                 bl_count[0] = 0; | ||||||
| @@ -935,7 +921,6 @@ static inline uint32_t fix_code_lens(struct heap_tree *heap_space, uint32_t root | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         return j; |         return j; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void | static inline void | ||||||
| @@ -953,7 +938,6 @@ gen_huff_code_lens(struct heap_tree *heap_space, uint32_t heap_size, uint32_t * | |||||||
|         memset(codes, 0, codes_count * sizeof(*codes)); |         memset(codes, 0, codes_count * sizeof(*codes)); | ||||||
|         for (node_ptr = root_node; node_ptr < end_node; node_ptr++) |         for (node_ptr = root_node; node_ptr < end_node; node_ptr++) | ||||||
|                 codes[tree[node_ptr].child].length = tree[node_ptr].depth; |                 codes[tree[node_ptr].child].length = tree[node_ptr].depth; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -964,8 +948,8 @@ gen_huff_code_lens(struct heap_tree *heap_space, uint32_t heap_size, uint32_t * | |||||||
|  * @param table_length: The length of table. |  * @param table_length: The length of table. | ||||||
|  * @param count: a histogram representing the number of occurrences of codes of a given length |  * @param count: a histogram representing the number of occurrences of codes of a given length | ||||||
|  */ |  */ | ||||||
| static inline uint32_t set_huff_codes(struct huff_code *huff_code_table, int table_length, | static inline uint32_t | ||||||
| 				      uint32_t * count) | set_huff_codes(struct huff_code *huff_code_table, int table_length, uint32_t *count) | ||||||
| { | { | ||||||
|         /* Uses the algorithm mentioned in the deflate standard, Rfc 1951. */ |         /* Uses the algorithm mentioned in the deflate standard, Rfc 1951. */ | ||||||
|         int i; |         int i; | ||||||
| @@ -980,8 +964,7 @@ static inline uint32_t set_huff_codes(struct huff_code *huff_code_table, int tab | |||||||
|  |  | ||||||
|         for (i = 0; i < table_length; i++) { |         for (i = 0; i < table_length; i++) { | ||||||
|                 if (huff_code_table[i].length != 0) { |                 if (huff_code_table[i].length != 0) { | ||||||
| 			huff_code_table[i].code = |                         huff_code_table[i].code = bit_reverse(next_code[huff_code_table[i].length], | ||||||
| 			    bit_reverse(next_code[huff_code_table[i].length], |  | ||||||
|                                                               huff_code_table[i].length); |                                                               huff_code_table[i].length); | ||||||
|                         next_code[huff_code_table[i].length] += 1; |                         next_code[huff_code_table[i].length] += 1; | ||||||
|                         max_code = i; |                         max_code = i; | ||||||
| @@ -996,7 +979,8 @@ static inline uint32_t set_huff_codes(struct huff_code *huff_code_table, int tab | |||||||
| // 23:16 code length | // 23:16 code length | ||||||
| // 15:0  code value in low order bits | // 15:0  code value in low order bits | ||||||
| // returns max code value | // returns max code value | ||||||
| static inline uint32_t set_dist_huff_codes(struct huff_code *codes, uint32_t * bl_count) | static inline uint32_t | ||||||
|  | set_dist_huff_codes(struct huff_code *codes, uint32_t *bl_count) | ||||||
| { | { | ||||||
|         uint32_t code, code_len, bits, i; |         uint32_t code, code_len, bits, i; | ||||||
|         uint32_t next_code[MAX_DEFLATE_CODE_LEN + 1]; |         uint32_t next_code[MAX_DEFLATE_CODE_LEN + 1]; | ||||||
| @@ -1033,11 +1017,10 @@ static inline uint32_t set_dist_huff_codes(struct huff_code *codes, uint32_t * b | |||||||
|  * @param hlit: Length of literal/length table minus 257. |  * @param hlit: Length of literal/length table minus 257. | ||||||
|  * @param hdist: Length of distance table minus 1. |  * @param hdist: Length of distance table minus 1. | ||||||
|  */ |  */ | ||||||
| static int create_huffman_header(struct BitBuf2 *header_bitbuf, | static int | ||||||
| 				 struct huff_code *lookup_table, | create_huffman_header(struct BitBuf2 *header_bitbuf, struct huff_code *lookup_table, | ||||||
| 				 struct rl_code *huffman_rep, |                       struct rl_code *huffman_rep, uint16_t huffman_rep_length, | ||||||
| 				 uint16_t huffman_rep_length, uint32_t end_of_block, |                       uint32_t end_of_block, uint32_t hclen, uint32_t hlit, uint32_t hdist) | ||||||
| 				 uint32_t hclen, uint32_t hlit, uint32_t hdist) |  | ||||||
| { | { | ||||||
|         /* hlit, hdist, hclen are as defined in the deflate standard, head is the |         /* hlit, hdist, hclen are as defined in the deflate standard, head is the | ||||||
|          * first three deflate header bits.*/ |          * first three deflate header bits.*/ | ||||||
| @@ -1084,9 +1067,9 @@ static int create_huffman_header(struct BitBuf2 *header_bitbuf, | |||||||
|  * @param end_of_block: Value determining whether end of block header is produced or not; |  * @param end_of_block: Value determining whether end of block header is produced or not; | ||||||
|  * 0 corresponds to not end of block and all other inputs correspond to end of block. |  * 0 corresponds to not end of block and all other inputs correspond to end of block. | ||||||
|  */ |  */ | ||||||
| static inline int create_header(struct BitBuf2 *header_bitbuf, struct rl_code *huffman_rep, | static inline int | ||||||
| 				uint32_t length, uint64_t * histogram, uint32_t hlit, | create_header(struct BitBuf2 *header_bitbuf, struct rl_code *huffman_rep, uint32_t length, | ||||||
| 				uint32_t hdist, uint32_t end_of_block) |               uint64_t *histogram, uint32_t hlit, uint32_t hdist, uint32_t end_of_block) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|  |  | ||||||
| @@ -1113,15 +1096,14 @@ static inline int create_header(struct BitBuf2 *header_bitbuf, struct rl_code *h | |||||||
|         hclen = i - 3; |         hclen = i - 3; | ||||||
|  |  | ||||||
|         /* Generate actual header. */ |         /* Generate actual header. */ | ||||||
| 	bit_count = create_huffman_header(header_bitbuf, lookup_table, huffman_rep, |         bit_count = create_huffman_header(header_bitbuf, lookup_table, huffman_rep, length, | ||||||
| 					  length, end_of_block, hclen, hlit, hdist); |                                           end_of_block, hclen, hlit, hdist); | ||||||
|  |  | ||||||
|         return bit_count; |         return bit_count; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline | static inline struct rl_code * | ||||||
|     struct rl_code *write_rl(struct rl_code *pout, uint16_t last_len, uint32_t run_len, | write_rl(struct rl_code *pout, uint16_t last_len, uint32_t run_len, uint64_t *counts) | ||||||
| 			     uint64_t * counts) |  | ||||||
| { | { | ||||||
|         if (last_len == 0) { |         if (last_len == 0) { | ||||||
|                 while (run_len > 138) { |                 while (run_len > 138) { | ||||||
| @@ -1204,8 +1186,8 @@ static inline | |||||||
| // 4:0  code (0...18) | // 4:0  code (0...18) | ||||||
| // 15:8 Extra bits (0...127) | // 15:8 Extra bits (0...127) | ||||||
| // returns number of symbols in out | // returns number of symbols in out | ||||||
| static inline uint32_t rl_encode(uint16_t * codes, uint32_t num_codes, uint64_t * counts, | static inline uint32_t | ||||||
| 				 struct rl_code *out) | rl_encode(uint16_t *codes, uint32_t num_codes, uint64_t *counts, struct rl_code *out) | ||||||
| { | { | ||||||
|         uint32_t i, run_len; |         uint32_t i, run_len; | ||||||
|         uint16_t last_len, len; |         uint16_t last_len, len; | ||||||
| @@ -1236,8 +1218,9 @@ static inline uint32_t rl_encode(uint16_t * codes, uint32_t num_codes, uint64_t | |||||||
|  * @param length: the length of hufftable |  * @param length: the length of hufftable | ||||||
|  * @param hufftable: a huffman lookup table |  * @param hufftable: a huffman lookup table | ||||||
|  */ |  */ | ||||||
| static void create_code_tables(uint16_t * code_table, uint8_t * code_length_table, | static void | ||||||
| 			       uint32_t length, struct huff_code *hufftable) | create_code_tables(uint16_t *code_table, uint8_t *code_length_table, uint32_t length, | ||||||
|  |                    struct huff_code *hufftable) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         for (i = 0; i < length; i++) { |         for (i = 0; i < length; i++) { | ||||||
| @@ -1254,8 +1237,8 @@ static void create_code_tables(uint16_t * code_table, uint8_t * code_length_tabl | |||||||
|  * @param length: the length of lit_len_hufftable |  * @param length: the length of lit_len_hufftable | ||||||
|  * @param lit_len_hufftable: a literal/length huffman lookup table |  * @param lit_len_hufftable: a literal/length huffman lookup table | ||||||
|  */ |  */ | ||||||
| static void create_packed_len_table(uint32_t * packed_table, | static void | ||||||
| 				    struct huff_code *lit_len_hufftable) | create_packed_len_table(uint32_t *packed_table, struct huff_code *lit_len_hufftable) | ||||||
| { | { | ||||||
|         int i, count = 0; |         int i, count = 0; | ||||||
|         uint16_t extra_bits; |         uint16_t extra_bits; | ||||||
| @@ -1293,8 +1276,8 @@ static void create_packed_len_table(uint32_t * packed_table, | |||||||
|  * @param length: the length of lit_len_hufftable |  * @param length: the length of lit_len_hufftable | ||||||
|  * @param dist_hufftable: a distance huffman lookup table |  * @param dist_hufftable: a distance huffman lookup table | ||||||
|  */ |  */ | ||||||
| static void create_packed_dist_table(uint32_t * packed_table, uint32_t length, | static void | ||||||
| 				     struct huff_code *dist_hufftable) | create_packed_dist_table(uint32_t *packed_table, uint32_t length, struct huff_code *dist_hufftable) | ||||||
| { | { | ||||||
|         int i, count = 0; |         int i, count = 0; | ||||||
|         uint16_t extra_bits; |         uint16_t extra_bits; | ||||||
| @@ -1313,7 +1296,6 @@ static void create_packed_dist_table(uint32_t * packed_table, uint32_t length, | |||||||
|                                 (extra_bits << (dist_hufftable[i].length + LENGTH_BITS)) | |                                 (extra_bits << (dist_hufftable[i].length + LENGTH_BITS)) | | ||||||
|                                 (dist_hufftable[i].code << LENGTH_BITS) | |                                 (dist_hufftable[i].code << LENGTH_BITS) | | ||||||
|                                 (dist_hufftable[i].length + extra_bits_count); |                                 (dist_hufftable[i].length + extra_bits_count); | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if (i == gain_extra_bits) { |                 if (i == gain_extra_bits) { | ||||||
| @@ -1330,8 +1312,8 @@ static void create_packed_dist_table(uint32_t * packed_table, uint32_t length, | |||||||
|  * @param dist_hufftable: distance huffman code |  * @param dist_hufftable: distance huffman code | ||||||
|  * @returns Returns 0 if the table is usable |  * @returns Returns 0 if the table is usable | ||||||
|  */ |  */ | ||||||
| static int are_hufftables_useable(struct huff_code *lit_len_hufftable, | static int | ||||||
| 				  struct huff_code *dist_hufftable) | are_hufftables_useable(struct huff_code *lit_len_hufftable, struct huff_code *dist_hufftable) | ||||||
| { | { | ||||||
|         int max_lit_code_len = 0, max_len_code_len = 0, max_dist_code_len = 0; |         int max_lit_code_len = 0, max_len_code_len = 0, max_dist_code_len = 0; | ||||||
|         int dist_extra_bits = 0, len_extra_bits = 0; |         int dist_extra_bits = 0, len_extra_bits = 0; | ||||||
| @@ -1372,8 +1354,8 @@ static int are_hufftables_useable(struct huff_code *lit_len_hufftable, | |||||||
|         return (max_code_len > MAX_BITBUF_BIT_WRITE); |         return (max_code_len > MAX_BITBUF_BIT_WRITE); | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_create_hufftables(struct isal_hufftables *hufftables, | int | ||||||
| 			   struct isal_huff_histogram *histogram) | isal_create_hufftables(struct isal_hufftables *hufftables, struct isal_huff_histogram *histogram) | ||||||
| { | { | ||||||
|         struct huff_code lit_huff_table[LIT_LEN], dist_huff_table[DIST_LEN]; |         struct huff_code lit_huff_table[LIT_LEN], dist_huff_table[DIST_LEN]; | ||||||
|         uint64_t bit_count; |         uint64_t bit_count; | ||||||
| @@ -1408,8 +1390,7 @@ int isal_create_hufftables(struct isal_hufftables *hufftables, | |||||||
|  |  | ||||||
|         heap_size = init_heap64_complete(&heap_space, dist_histogram, DIST_LEN); |         heap_size = init_heap64_complete(&heap_space, dist_histogram, DIST_LEN); | ||||||
|         gen_huff_code_lens(&heap_space, heap_size, code_len_count, |         gen_huff_code_lens(&heap_space, heap_size, code_len_count, | ||||||
| 			   (struct huff_code *)dist_huff_table, max_dist, |                            (struct huff_code *) dist_huff_table, max_dist, MAX_DEFLATE_CODE_LEN); | ||||||
| 			   MAX_DEFLATE_CODE_LEN); |  | ||||||
|         max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); |         max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); | ||||||
|  |  | ||||||
|         if (are_hufftables_useable(lit_huff_table, dist_huff_table)) { |         if (are_hufftables_useable(lit_huff_table, dist_huff_table)) { | ||||||
| @@ -1424,7 +1405,6 @@ int isal_create_hufftables(struct isal_hufftables *hufftables, | |||||||
|                                    (struct huff_code *) dist_huff_table, max_dist, |                                    (struct huff_code *) dist_huff_table, max_dist, | ||||||
|                                    MAX_SAFE_DIST_CODE_LEN); |                                    MAX_SAFE_DIST_CODE_LEN); | ||||||
|                 max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); |                 max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         create_code_tables(dcodes, dcodes_sizes, DIST_LEN - DCODE_OFFSET, |         create_code_tables(dcodes, dcodes_sizes, DIST_LEN - DCODE_OFFSET, | ||||||
| @@ -1447,13 +1427,11 @@ int isal_create_hufftables(struct isal_hufftables *hufftables, | |||||||
|                 combined_table[i] = lit_huff_table[i].length; |                 combined_table[i] = lit_huff_table[i].length; | ||||||
|         for (i = 0; i < 1 + hdist; i++) |         for (i = 0; i < 1 + hdist; i++) | ||||||
|                 combined_table[i + hlit + 257] = dist_huff_table[i].length; |                 combined_table[i + hlit + 257] = dist_huff_table[i].length; | ||||||
| 	rl_huff_len = |         rl_huff_len = rl_encode(combined_table, hlit + 257 + hdist + 1, count_histogram, rl_huff); | ||||||
| 	    rl_encode(combined_table, hlit + 257 + hdist + 1, count_histogram, rl_huff); |  | ||||||
|  |  | ||||||
|         /* Create header */ |         /* Create header */ | ||||||
| 	bit_count = |         bit_count = create_header(&header_bitbuf, rl_huff, rl_huff_len, count_histogram, hlit, | ||||||
| 	    create_header(&header_bitbuf, rl_huff, rl_huff_len, |                                   hdist, LAST_BLOCK); | ||||||
| 			  count_histogram, hlit, hdist, LAST_BLOCK); |  | ||||||
|         flush(&header_bitbuf); |         flush(&header_bitbuf); | ||||||
|  |  | ||||||
|         hufftables->deflate_hdr_count = bit_count / 8; |         hufftables->deflate_hdr_count = bit_count / 8; | ||||||
| @@ -1462,7 +1440,8 @@ int isal_create_hufftables(struct isal_hufftables *hufftables, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_create_hufftables_subset(struct isal_hufftables *hufftables, | int | ||||||
|  | isal_create_hufftables_subset(struct isal_hufftables *hufftables, | ||||||
|                               struct isal_huff_histogram *histogram) |                               struct isal_huff_histogram *histogram) | ||||||
| { | { | ||||||
|         struct huff_code lit_huff_table[LIT_LEN], dist_huff_table[DIST_LEN]; |         struct huff_code lit_huff_table[LIT_LEN], dist_huff_table[DIST_LEN]; | ||||||
| @@ -1491,8 +1470,7 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables, | |||||||
|  |  | ||||||
|         memset(hufftables, 0, sizeof(struct isal_hufftables)); |         memset(hufftables, 0, sizeof(struct isal_hufftables)); | ||||||
|  |  | ||||||
| 	heap_size = |         heap_size = init_heap64_semi_complete(&heap_space, lit_len_histogram, LIT_LEN, | ||||||
| 	    init_heap64_semi_complete(&heap_space, lit_len_histogram, LIT_LEN, |  | ||||||
|                                               ISAL_DEF_LIT_SYMBOLS); |                                               ISAL_DEF_LIT_SYMBOLS); | ||||||
|         gen_huff_code_lens(&heap_space, heap_size, code_len_count, |         gen_huff_code_lens(&heap_space, heap_size, code_len_count, | ||||||
|                            (struct huff_code *) lit_huff_table, LIT_LEN, MAX_DEFLATE_CODE_LEN); |                            (struct huff_code *) lit_huff_table, LIT_LEN, MAX_DEFLATE_CODE_LEN); | ||||||
| @@ -1500,8 +1478,7 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables, | |||||||
|  |  | ||||||
|         heap_size = init_heap64_complete(&heap_space, dist_histogram, DIST_LEN); |         heap_size = init_heap64_complete(&heap_space, dist_histogram, DIST_LEN); | ||||||
|         gen_huff_code_lens(&heap_space, heap_size, code_len_count, |         gen_huff_code_lens(&heap_space, heap_size, code_len_count, | ||||||
| 			   (struct huff_code *)dist_huff_table, max_dist, |                            (struct huff_code *) dist_huff_table, max_dist, MAX_DEFLATE_CODE_LEN); | ||||||
| 			   MAX_DEFLATE_CODE_LEN); |  | ||||||
|         max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); |         max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); | ||||||
|  |  | ||||||
|         if (are_hufftables_useable(lit_huff_table, dist_huff_table)) { |         if (are_hufftables_useable(lit_huff_table, dist_huff_table)) { | ||||||
| @@ -1516,7 +1493,6 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables, | |||||||
|                                    (struct huff_code *) dist_huff_table, max_dist, |                                    (struct huff_code *) dist_huff_table, max_dist, | ||||||
|                                    MAX_SAFE_DIST_CODE_LEN); |                                    MAX_SAFE_DIST_CODE_LEN); | ||||||
|                 max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); |                 max_dist_sym = set_huff_codes(dist_huff_table, DIST_LEN, code_len_count); | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         create_code_tables(dcodes, dcodes_sizes, DIST_LEN - DCODE_OFFSET, |         create_code_tables(dcodes, dcodes_sizes, DIST_LEN - DCODE_OFFSET, | ||||||
| @@ -1539,13 +1515,11 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables, | |||||||
|                 combined_table[i] = lit_huff_table[i].length; |                 combined_table[i] = lit_huff_table[i].length; | ||||||
|         for (i = 0; i < 1 + hdist; i++) |         for (i = 0; i < 1 + hdist; i++) | ||||||
|                 combined_table[i + hlit + 257] = dist_huff_table[i].length; |                 combined_table[i + hlit + 257] = dist_huff_table[i].length; | ||||||
| 	rl_huff_len = |         rl_huff_len = rl_encode(combined_table, hlit + 257 + hdist + 1, count_histogram, rl_huff); | ||||||
| 	    rl_encode(combined_table, hlit + 257 + hdist + 1, count_histogram, rl_huff); |  | ||||||
|  |  | ||||||
|         /* Create header */ |         /* Create header */ | ||||||
| 	bit_count = |         bit_count = create_header(&header_bitbuf, rl_huff, rl_huff_len, count_histogram, hlit, | ||||||
| 	    create_header(&header_bitbuf, rl_huff, rl_huff_len, |                                   hdist, LAST_BLOCK); | ||||||
| 			  count_histogram, hlit, hdist, LAST_BLOCK); |  | ||||||
|         flush(&header_bitbuf); |         flush(&header_bitbuf); | ||||||
|  |  | ||||||
|         hufftables->deflate_hdr_count = bit_count / 8; |         hufftables->deflate_hdr_count = bit_count / 8; | ||||||
| @@ -1554,7 +1528,8 @@ int isal_create_hufftables_subset(struct isal_hufftables *hufftables, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void expand_hufftables_icf(struct hufftables_icf *hufftables) | static void | ||||||
|  | expand_hufftables_icf(struct hufftables_icf *hufftables) | ||||||
| { | { | ||||||
|         uint32_t i, eb, j, k, len, code; |         uint32_t i, eb, j, k, len, code; | ||||||
|         struct huff_code orig[21], *p_code; |         struct huff_code orig[21], *p_code; | ||||||
| @@ -1618,13 +1593,13 @@ create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables, | |||||||
|                 ll_hist[256] = 1; |                 ll_hist[256] = 1; | ||||||
|  |  | ||||||
|         heap_size = init_heap32(&heap_space, ll_hist, LIT_LEN); |         heap_size = init_heap32(&heap_space, ll_hist, LIT_LEN); | ||||||
| 	gen_huff_code_lens(&heap_space, heap_size, bl_count, |         gen_huff_code_lens(&heap_space, heap_size, bl_count, ll_codes, LIT_LEN, | ||||||
| 			   ll_codes, LIT_LEN, MAX_DEFLATE_CODE_LEN); |                            MAX_DEFLATE_CODE_LEN); | ||||||
|         max_ll_code = set_huff_codes(ll_codes, LIT_LEN, bl_count); |         max_ll_code = set_huff_codes(ll_codes, LIT_LEN, bl_count); | ||||||
|  |  | ||||||
|         heap_size = init_heap32(&heap_space, d_hist, DIST_LEN); |         heap_size = init_heap32(&heap_space, d_hist, DIST_LEN); | ||||||
| 	gen_huff_code_lens(&heap_space, heap_size, bl_count, d_codes, |         gen_huff_code_lens(&heap_space, heap_size, bl_count, d_codes, DIST_LEN, | ||||||
| 			   DIST_LEN, MAX_DEFLATE_CODE_LEN); |                            MAX_DEFLATE_CODE_LEN); | ||||||
|         max_d_code = set_dist_huff_codes(d_codes, bl_count); |         max_d_code = set_dist_huff_codes(d_codes, bl_count); | ||||||
|  |  | ||||||
|         assert(max_ll_code >= 256); // must be EOB code |         assert(max_ll_code >= 256); // must be EOB code | ||||||
| @@ -1641,8 +1616,7 @@ create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables, | |||||||
|  |  | ||||||
|         for (; i < max_ll_code + 1; i++) { |         for (; i < max_ll_code + 1; i++) { | ||||||
|                 combined_table[i] = ll_codes[i].length; |                 combined_table[i] = ll_codes[i].length; | ||||||
| 		compressed_len += |                 compressed_len += (ll_codes[i].length + len_code_extra_bits[i - 257]) * ll_hist[i]; | ||||||
| 		    (ll_codes[i].length + len_code_extra_bits[i - 257]) * ll_hist[i]; |  | ||||||
|                 static_compressed_len += |                 static_compressed_len += | ||||||
|                         (static_ll_codes[i].length + len_code_extra_bits[i - 257]) * ll_hist[i]; |                         (static_ll_codes[i].length + len_code_extra_bits[i - 257]) * ll_hist[i]; | ||||||
|         } |         } | ||||||
| @@ -1655,8 +1629,8 @@ create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables, | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (static_compressed_len > compressed_len) { |         if (static_compressed_len > compressed_len) { | ||||||
| 		num_cl_tokens = rl_encode(combined_table, max_ll_code + max_d_code + 2, |                 num_cl_tokens = rl_encode(combined_table, max_ll_code + max_d_code + 2, cl_counts, | ||||||
| 					  cl_counts, cl_tokens); |                                           cl_tokens); | ||||||
|  |  | ||||||
|                 /* Create header */ |                 /* Create header */ | ||||||
|                 create_header(bb, cl_tokens, num_cl_tokens, cl_counts, max_ll_code - 256, |                 create_header(bb, cl_tokens, num_cl_tokens, cl_counts, max_ll_code - 256, | ||||||
|   | |||||||
| @@ -50,7 +50,8 @@ | |||||||
|  * |  * | ||||||
|  * @returns bit offset of msb starting at 1 for first bit |  * @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) | #if defined(_MSC_VER) | ||||||
| @@ -71,7 +72,8 @@ static inline uint32_t bsr(uint32_t val) | |||||||
|         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; | ||||||
|  |  | ||||||
| @@ -90,8 +92,9 @@ static inline uint32_t tzbytecnt(uint64_t val) | |||||||
|         return cnt; |         return cnt; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist, | static void | ||||||
| 			      uint64_t * p_code, uint64_t * p_len) | 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); | ||||||
|  |  | ||||||
| @@ -116,8 +119,8 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist, | |||||||
|         *p_len = len + num_extra_bits; |         *p_len = len + num_extra_bits; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t dist, | static inline void | ||||||
| 				 uint64_t * code, uint64_t * len) | get_dist_code(struct isal_hufftables *hufftables, uint32_t dist, uint64_t *code, uint64_t *len) | ||||||
| { | { | ||||||
|         assert(dist >= 1); |         assert(dist >= 1); | ||||||
|         assert(dist <= 32768); |         assert(dist <= 32768); | ||||||
| @@ -131,8 +134,8 @@ static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t di | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void get_len_code(struct isal_hufftables *hufftables, uint32_t length, | static inline void | ||||||
| 				uint64_t * code, uint64_t * len) | get_len_code(struct isal_hufftables *hufftables, uint32_t length, uint64_t *code, uint64_t *len) | ||||||
| { | { | ||||||
|         assert(length >= 3); |         assert(length >= 3); | ||||||
|         assert(length <= 258); |         assert(length <= 258); | ||||||
| @@ -143,8 +146,8 @@ static inline void get_len_code(struct isal_hufftables *hufftables, uint32_t len | |||||||
|         *len = code_len & 0x1F; |         *len = code_len & 0x1F; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void get_lit_code(struct isal_hufftables *hufftables, uint32_t lit, | static inline void | ||||||
| 				uint64_t * code, uint64_t * len) | get_lit_code(struct isal_hufftables *hufftables, uint32_t lit, uint64_t *code, uint64_t *len) | ||||||
| { | { | ||||||
|         assert(lit <= 256); |         assert(lit <= 256); | ||||||
|  |  | ||||||
| @@ -152,7 +155,8 @@ static inline void get_lit_code(struct isal_hufftables *hufftables, uint32_t lit | |||||||
|         *len = hufftables->lit_table_sizes[lit]; |         *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 msb; | ||||||
|         uint32_t num_extra_bits; |         uint32_t num_extra_bits; | ||||||
| @@ -167,7 +171,8 @@ static void compute_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t * ext | |||||||
|         assert(*code < 30); |         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 >= 1); | ||||||
|         assert(dist <= 32768); |         assert(dist <= 32768); | ||||||
| @@ -179,7 +184,8 @@ static inline void get_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t * | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void get_len_icf_code(uint32_t length, uint32_t * code) | static inline void | ||||||
|  | get_len_icf_code(uint32_t length, uint32_t *code) | ||||||
| { | { | ||||||
|         assert(length >= 3); |         assert(length >= 3); | ||||||
|         assert(length <= 258); |         assert(length <= 258); | ||||||
| @@ -187,7 +193,8 @@ static inline void get_len_icf_code(uint32_t length, uint32_t * code) | |||||||
|         *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); | ||||||
|  |  | ||||||
| @@ -197,7 +204,8 @@ static inline void get_lit_icf_code(uint32_t lit, uint32_t * code) | |||||||
| /** | /** | ||||||
|  * @brief Returns a hash of the first 3 bytes of input data. |  * @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__ | #ifdef __SSE4_2__ | ||||||
|  |  | ||||||
| @@ -219,7 +227,8 @@ static inline uint32_t compute_hash(uint32_t data) | |||||||
|  |  | ||||||
| #define PROD1 0xFFFFE84B | #define PROD1 0xFFFFE84B | ||||||
| #define PROD2 0xFFFF97B1 | #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_low; | ||||||
|         int16_t data_high; |         int16_t data_high; | ||||||
| @@ -235,7 +244,8 @@ static inline uint32_t compute_hash_mad(uint32_t data) | |||||||
|         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,7 +257,8 @@ static inline uint32_t compute_long_hash(uint64_t data) | |||||||
|  * @param str2: Second input string. |  * @param str2: Second input string. | ||||||
|  * @param max_length: length of the smaller 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; |         uint32_t count; | ||||||
|         uint64_t test; |         uint64_t test; | ||||||
| @@ -308,7 +319,8 @@ static inline int compare258(uint8_t * str1, uint8_t * str2, uint32_t max_length | |||||||
|  * @param str2: Second input string. |  * @param str2: Second input string. | ||||||
|  * @param max_length: length of the smaller 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; |         uint32_t count; | ||||||
|         uint64_t test; |         uint64_t test; | ||||||
|   | |||||||
							
								
								
									
										11710
									
								
								igzip/hufftables_c.c
									
									
									
									
									
								
							
							
						
						
									
										11710
									
								
								igzip/hufftables_c.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										389
									
								
								igzip/igzip.c
									
									
									
									
									
								
							
							
						
						
									
										389
									
								
								igzip/igzip.c
									
									
									
									
									
								
							| @@ -54,10 +54,14 @@ | |||||||
| #include "igzip_wrapper.h" | #include "igzip_wrapper.h" | ||||||
| #include "unaligned.h" | #include "unaligned.h" | ||||||
|  |  | ||||||
| extern void isal_deflate_hash_lvl0(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | extern void | ||||||
| extern void isal_deflate_hash_lvl1(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | isal_deflate_hash_lvl0(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | ||||||
| extern void isal_deflate_hash_lvl2(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | extern void | ||||||
| extern void isal_deflate_hash_lvl3(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | isal_deflate_hash_lvl1(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | ||||||
|  | extern void | ||||||
|  | isal_deflate_hash_lvl2(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | ||||||
|  | extern void | ||||||
|  | isal_deflate_hash_lvl3(uint16_t *, uint32_t, uint32_t, uint8_t *, uint32_t); | ||||||
| extern const uint8_t gzip_hdr[]; | extern const uint8_t gzip_hdr[]; | ||||||
| extern const uint32_t gzip_hdr_bytes; | extern const uint32_t gzip_hdr_bytes; | ||||||
| extern const uint32_t gzip_trl_bytes; | extern const uint32_t gzip_trl_bytes; | ||||||
| @@ -67,38 +71,52 @@ extern const uint32_t zlib_trl_bytes; | |||||||
| extern const struct isal_hufftables hufftables_default; | extern const struct isal_hufftables hufftables_default; | ||||||
| extern const struct isal_hufftables hufftables_static; | extern const struct isal_hufftables hufftables_static; | ||||||
|  |  | ||||||
| static uint32_t write_stored_block(struct isal_zstream *stream); | static uint32_t | ||||||
|  | write_stored_block(struct isal_zstream *stream); | ||||||
|  |  | ||||||
| static int write_stream_header_stateless(struct isal_zstream *stream); | static int | ||||||
| static void write_stream_header(struct isal_zstream *stream); | write_stream_header_stateless(struct isal_zstream *stream); | ||||||
| static int write_deflate_header_stateless(struct isal_zstream *stream); | static void | ||||||
| static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream); | write_stream_header(struct isal_zstream *stream); | ||||||
|  | static int | ||||||
|  | write_deflate_header_stateless(struct isal_zstream *stream); | ||||||
|  | static int | ||||||
|  | write_deflate_header_unaligned_stateless(struct isal_zstream *stream); | ||||||
|  |  | ||||||
| #define TYPE0_HDR_LEN     4 | #define TYPE0_HDR_LEN     4 | ||||||
| #define TYPE0_BLK_HDR_LEN 5 | #define TYPE0_BLK_HDR_LEN 5 | ||||||
| #define TYPE0_MAX_BLK_LEN 65535 | #define TYPE0_MAX_BLK_LEN 65535 | ||||||
|  |  | ||||||
| void isal_deflate_body(struct isal_zstream *stream); | void | ||||||
| void isal_deflate_finish(struct isal_zstream *stream); | isal_deflate_body(struct isal_zstream *stream); | ||||||
|  | void | ||||||
|  | isal_deflate_finish(struct isal_zstream *stream); | ||||||
|  |  | ||||||
| void isal_deflate_icf_body(struct isal_zstream *stream); | void | ||||||
| void isal_deflate_icf_finish_lvl1(struct isal_zstream *stream); | isal_deflate_icf_body(struct isal_zstream *stream); | ||||||
| void isal_deflate_icf_finish_lvl2(struct isal_zstream *stream); | void | ||||||
| void isal_deflate_icf_finish_lvl3(struct isal_zstream *stream); | isal_deflate_icf_finish_lvl1(struct isal_zstream *stream); | ||||||
|  | void | ||||||
|  | isal_deflate_icf_finish_lvl2(struct isal_zstream *stream); | ||||||
|  | void | ||||||
|  | isal_deflate_icf_finish_lvl3(struct isal_zstream *stream); | ||||||
| /*****************************************************************/ | /*****************************************************************/ | ||||||
|  |  | ||||||
| /* Forward declarations */ | /* Forward declarations */ | ||||||
| static inline void reset_match_history(struct isal_zstream *stream); | static inline void | ||||||
| static void write_header(struct isal_zstream *stream, uint8_t * deflate_hdr, | reset_match_history(struct isal_zstream *stream); | ||||||
| 			 uint32_t deflate_hdr_count, uint32_t extra_bits_count, | static void | ||||||
| 			 uint32_t next_state, uint32_t toggle_end_of_stream); | write_header(struct isal_zstream *stream, uint8_t *deflate_hdr, uint32_t deflate_hdr_count, | ||||||
| static void write_trailer(struct isal_zstream *stream); |              uint32_t extra_bits_count, uint32_t next_state, uint32_t toggle_end_of_stream); | ||||||
|  | static void | ||||||
|  | write_trailer(struct isal_zstream *stream); | ||||||
|  |  | ||||||
| /*****************************************************************/ | /*****************************************************************/ | ||||||
|  |  | ||||||
| // isal_adler32_bam1 - adler with (B | A minus 1) storage | // isal_adler32_bam1 - adler with (B | A minus 1) storage | ||||||
|  |  | ||||||
| uint32_t isal_adler32_bam1(uint32_t adler32, const unsigned char *start, uint64_t length) | uint32_t | ||||||
|  | isal_adler32_bam1(uint32_t adler32, const unsigned char *start, uint64_t length) | ||||||
| { | { | ||||||
|         uint64_t a; |         uint64_t a; | ||||||
|  |  | ||||||
| @@ -113,7 +131,8 @@ uint32_t isal_adler32_bam1(uint32_t adler32, const unsigned char *start, uint64_ | |||||||
|         return (adler32 & 0xffff0000) | a; |         return (adler32 & 0xffff0000) | a; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void update_checksum(struct isal_zstream *stream, uint8_t * start_in, uint64_t length) | static void | ||||||
|  | update_checksum(struct isal_zstream *stream, uint8_t *start_in, uint64_t length) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         switch (stream->gzip_flag) { |         switch (stream->gzip_flag) { | ||||||
| @@ -128,8 +147,8 @@ static void update_checksum(struct isal_zstream *stream, uint8_t * start_in, uin | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static | static void | ||||||
| void sync_flush(struct isal_zstream *stream) | sync_flush(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint64_t bits_to_write = 0xFFFF0000, bits_len; |         uint64_t bits_to_write = 0xFFFF0000, bits_len; | ||||||
| @@ -162,7 +181,8 @@ void sync_flush(struct isal_zstream *stream) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void flush_write_buffer(struct isal_zstream *stream) | static void | ||||||
|  | flush_write_buffer(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         int bytes = 0; |         int bytes = 0; | ||||||
| @@ -177,7 +197,8 @@ static void flush_write_buffer(struct isal_zstream *stream) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void flush_icf_block(struct isal_zstream *stream) | static void | ||||||
|  | flush_icf_block(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -186,9 +207,9 @@ static void flush_icf_block(struct isal_zstream *stream) | |||||||
|  |  | ||||||
|         set_buf(write_buf, stream->next_out, stream->avail_out); |         set_buf(write_buf, stream->next_out, stream->avail_out); | ||||||
|  |  | ||||||
| 	icf_buf_encoded_next = encode_deflate_icf(level_buf->icf_buf_start + state->count, |         icf_buf_encoded_next = | ||||||
| 						  level_buf->icf_buf_next, write_buf, |                 encode_deflate_icf(level_buf->icf_buf_start + state->count, level_buf->icf_buf_next, | ||||||
| 						  &level_buf->encode_tables); |                                    write_buf, &level_buf->encode_tables); | ||||||
|  |  | ||||||
|         state->count = icf_buf_encoded_next - level_buf->icf_buf_start; |         state->count = icf_buf_encoded_next - level_buf->icf_buf_start; | ||||||
|         stream->next_out = buffer_ptr(write_buf); |         stream->next_out = buffer_ptr(write_buf); | ||||||
| @@ -206,7 +227,8 @@ static void flush_icf_block(struct isal_zstream *stream) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static int check_level_req(struct isal_zstream *stream) | static int | ||||||
|  | check_level_req(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         if (stream->level == 0) |         if (stream->level == 0) | ||||||
|                 return 0; |                 return 0; | ||||||
| @@ -235,7 +257,8 @@ static int check_level_req(struct isal_zstream *stream) | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int init_hash8k_buf(struct isal_zstream *stream) | static int | ||||||
|  | init_hash8k_buf(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -243,7 +266,8 @@ static int init_hash8k_buf(struct isal_zstream *stream) | |||||||
|         return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash8k); |         return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash8k); | ||||||
| } | } | ||||||
|  |  | ||||||
| static int init_hash_hist_buf(struct isal_zstream *stream) | static int | ||||||
|  | init_hash_hist_buf(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -251,7 +275,8 @@ static int init_hash_hist_buf(struct isal_zstream *stream) | |||||||
|         return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash_hist); |         return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash_hist); | ||||||
| } | } | ||||||
|  |  | ||||||
| static int init_hash_map_buf(struct isal_zstream *stream) | static int | ||||||
|  | init_hash_map_buf(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -262,11 +287,11 @@ static int init_hash_map_buf(struct isal_zstream *stream) | |||||||
|         state->has_level_buf_init = 1; |         state->has_level_buf_init = 1; | ||||||
|  |  | ||||||
|         return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash_map); |         return sizeof(struct level_buf) - MAX_LVL_BUF_SIZE + sizeof(level_buf->hash_map); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* returns the size of the level specific buffer */ | /* returns the size of the level specific buffer */ | ||||||
| static int init_lvlX_buf(struct isal_zstream *stream) | static int | ||||||
|  | init_lvlX_buf(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         switch (stream->level) { |         switch (stream->level) { | ||||||
|         case 3: |         case 3: | ||||||
| @@ -276,10 +301,10 @@ static int init_lvlX_buf(struct isal_zstream *stream) | |||||||
|         default: |         default: | ||||||
|                 return init_hash8k_buf(stream); |                 return init_hash8k_buf(stream); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static void init_new_icf_block(struct isal_zstream *stream) | static void | ||||||
|  | init_new_icf_block(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -288,8 +313,7 @@ static void init_new_icf_block(struct isal_zstream *stream) | |||||||
|         level_struct_size = init_lvlX_buf(stream); |         level_struct_size = init_lvlX_buf(stream); | ||||||
|  |  | ||||||
|         state->block_next = state->block_end; |         state->block_next = state->block_end; | ||||||
| 	level_buf->icf_buf_start = |         level_buf->icf_buf_start = (struct deflate_icf *) (stream->level_buf + level_struct_size); | ||||||
| 	    (struct deflate_icf *)(stream->level_buf + level_struct_size); |  | ||||||
|  |  | ||||||
|         level_buf->icf_buf_next = level_buf->icf_buf_start; |         level_buf->icf_buf_next = level_buf->icf_buf_start; | ||||||
|         level_buf->icf_buf_avail_out = |         level_buf->icf_buf_avail_out = | ||||||
| @@ -299,20 +323,23 @@ static void init_new_icf_block(struct isal_zstream *stream) | |||||||
|         state->state = ZSTATE_BODY; |         state->state = ZSTATE_BODY; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int are_buffers_empty_hashX(struct isal_zstream *stream) | static int | ||||||
|  | are_buffers_empty_hashX(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         return !stream->avail_in; |         return !stream->avail_in; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int are_buffers_empty_hash_map(struct isal_zstream *stream) | static int | ||||||
|  | are_buffers_empty_hash_map(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
|  |  | ||||||
| 	return (!stream->avail_in |         return (!stream->avail_in && | ||||||
| 		&& level_buf->hash_map.matches_next >= level_buf->hash_map.matches_end); |                 level_buf->hash_map.matches_next >= level_buf->hash_map.matches_end); | ||||||
| } | } | ||||||
|  |  | ||||||
| static int are_buffers_empty(struct isal_zstream *stream) | static int | ||||||
|  | are_buffers_empty(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|  |  | ||||||
|         switch (stream->level) { |         switch (stream->level) { | ||||||
| @@ -325,7 +352,8 @@ static int are_buffers_empty(struct isal_zstream *stream) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in) | static void | ||||||
|  | create_icf_block_hdr(struct isal_zstream *stream, uint8_t *start_in) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -346,8 +374,9 @@ static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in | |||||||
|          * for bits stored in the bitbuf. Since 3 bits correspond to the deflate |          * for bits stored in the bitbuf. Since 3 bits correspond to the deflate | ||||||
|          * type 0 header, we need to add one byte more when the number of bits |          * type 0 header, we need to add one byte more when the number of bits | ||||||
|          * is at least 6 mod 8. */ |          * is at least 6 mod 8. */ | ||||||
| 	block_size = (TYPE0_BLK_HDR_LEN) * ((block_in_size + TYPE0_MAX_BLK_LEN - 1) / |         block_size = (TYPE0_BLK_HDR_LEN) * | ||||||
| 					    TYPE0_MAX_BLK_LEN) + block_in_size; |                              ((block_in_size + TYPE0_MAX_BLK_LEN - 1) / TYPE0_MAX_BLK_LEN) + | ||||||
|  |                      block_in_size; | ||||||
|         block_size = block_size ? block_size : TYPE0_BLK_HDR_LEN; |         block_size = block_size ? block_size : TYPE0_BLK_HDR_LEN; | ||||||
|         block_size += (write_buf->m_bit_count + 2) / 8; |         block_size += (write_buf->m_bit_count + 2) / 8; | ||||||
|  |  | ||||||
| @@ -374,17 +403,17 @@ static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in | |||||||
|                 buffer_header = 1; |                 buffer_header = 1; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	bit_count = create_hufftables_icf(write_buf, &level_buf->encode_tables, |         bit_count = create_hufftables_icf(write_buf, &level_buf->encode_tables, &level_buf->hist, | ||||||
| 					  &level_buf->hist, state->has_eob_hdr); |                                           state->has_eob_hdr); | ||||||
|  |  | ||||||
|         /* Assumes that type 0 block has size less than 4G */ |         /* Assumes that type 0 block has size less than 4G */ | ||||||
|         block_start_offset = (stream->total_in - state->block_next); |         block_start_offset = (stream->total_in - state->block_next); | ||||||
|         cur_in_processed = stream->next_in - start_in; |         cur_in_processed = stream->next_in - start_in; | ||||||
| 	avail_output = stream->avail_out + sizeof(state->buffer) - |         avail_output = | ||||||
| 	    (stream->total_in - state->block_end); |                 stream->avail_out + sizeof(state->buffer) - (stream->total_in - state->block_end); | ||||||
|  |  | ||||||
| 	if (bit_count / 8 >= block_size && cur_in_processed >= block_start_offset |         if (bit_count / 8 >= block_size && cur_in_processed >= block_start_offset && | ||||||
| 	    && block_size <= avail_output) { |             block_size <= avail_output) { | ||||||
|                 /* Reset stream for writing out a type0 block */ |                 /* Reset stream for writing out a type0 block */ | ||||||
|                 state->has_eob_hdr = 0; |                 state->has_eob_hdr = 0; | ||||||
|                 memcpy(write_buf, &write_buf_tmp, sizeof(struct BitBuf2)); |                 memcpy(write_buf, &write_buf_tmp, sizeof(struct BitBuf2)); | ||||||
| @@ -408,7 +437,8 @@ static void create_icf_block_hdr(struct isal_zstream *stream, uint8_t * start_in | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void isal_deflate_pass(struct isal_zstream *stream) | static void | ||||||
|  | isal_deflate_pass(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct isal_hufftables *hufftables = stream->hufftables; |         struct isal_hufftables *hufftables = stream->hufftables; | ||||||
| @@ -442,7 +472,8 @@ static void isal_deflate_pass(struct isal_zstream *stream) | |||||||
|                 write_trailer(stream); |                 write_trailer(stream); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void isal_deflate_icf_finish(struct isal_zstream *stream) | static void | ||||||
|  | isal_deflate_icf_finish(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         switch (stream->level) { |         switch (stream->level) { | ||||||
|         case 3: |         case 3: | ||||||
| @@ -456,7 +487,8 @@ static void isal_deflate_icf_finish(struct isal_zstream *stream) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_start) | static void | ||||||
|  | isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t *inbuf_start) | ||||||
| { | { | ||||||
|         uint8_t *start_in = stream->next_in; |         uint8_t *start_in = stream->next_in; | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
| @@ -479,10 +511,8 @@ static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_s | |||||||
|                         /* Note that the header may be prepended by the |                         /* Note that the header may be prepended by the | ||||||
|                          * remaining bits in the previous block, as such the |                          * remaining bits in the previous block, as such the | ||||||
|                          * toggle header flag cannot be used */ |                          * toggle header flag cannot be used */ | ||||||
| 			write_header(stream, level_buf->deflate_hdr, |                         write_header(stream, level_buf->deflate_hdr, level_buf->deflate_hdr_count, | ||||||
| 				     level_buf->deflate_hdr_count, |                                      level_buf->deflate_hdr_extra_bits, ZSTATE_FLUSH_ICF_BUFFER, 0); | ||||||
| 				     level_buf->deflate_hdr_extra_bits, |  | ||||||
| 				     ZSTATE_FLUSH_ICF_BUFFER, 0); |  | ||||||
|  |  | ||||||
|                 if (state->state == ZSTATE_FLUSH_ICF_BUFFER) |                 if (state->state == ZSTATE_FLUSH_ICF_BUFFER) | ||||||
|                         flush_icf_block(stream); |                         flush_icf_block(stream); | ||||||
| @@ -493,8 +523,7 @@ static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_s | |||||||
|                         write_stored_block(stream); |                         write_stored_block(stream); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| 	} |         } while (state->state == ZSTATE_NEW_HDR); | ||||||
| 	while (state->state == ZSTATE_NEW_HDR); |  | ||||||
|  |  | ||||||
|         if (state->state == ZSTATE_SYNC_FLUSH) |         if (state->state == ZSTATE_SYNC_FLUSH) | ||||||
|                 sync_flush(stream); |                 sync_flush(stream); | ||||||
| @@ -509,7 +538,8 @@ static void isal_deflate_icf_pass(struct isal_zstream *stream, uint8_t * inbuf_s | |||||||
|                 write_trailer(stream); |                 write_trailer(stream); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void isal_deflate_int(struct isal_zstream *stream, uint8_t * start_in) | static void | ||||||
|  | isal_deflate_int(struct isal_zstream *stream, uint8_t *start_in) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint32_t size; |         uint32_t size; | ||||||
| @@ -528,7 +558,8 @@ static void isal_deflate_int(struct isal_zstream *stream, uint8_t * start_in) | |||||||
|                 if (state->tmp_out_start == state->tmp_out_end) |                 if (state->tmp_out_start == state->tmp_out_end) | ||||||
|                         state->state -= ZSTATE_TMP_OFFSET; |                         state->state -= ZSTATE_TMP_OFFSET; | ||||||
|  |  | ||||||
| 		if (stream->avail_out == 0 || state->state == ZSTATE_END |                 if (stream->avail_out == 0 || | ||||||
|  |                     state->state == ZSTATE_END | ||||||
|                     // or do not write out empty blocks since the outbuffer was processed |                     // or do not write out empty blocks since the outbuffer was processed | ||||||
|                     || (state->state == ZSTATE_NEW_HDR && stream->avail_out == 0)) |                     || (state->state == ZSTATE_NEW_HDR && stream->avail_out == 0)) | ||||||
|                         return; |                         return; | ||||||
| @@ -576,14 +607,12 @@ static void isal_deflate_int(struct isal_zstream *stream, uint8_t * start_in) | |||||||
|                         state->tmp_out_start += size; |                         state->tmp_out_start += size; | ||||||
|                         if (state->tmp_out_start != state->tmp_out_end) |                         if (state->tmp_out_start != state->tmp_out_end) | ||||||
|                                 state->state += ZSTATE_TMP_OFFSET; |                                 state->state += ZSTATE_TMP_OFFSET; | ||||||
|  |                 } | ||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| } | static void | ||||||
|  | write_constant_compressed_stateless(struct isal_zstream *stream, uint32_t repeated_length) | ||||||
| static void write_constant_compressed_stateless(struct isal_zstream *stream, |  | ||||||
| 						uint32_t repeated_length) |  | ||||||
| { | { | ||||||
|         /* Assumes repeated_length is at least 1. |         /* Assumes repeated_length is at least 1. | ||||||
|          * Assumes the input end_of_stream is either 0 or 1. */ |          * Assumes the input end_of_stream is either 0 or 1. */ | ||||||
| @@ -636,13 +665,12 @@ static void write_constant_compressed_stateless(struct isal_zstream *stream, | |||||||
|  |  | ||||||
|                 if (rep_extra >= 230) { |                 if (rep_extra >= 230) { | ||||||
|                         write_bits(&state->bitbuf, |                         write_bits(&state->bitbuf, | ||||||
| 				   CODE_280 | ((rep_extra / 2 - 115) << |                                    CODE_280 | ((rep_extra / 2 - 115) << CODE_280_LENGTH), | ||||||
| 					       CODE_280_LENGTH), CODE_280_TOTAL_LENGTH); |                                    CODE_280_TOTAL_LENGTH); | ||||||
|                         rep_extra -= rep_extra / 2; |                         rep_extra -= rep_extra / 2; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| 		write_bits(&state->bitbuf, |                 write_bits(&state->bitbuf, CODE_280 | ((rep_extra - 115) << CODE_280_LENGTH), | ||||||
| 			   CODE_280 | ((rep_extra - 115) << CODE_280_LENGTH), |  | ||||||
|                            CODE_280_TOTAL_LENGTH); |                            CODE_280_TOTAL_LENGTH); | ||||||
|  |  | ||||||
|         } else { |         } else { | ||||||
| @@ -674,7 +702,8 @@ static void write_constant_compressed_stateless(struct isal_zstream *stream, | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int detect_repeated_char_length(uint8_t * in, uint32_t length) | static int | ||||||
|  | detect_repeated_char_length(uint8_t *in, uint32_t length) | ||||||
| { | { | ||||||
|         /* This currently assumes the first 8 bytes are the same character. |         /* This currently assumes the first 8 bytes are the same character. | ||||||
|          * This won't work effectively if the input stream isn't aligned well. */ |          * This won't work effectively if the input stream isn't aligned well. */ | ||||||
| @@ -683,16 +712,19 @@ static int detect_repeated_char_length(uint8_t * in, uint32_t length) | |||||||
|         uint64_t w = *p_64; |         uint64_t w = *p_64; | ||||||
|         uint8_t c = (uint8_t) w; |         uint8_t c = (uint8_t) w; | ||||||
|  |  | ||||||
| 	for (; (p_64 <= (uint64_t *) (end - 8)) && (w == *p_64); p_64++) ; |         for (; (p_64 <= (uint64_t *) (end - 8)) && (w == *p_64); p_64++) | ||||||
|  |                 ; | ||||||
|  |  | ||||||
|         p_8 = (uint8_t *) p_64; |         p_8 = (uint8_t *) p_64; | ||||||
|  |  | ||||||
| 	for (; (p_8 < end) && (c == *p_8); p_8++) ; |         for (; (p_8 < end) && (c == *p_8); p_8++) | ||||||
|  |                 ; | ||||||
|  |  | ||||||
|         return p_8 - in; |         return p_8 - in; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int isal_deflate_int_stateless(struct isal_zstream *stream) | static int | ||||||
|  | isal_deflate_int_stateless(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         uint32_t repeat_length; |         uint32_t repeat_length; | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
| @@ -701,9 +733,8 @@ static int isal_deflate_int_stateless(struct isal_zstream *stream) | |||||||
|                 if (write_stream_header_stateless(stream)) |                 if (write_stream_header_stateless(stream)) | ||||||
|                         return STATELESS_OVERFLOW; |                         return STATELESS_OVERFLOW; | ||||||
|  |  | ||||||
| 	if (stream->avail_in >= 8 |         if (stream->avail_in >= 8 && (load_native_u64(stream->next_in) == 0 || | ||||||
| 	    && (load_native_u64(stream->next_in) == 0 |                                       load_native_u64(stream->next_in) == ~(uint64_t) 0)) { | ||||||
| 		|| load_native_u64(stream->next_in) == ~(uint64_t) 0)) { |  | ||||||
|                 repeat_length = detect_repeated_char_length(stream->next_in, stream->avail_in); |                 repeat_length = detect_repeated_char_length(stream->next_in, stream->avail_in); | ||||||
|  |  | ||||||
|                 if (stream->avail_in == repeat_length || repeat_length >= MIN_REPEAT_LEN) |                 if (stream->avail_in == repeat_length || repeat_length >= MIN_REPEAT_LEN) | ||||||
| @@ -727,17 +758,17 @@ static int isal_deflate_int_stateless(struct isal_zstream *stream) | |||||||
|  |  | ||||||
|                 state->count = 0; |                 state->count = 0; | ||||||
|                 isal_deflate_icf_pass(stream, stream->next_in); |                 isal_deflate_icf_pass(stream, stream->next_in); | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	if (state->state == ZSTATE_END |         if (state->state == ZSTATE_END || | ||||||
| 	    || (state->state == ZSTATE_NEW_HDR && stream->flush == FULL_FLUSH)) |             (state->state == ZSTATE_NEW_HDR && stream->flush == FULL_FLUSH)) | ||||||
|                 return COMP_OK; |                 return COMP_OK; | ||||||
|         else |         else | ||||||
|                 return STATELESS_OVERFLOW; |                 return STATELESS_OVERFLOW; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void write_type0_header(struct isal_zstream *stream) | static void | ||||||
|  | write_type0_header(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint64_t stored_blk_hdr; |         uint64_t stored_blk_hdr; | ||||||
| @@ -791,7 +822,8 @@ static void write_type0_header(struct isal_zstream *stream) | |||||||
|         stream->internal_state.count = copy_size; |         stream->internal_state.count = copy_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| static uint32_t write_stored_block(struct isal_zstream *stream) | static uint32_t | ||||||
|  | write_stored_block(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         uint32_t copy_size, avail_in, block_next_offset; |         uint32_t copy_size, avail_in, block_next_offset; | ||||||
|         uint8_t *next_in; |         uint8_t *next_in; | ||||||
| @@ -813,8 +845,7 @@ static uint32_t write_stored_block(struct isal_zstream *stream) | |||||||
|  |  | ||||||
|                 if (copy_size > stream->avail_out || copy_size > avail_in) { |                 if (copy_size > stream->avail_out || copy_size > avail_in) { | ||||||
|                         state->count = copy_size; |                         state->count = copy_size; | ||||||
| 			copy_size = (stream->avail_out <= avail_in) ? |                         copy_size = (stream->avail_out <= avail_in) ? stream->avail_out : avail_in; | ||||||
| 			    stream->avail_out : avail_in; |  | ||||||
|  |  | ||||||
|                         memcpy(stream->next_out, next_in, copy_size); |                         memcpy(stream->next_out, next_in, copy_size); | ||||||
|                         state->count -= copy_size; |                         state->count -= copy_size; | ||||||
| @@ -832,8 +863,8 @@ static uint32_t write_stored_block(struct isal_zstream *stream) | |||||||
|  |  | ||||||
|                 if (state->block_next == state->block_end) { |                 if (state->block_next == state->block_end) { | ||||||
|                         state->state = state->has_eob_hdr ? ZSTATE_TRL : ZSTATE_NEW_HDR; |                         state->state = state->has_eob_hdr ? ZSTATE_TRL : ZSTATE_NEW_HDR; | ||||||
| 			if (stream->flush == FULL_FLUSH && state->state == ZSTATE_NEW_HDR |                         if (stream->flush == FULL_FLUSH && state->state == ZSTATE_NEW_HDR && | ||||||
| 			    && are_buffers_empty(stream)) { |                             are_buffers_empty(stream)) { | ||||||
|                                 /* Clear match history so there are no cross |                                 /* Clear match history so there are no cross | ||||||
|                                  * block length distance pairs */ |                                  * block length distance pairs */ | ||||||
|                                 reset_match_history(stream); |                                 reset_match_history(stream); | ||||||
| @@ -844,7 +875,8 @@ static uint32_t write_stored_block(struct isal_zstream *stream) | |||||||
|         return state->block_end - state->block_next; |         return state->block_end - state->block_next; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void reset_match_history(struct isal_zstream *stream) | static inline void | ||||||
|  | reset_match_history(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
| @@ -878,20 +910,17 @@ static inline void reset_match_history(struct isal_zstream *stream) | |||||||
|                 uint16_t hash_init_val; |                 uint16_t hash_init_val; | ||||||
|  |  | ||||||
|                 hash_init_val = stream->total_in & 0xffff; |                 hash_init_val = stream->total_in & 0xffff; | ||||||
| 		wmemset((wchar_t *)hash_table, hash_init_val, |                 wmemset((wchar_t *) hash_table, hash_init_val, hash_table_size / sizeof(wchar_t)); | ||||||
| 			hash_table_size / sizeof(wchar_t)); |  | ||||||
|  |  | ||||||
|         } else if (sizeof(wchar_t) == 4) { |         } else if (sizeof(wchar_t) == 4) { | ||||||
|                 uint32_t hash_init_val; |                 uint32_t hash_init_val; | ||||||
|                 int rep_bits; |                 int rep_bits; | ||||||
|  |  | ||||||
|                 hash_init_val = stream->total_in & 0xffff; |                 hash_init_val = stream->total_in & 0xffff; | ||||||
| 		for (rep_bits = sizeof(uint16_t) * 8; rep_bits < sizeof(wchar_t) * 8; |                 for (rep_bits = sizeof(uint16_t) * 8; rep_bits < sizeof(wchar_t) * 8; rep_bits *= 2) | ||||||
| 		     rep_bits *= 2) |  | ||||||
|                         hash_init_val |= hash_init_val << rep_bits; |                         hash_init_val |= hash_init_val << rep_bits; | ||||||
|  |  | ||||||
| 		wmemset((wchar_t *)hash_table, hash_init_val, |                 wmemset((wchar_t *) hash_table, hash_init_val, hash_table_size / sizeof(wchar_t)); | ||||||
| 			hash_table_size / sizeof(wchar_t)); |  | ||||||
|         } else { |         } else { | ||||||
|                 if ((stream->total_in & 0xFFFF) == 0) |                 if ((stream->total_in & 0xFFFF) == 0) | ||||||
|                         memset(hash_table, 0, hash_table_size); |                         memset(hash_table, 0, hash_table_size); | ||||||
| @@ -902,7 +931,6 @@ static inline void reset_match_history(struct isal_zstream *stream) | |||||||
|                         } |                         } | ||||||
|                 } |                 } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static void inline set_dist_mask(struct isal_zstream *stream) | static void inline set_dist_mask(struct isal_zstream *stream) | ||||||
| @@ -939,7 +967,8 @@ static void inline set_hash_mask(struct isal_zstream *stream) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_init(struct isal_zstream *stream) | void | ||||||
|  | isal_deflate_init(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|  |  | ||||||
| @@ -977,7 +1006,8 @@ void isal_deflate_init(struct isal_zstream *stream) | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_reset(struct isal_zstream *stream) | void | ||||||
|  | isal_deflate_reset(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|  |  | ||||||
| @@ -1003,10 +1033,10 @@ void isal_deflate_reset(struct isal_zstream *stream) | |||||||
|         init(&state->bitbuf); |         init(&state->bitbuf); | ||||||
|  |  | ||||||
|         state->crc = 0; |         state->crc = 0; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_gzip_header_init(struct isal_gzip_header *gz_hdr) | void | ||||||
|  | isal_gzip_header_init(struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         gz_hdr->text = 0; |         gz_hdr->text = 0; | ||||||
|         gz_hdr->time = 0; |         gz_hdr->time = 0; | ||||||
| @@ -1023,7 +1053,8 @@ void isal_gzip_header_init(struct isal_gzip_header *gz_hdr) | |||||||
|         gz_hdr->flags = 0; |         gz_hdr->flags = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_zlib_header_init(struct isal_zlib_header *z_hdr) | void | ||||||
|  | isal_zlib_header_init(struct isal_zlib_header *z_hdr) | ||||||
| { | { | ||||||
|         z_hdr->info = 0; |         z_hdr->info = 0; | ||||||
|         z_hdr->level = 0; |         z_hdr->level = 0; | ||||||
| @@ -1031,7 +1062,8 @@ void isal_zlib_header_init(struct isal_zlib_header *z_hdr) | |||||||
|         z_hdr->dict_flag = 0; |         z_hdr->dict_flag = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| uint32_t isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_header *gz_hdr) | uint32_t | ||||||
|  | isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         uint32_t flags = 0, hcrc, hdr_size = GZIP_HDR_BASE; |         uint32_t flags = 0, hcrc, hdr_size = GZIP_HDR_BASE; | ||||||
|         uint8_t *out_buf = stream->next_out, *out_buf_start = stream->next_out; |         uint8_t *out_buf = stream->next_out, *out_buf_start = stream->next_out; | ||||||
| @@ -1105,7 +1137,8 @@ uint32_t isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_he | |||||||
|         return ISAL_DECOMP_OK; |         return ISAL_DECOMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| uint32_t isal_write_zlib_header(struct isal_zstream *stream, struct isal_zlib_header *z_hdr) | uint32_t | ||||||
|  | isal_write_zlib_header(struct isal_zstream *stream, struct isal_zlib_header *z_hdr) | ||||||
| { | { | ||||||
|         uint32_t cmf, flg, dict_flag = 0, hdr_size = ZLIB_HDR_BASE; |         uint32_t cmf, flg, dict_flag = 0, hdr_size = ZLIB_HDR_BASE; | ||||||
|         uint8_t *out_buf = stream->next_out; |         uint8_t *out_buf = stream->next_out; | ||||||
| @@ -1136,8 +1169,9 @@ uint32_t isal_write_zlib_header(struct isal_zstream *stream, struct isal_zlib_he | |||||||
|         return ISAL_DECOMP_OK; |         return ISAL_DECOMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_set_hufftables(struct isal_zstream *stream, | int | ||||||
| 				struct isal_hufftables *hufftables, int type) | isal_deflate_set_hufftables(struct isal_zstream *stream, struct isal_hufftables *hufftables, | ||||||
|  |                             int type) | ||||||
| { | { | ||||||
|         if (stream->internal_state.state != ZSTATE_NEW_HDR) |         if (stream->internal_state.state != ZSTATE_NEW_HDR) | ||||||
|                 return ISAL_INVALID_OPERATION; |                 return ISAL_INVALID_OPERATION; | ||||||
| @@ -1161,7 +1195,8 @@ int isal_deflate_set_hufftables(struct isal_zstream *stream, | |||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_stateless_init(struct isal_zstream *stream) | void | ||||||
|  | isal_deflate_stateless_init(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         stream->total_in = 0; |         stream->total_in = 0; | ||||||
|         stream->total_out = 0; |         stream->total_out = 0; | ||||||
| @@ -1178,7 +1213,8 @@ void isal_deflate_stateless_init(struct isal_zstream *stream) | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_hash(struct isal_zstream *stream, uint8_t * dict, uint32_t dict_len) | void | ||||||
|  | isal_deflate_hash(struct isal_zstream *stream, uint8_t *dict, uint32_t dict_len) | ||||||
| { | { | ||||||
|         /* Reset history to prevent out of bounds matches this works because |         /* Reset history to prevent out of bounds matches this works because | ||||||
|          * dictionary must set at least 1 element in the history */ |          * dictionary must set at least 1 element in the history */ | ||||||
| @@ -1188,35 +1224,34 @@ void isal_deflate_hash(struct isal_zstream *stream, uint8_t * dict, uint32_t dic | |||||||
|         switch (stream->level) { |         switch (stream->level) { | ||||||
|         case 3: |         case 3: | ||||||
|                 memset(level_buf->lvl3.hash_table, -1, sizeof(level_buf->lvl3.hash_table)); |                 memset(level_buf->lvl3.hash_table, -1, sizeof(level_buf->lvl3.hash_table)); | ||||||
| 		isal_deflate_hash_lvl3(level_buf->lvl3.hash_table, hash_mask, |                 isal_deflate_hash_lvl3(level_buf->lvl3.hash_table, hash_mask, stream->total_in, | ||||||
| 				       stream->total_in, dict, dict_len); |                                        dict, dict_len); | ||||||
|                 break; |                 break; | ||||||
|  |  | ||||||
|         case 2: |         case 2: | ||||||
|                 memset(level_buf->lvl2.hash_table, -1, sizeof(level_buf->lvl2.hash_table)); |                 memset(level_buf->lvl2.hash_table, -1, sizeof(level_buf->lvl2.hash_table)); | ||||||
| 		isal_deflate_hash_lvl2(level_buf->lvl2.hash_table, hash_mask, |                 isal_deflate_hash_lvl2(level_buf->lvl2.hash_table, hash_mask, stream->total_in, | ||||||
| 				       stream->total_in, dict, dict_len); |                                        dict, dict_len); | ||||||
|                 break; |                 break; | ||||||
|         case 1: |         case 1: | ||||||
|                 memset(level_buf->lvl1.hash_table, -1, sizeof(level_buf->lvl1.hash_table)); |                 memset(level_buf->lvl1.hash_table, -1, sizeof(level_buf->lvl1.hash_table)); | ||||||
| 		isal_deflate_hash_lvl1(level_buf->lvl1.hash_table, hash_mask, |                 isal_deflate_hash_lvl1(level_buf->lvl1.hash_table, hash_mask, stream->total_in, | ||||||
| 				       stream->total_in, dict, dict_len); |                                        dict, dict_len); | ||||||
|                 break; |                 break; | ||||||
|         default: |         default: | ||||||
|                 memset(stream->internal_state.head, -1, sizeof(stream->internal_state.head)); |                 memset(stream->internal_state.head, -1, sizeof(stream->internal_state.head)); | ||||||
| 		isal_deflate_hash_lvl0(stream->internal_state.head, hash_mask, |                 isal_deflate_hash_lvl0(stream->internal_state.head, hash_mask, stream->total_in, | ||||||
| 				       stream->total_in, dict, dict_len); |                                        dict, dict_len); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         stream->internal_state.has_hist = IGZIP_HIST; |         stream->internal_state.has_hist = IGZIP_HIST; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_process_dict(struct isal_zstream *stream, struct isal_dict *dict, | int | ||||||
| 			      uint8_t * dict_data, uint32_t dict_len) | isal_deflate_process_dict(struct isal_zstream *stream, struct isal_dict *dict, uint8_t *dict_data, | ||||||
|  |                           uint32_t dict_len) | ||||||
| { | { | ||||||
| 	if ((dict == NULL) |         if ((dict == NULL) || (dict_len == 0) || (dict->level > ISAL_DEF_MAX_LEVEL)) | ||||||
| 	    || (dict_len == 0) |  | ||||||
| 	    || (dict->level > ISAL_DEF_MAX_LEVEL)) |  | ||||||
|                 return ISAL_INVALID_STATE; |                 return ISAL_INVALID_STATE; | ||||||
|  |  | ||||||
|         if (dict_len > IGZIP_HIST_SIZE) { |         if (dict_len > IGZIP_HIST_SIZE) { | ||||||
| @@ -1232,40 +1267,35 @@ int isal_deflate_process_dict(struct isal_zstream *stream, struct isal_dict *dic | |||||||
|         switch (stream->level) { |         switch (stream->level) { | ||||||
|         case 3: |         case 3: | ||||||
|                 dict->hash_size = IGZIP_LVL3_HASH_SIZE; |                 dict->hash_size = IGZIP_LVL3_HASH_SIZE; | ||||||
| 		isal_deflate_hash_lvl3(dict->hashtable, LVL3_HASH_MASK, |                 isal_deflate_hash_lvl3(dict->hashtable, LVL3_HASH_MASK, 0, dict_data, dict_len); | ||||||
| 				       0, dict_data, dict_len); |  | ||||||
|                 break; |                 break; | ||||||
|  |  | ||||||
|         case 2: |         case 2: | ||||||
|                 dict->hash_size = IGZIP_LVL2_HASH_SIZE; |                 dict->hash_size = IGZIP_LVL2_HASH_SIZE; | ||||||
| 		isal_deflate_hash_lvl2(dict->hashtable, LVL2_HASH_MASK, |                 isal_deflate_hash_lvl2(dict->hashtable, LVL2_HASH_MASK, 0, dict_data, dict_len); | ||||||
| 				       0, dict_data, dict_len); |  | ||||||
|                 break; |                 break; | ||||||
|         case 1: |         case 1: | ||||||
|                 dict->hash_size = IGZIP_LVL1_HASH_SIZE; |                 dict->hash_size = IGZIP_LVL1_HASH_SIZE; | ||||||
| 		isal_deflate_hash_lvl1(dict->hashtable, LVL1_HASH_MASK, |                 isal_deflate_hash_lvl1(dict->hashtable, LVL1_HASH_MASK, 0, dict_data, dict_len); | ||||||
| 				       0, dict_data, dict_len); |  | ||||||
|                 break; |                 break; | ||||||
|         default: |         default: | ||||||
|                 dict->hash_size = IGZIP_LVL0_HASH_SIZE; |                 dict->hash_size = IGZIP_LVL0_HASH_SIZE; | ||||||
| 		isal_deflate_hash_lvl0(dict->hashtable, LVL0_HASH_MASK, |                 isal_deflate_hash_lvl0(dict->hashtable, LVL0_HASH_MASK, 0, dict_data, dict_len); | ||||||
| 				       0, dict_data, dict_len); |  | ||||||
|         } |         } | ||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_reset_dict(struct isal_zstream *stream, struct isal_dict *dict) | int | ||||||
|  | isal_deflate_reset_dict(struct isal_zstream *stream, struct isal_dict *dict) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
|         int ret; |         int ret; | ||||||
|  |  | ||||||
| 	if ((state->state != ZSTATE_NEW_HDR) |         if ((state->state != ZSTATE_NEW_HDR) || | ||||||
| 	    || (state->b_bytes_processed != state->b_bytes_valid) |             (state->b_bytes_processed != state->b_bytes_valid) || (dict->level != stream->level) || | ||||||
| 	    || (dict->level != stream->level) |             (dict->hist_size == 0) || (dict->hist_size > IGZIP_HIST_SIZE) || | ||||||
| 	    || (dict->hist_size == 0) |             (dict->hash_size > IGZIP_LVL3_HASH_SIZE)) | ||||||
| 	    || (dict->hist_size > IGZIP_HIST_SIZE) |  | ||||||
| 	    || (dict->hash_size > IGZIP_LVL3_HASH_SIZE)) |  | ||||||
|                 return ISAL_INVALID_STATE; |                 return ISAL_INVALID_STATE; | ||||||
|  |  | ||||||
|         ret = check_level_req(stream); |         ret = check_level_req(stream); | ||||||
| @@ -1299,7 +1329,8 @@ int isal_deflate_reset_dict(struct isal_zstream *stream, struct isal_dict *dict) | |||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_set_dict(struct isal_zstream *stream, uint8_t * dict, uint32_t dict_len) | int | ||||||
|  | isal_deflate_set_dict(struct isal_zstream *stream, uint8_t *dict, uint32_t dict_len) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|  |  | ||||||
| @@ -1323,7 +1354,8 @@ int isal_deflate_set_dict(struct isal_zstream *stream, uint8_t * dict, uint32_t | |||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_stateless(struct isal_zstream *stream) | int | ||||||
|  | isal_deflate_stateless(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint8_t *next_in = stream->next_in; |         uint8_t *next_in = stream->next_in; | ||||||
| @@ -1373,8 +1405,8 @@ int isal_deflate_stateless(struct isal_zstream *stream) | |||||||
|         if (avail_in == 0) |         if (avail_in == 0) | ||||||
|                 stored_len = TYPE0_BLK_HDR_LEN; |                 stored_len = TYPE0_BLK_HDR_LEN; | ||||||
|         else { |         else { | ||||||
| 		stored_len = TYPE0_BLK_HDR_LEN * ((avail_in + TYPE0_MAX_BLK_LEN - 1) / |                 stored_len = TYPE0_BLK_HDR_LEN * | ||||||
| 						  TYPE0_MAX_BLK_LEN); |                              ((avail_in + TYPE0_MAX_BLK_LEN - 1) / TYPE0_MAX_BLK_LEN); | ||||||
|                 stored_len += avail_in; |                 stored_len += avail_in; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -1446,11 +1478,10 @@ int isal_deflate_stateless(struct isal_zstream *stream) | |||||||
|                 write_trailer(stream); |                 write_trailer(stream); | ||||||
|  |  | ||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t get_hist_size(struct isal_zstream *stream, uint8_t * start_in, | static inline uint32_t | ||||||
| 				     int32_t buf_hist_start) | get_hist_size(struct isal_zstream *stream, uint8_t *start_in, int32_t buf_hist_start) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint32_t history_size; |         uint32_t history_size; | ||||||
| @@ -1467,20 +1498,20 @@ static inline uint32_t get_hist_size(struct isal_zstream *stream, uint8_t * star | |||||||
|                 history_size = IGZIP_HIST_SIZE; |                 history_size = IGZIP_HIST_SIZE; | ||||||
|  |  | ||||||
|         /* Calculate history required based on internal state */ |         /* Calculate history required based on internal state */ | ||||||
| 	if (state->state == ZSTATE_TYPE0_HDR |         if (state->state == ZSTATE_TYPE0_HDR || state->state == ZSTATE_TYPE0_BODY || | ||||||
| 	    || state->state == ZSTATE_TYPE0_BODY |             state->state == ZSTATE_TMP_TYPE0_HDR || state->state == ZSTATE_TMP_TYPE0_BODY) { | ||||||
| 	    || state->state == ZSTATE_TMP_TYPE0_HDR || state->state == ZSTATE_TMP_TYPE0_BODY) { |  | ||||||
|                 if (stream->total_in - state->block_next > history_size) { |                 if (stream->total_in - state->block_next > history_size) { | ||||||
|                         history_size = (stream->total_in - state->block_next); |                         history_size = (stream->total_in - state->block_next); | ||||||
|                 } |                 } | ||||||
| 	} else if (stream->avail_in + buffered_size == 0 |         } else if (stream->avail_in + buffered_size == 0 && | ||||||
| 		   && (stream->end_of_stream || stream->flush == FULL_FLUSH)) { |                    (stream->end_of_stream || stream->flush == FULL_FLUSH)) { | ||||||
|                 history_size = 0; |                 history_size = 0; | ||||||
|         } |         } | ||||||
|         return history_size; |         return history_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate(struct isal_zstream *stream) | int | ||||||
|  | isal_deflate(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         int ret = COMP_OK; |         int ret = COMP_OK; | ||||||
| @@ -1511,8 +1542,8 @@ int isal_deflate(struct isal_zstream *stream) | |||||||
|         if (state->has_hist == IGZIP_NO_HIST) { |         if (state->has_hist == IGZIP_NO_HIST) { | ||||||
|                 set_dist_mask(stream); |                 set_dist_mask(stream); | ||||||
|                 set_hash_mask(stream); |                 set_hash_mask(stream); | ||||||
| 		if (state->hash_mask > 2 * stream->avail_in |                 if (state->hash_mask > 2 * stream->avail_in && | ||||||
| 		    && (stream->flush == FULL_FLUSH || stream->end_of_stream)) |                     (stream->flush == FULL_FLUSH || stream->end_of_stream)) | ||||||
|                         state->hash_mask = (1 << bsr(2 * stream->avail_in)) - 1; |                         state->hash_mask = (1 << bsr(2 * stream->avail_in)) - 1; | ||||||
|                 stream->total_in -= buffered_size; |                 stream->total_in -= buffered_size; | ||||||
|                 reset_match_history(stream); |                 reset_match_history(stream); | ||||||
| @@ -1580,10 +1611,10 @@ int isal_deflate(struct isal_zstream *stream) | |||||||
|                         /* If not much data is buffered and there is no need to |                         /* If not much data is buffered and there is no need to | ||||||
|                          * flush the buffer, just continue rather than attempt |                          * flush the buffer, just continue rather than attempt | ||||||
|                          * to compress */ |                          * to compress */ | ||||||
| 			if (avail_in == 0 && buffered_size <= IGZIP_HIST_SIZE |                         if (avail_in == 0 && buffered_size <= IGZIP_HIST_SIZE && | ||||||
| 			    && stream->total_in - buffered_size - state->block_next <= |                             stream->total_in - buffered_size - state->block_next <= | ||||||
| 			    IGZIP_HIST_SIZE && !stream->end_of_stream |                                     IGZIP_HIST_SIZE && | ||||||
| 			    && stream->flush == NO_FLUSH) |                             !stream->end_of_stream && stream->flush == NO_FLUSH) | ||||||
|                                 continue; |                                 continue; | ||||||
|  |  | ||||||
|                         if (avail_in) { |                         if (avail_in) { | ||||||
| @@ -1630,8 +1661,8 @@ int isal_deflate(struct isal_zstream *stream) | |||||||
|                 in_size = stream->avail_in + buffered_size; |                 in_size = stream->avail_in + buffered_size; | ||||||
|                 out_size = stream->total_out; |                 out_size = stream->total_out; | ||||||
|  |  | ||||||
| 	} while (internal && stream->avail_in > 0 && stream->avail_out > 0 |         } while (internal && stream->avail_in > 0 && stream->avail_out > 0 && | ||||||
| 		 && (in_size_initial != in_size || out_size_initial != out_size)); |                  (in_size_initial != in_size || out_size_initial != out_size)); | ||||||
|  |  | ||||||
|         /* Buffer history if data was pulled from the external buffer and future |         /* Buffer history if data was pulled from the external buffer and future | ||||||
|          * calls to deflate will be required */ |          * calls to deflate will be required */ | ||||||
| @@ -1670,14 +1701,14 @@ int isal_deflate(struct isal_zstream *stream) | |||||||
|                 stream->next_in += future_size; |                 stream->next_in += future_size; | ||||||
|                 stream->total_in += future_size; |                 stream->total_in += future_size; | ||||||
|                 stream->avail_in -= future_size; |                 stream->avail_in -= future_size; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| // Helper function to avoid code duplication. | // Helper function to avoid code duplication. | ||||||
| static void _zlib_header_in_buffer(struct isal_zstream *stream, uint8_t * buffer) | static void | ||||||
|  | _zlib_header_in_buffer(struct isal_zstream *stream, uint8_t *buffer) | ||||||
| { | { | ||||||
|         uint8_t hist_bits, info, level, cmf, flg; |         uint8_t hist_bits, info, level, cmf, flg; | ||||||
|         uint8_t dict_flag = 0; |         uint8_t dict_flag = 0; | ||||||
| @@ -1703,15 +1734,13 @@ static void _zlib_header_in_buffer(struct isal_zstream *stream, uint8_t * buffer | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int write_stream_header_stateless(struct isal_zstream *stream) | static int | ||||||
|  | write_stream_header_stateless(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         uint32_t hdr_bytes; |         uint32_t hdr_bytes; | ||||||
|         // Create a 10-byte buffer. Since the gzip header is almost fixed (9 of 10 |         // Create a 10-byte buffer. Since the gzip header is almost fixed (9 of 10 | ||||||
|         // bytes are fixed) use it to initialize the buffer. |         // bytes are fixed) use it to initialize the buffer. | ||||||
| 	uint8_t buffer[10] = { |         uint8_t buffer[10] = { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff }; | ||||||
| 		0x1f, 0x8b, 0x08, 0x00, 0x00, |  | ||||||
| 		0x00, 0x00, 0x00, 0x00, 0xff |  | ||||||
| 	}; |  | ||||||
|         uint32_t next_flag; |         uint32_t next_flag; | ||||||
|  |  | ||||||
|         if (stream->internal_state.has_wrap_hdr) |         if (stream->internal_state.has_wrap_hdr) | ||||||
| @@ -1743,17 +1772,15 @@ static int write_stream_header_stateless(struct isal_zstream *stream) | |||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void write_stream_header(struct isal_zstream *stream) | static void | ||||||
|  | write_stream_header(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         int bytes_to_write; |         int bytes_to_write; | ||||||
|         uint32_t hdr_bytes; |         uint32_t hdr_bytes; | ||||||
|         // Create a 10-byte buffer. Since the gzip header is almost fixed (9 of 10 |         // Create a 10-byte buffer. Since the gzip header is almost fixed (9 of 10 | ||||||
|         // bytes are fixed) use it to initialize the buffer. |         // bytes are fixed) use it to initialize the buffer. | ||||||
| 	uint8_t buffer[10] = { |         uint8_t buffer[10] = { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff }; | ||||||
| 		0x1f, 0x8b, 0x08, 0x00, 0x00, |  | ||||||
| 		0x00, 0x00, 0x00, 0x00, 0xff |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
|         if (stream->internal_state.has_wrap_hdr) |         if (stream->internal_state.has_wrap_hdr) | ||||||
|                 return; |                 return; | ||||||
| @@ -1784,10 +1811,10 @@ static void write_stream_header(struct isal_zstream *stream) | |||||||
|         stream->avail_out -= bytes_to_write; |         stream->avail_out -= bytes_to_write; | ||||||
|         stream->total_out += bytes_to_write; |         stream->total_out += bytes_to_write; | ||||||
|         stream->next_out += bytes_to_write; |         stream->next_out += bytes_to_write; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static int write_deflate_header_stateless(struct isal_zstream *stream) | static int | ||||||
|  | write_deflate_header_stateless(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct isal_hufftables *hufftables = stream->hufftables; |         struct isal_hufftables *hufftables = stream->hufftables; | ||||||
| @@ -1825,7 +1852,8 @@ static int write_deflate_header_stateless(struct isal_zstream *stream) | |||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream) | static int | ||||||
|  | write_deflate_header_unaligned_stateless(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         struct isal_hufftables *hufftables = stream->hufftables; |         struct isal_hufftables *hufftables = stream->hufftables; | ||||||
| @@ -1863,14 +1891,12 @@ static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream) | |||||||
|                 write_bits(&state->bitbuf, header_bits, 32); |                 write_bits(&state->bitbuf, header_bits, 32); | ||||||
|                 header_bits = load_le_u64(header_next); |                 header_bits = load_le_u64(header_next); | ||||||
|         } |         } | ||||||
| 	bit_count = |         bit_count = (hufftables->deflate_hdr_count & 0x7) * 8 + hufftables->deflate_hdr_extra_bits; | ||||||
| 	    (hufftables->deflate_hdr_count & 0x7) * 8 + hufftables->deflate_hdr_extra_bits; |  | ||||||
|  |  | ||||||
|         if (bit_count > MAX_BITBUF_BIT_WRITE) { |         if (bit_count > MAX_BITBUF_BIT_WRITE) { | ||||||
|                 write_bits(&state->bitbuf, header_bits, MAX_BITBUF_BIT_WRITE); |                 write_bits(&state->bitbuf, header_bits, MAX_BITBUF_BIT_WRITE); | ||||||
|                 header_bits >>= MAX_BITBUF_BIT_WRITE; |                 header_bits >>= MAX_BITBUF_BIT_WRITE; | ||||||
|                 bit_count -= MAX_BITBUF_BIT_WRITE; |                 bit_count -= MAX_BITBUF_BIT_WRITE; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         write_bits(&state->bitbuf, header_bits, bit_count); |         write_bits(&state->bitbuf, header_bits, bit_count); | ||||||
| @@ -1891,9 +1917,9 @@ static int write_deflate_header_unaligned_stateless(struct isal_zstream *stream) | |||||||
| } | } | ||||||
|  |  | ||||||
| /* Toggle end of stream only works when deflate header is aligned */ | /* Toggle end of stream only works when deflate header is aligned */ | ||||||
| static void write_header(struct isal_zstream *stream, uint8_t * deflate_hdr, | static void | ||||||
| 			 uint32_t deflate_hdr_count, uint32_t extra_bits_count, | write_header(struct isal_zstream *stream, uint8_t *deflate_hdr, uint32_t deflate_hdr_count, | ||||||
| 			 uint32_t next_state, uint32_t toggle_end_of_stream) |              uint32_t extra_bits_count, uint32_t next_state, uint32_t toggle_end_of_stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint32_t hdr_extra_bits = deflate_hdr[deflate_hdr_count]; |         uint32_t hdr_extra_bits = deflate_hdr[deflate_hdr_count]; | ||||||
| @@ -1954,10 +1980,10 @@ static void write_header(struct isal_zstream *stream, uint8_t * deflate_hdr, | |||||||
|                 stream->avail_out -= count; |                 stream->avail_out -= count; | ||||||
|                 stream->total_out += count; |                 stream->total_out += count; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static void write_trailer(struct isal_zstream *stream) | static void | ||||||
|  | write_trailer(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         unsigned int bytes = 0; |         unsigned int bytes = 0; | ||||||
| @@ -2002,8 +2028,7 @@ static void write_trailer(struct isal_zstream *stream) | |||||||
|         case IGZIP_GZIP: |         case IGZIP_GZIP: | ||||||
|         case IGZIP_GZIP_NO_HDR: |         case IGZIP_GZIP_NO_HDR: | ||||||
|                 if (stream->avail_out - bytes >= gzip_trl_bytes) { |                 if (stream->avail_out - bytes >= gzip_trl_bytes) { | ||||||
| 			store_le_u64(stream->next_out, |                         store_le_u64(stream->next_out, ((uint64_t) stream->total_in << 32) | crc); | ||||||
| 				     ((uint64_t) stream->total_in << 32) | crc); |  | ||||||
|                         stream->next_out += gzip_trl_bytes; |                         stream->next_out += gzip_trl_bytes; | ||||||
|                         bytes += gzip_trl_bytes; |                         bytes += gzip_trl_bytes; | ||||||
|                         state->state = ZSTATE_END; |                         state->state = ZSTATE_END; | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ | |||||||
|  |  | ||||||
| extern const struct isal_hufftables hufftables_default; | extern const struct isal_hufftables hufftables_default; | ||||||
|  |  | ||||||
| static inline void update_state(struct isal_zstream *stream, uint8_t * start_in, | static inline void | ||||||
| 				uint8_t * next_in, uint8_t * end_in) | 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; |         struct isal_zstate *state = &stream->internal_state; | ||||||
|         uint32_t bytes_written; |         uint32_t bytes_written; | ||||||
| @@ -23,10 +23,10 @@ static inline void update_state(struct isal_zstream *stream, uint8_t * start_in, | |||||||
|         stream->total_out += bytes_written; |         stream->total_out += bytes_written; | ||||||
|         stream->next_out += bytes_written; |         stream->next_out += bytes_written; | ||||||
|         stream->avail_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; |         uint32_t literal, hash; | ||||||
|         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; |         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; | ||||||
| @@ -84,8 +84,7 @@ void isal_deflate_body_base(struct isal_zstream *stream) | |||||||
|                                         last_seen[hash] = (uint64_t) (next_hash - file_start); |                                         last_seen[hash] = (uint64_t) (next_hash - file_start); | ||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
| 				get_len_code(stream->hufftables, match_length, &code, |                                 get_len_code(stream->hufftables, match_length, &code, &code_len); | ||||||
| 					     &code_len); |  | ||||||
|                                 get_dist_code(stream->hufftables, dist, &code2, &code_len2); |                                 get_dist_code(stream->hufftables, dist, &code2, &code_len2); | ||||||
|  |  | ||||||
|                                 code |= code2 << code_len; |                                 code |= code2 << code_len; | ||||||
| @@ -111,10 +110,10 @@ void isal_deflate_body_base(struct isal_zstream *stream) | |||||||
|                 state->state = ZSTATE_FLUSH_READ_BUFFER; |                 state->state = ZSTATE_FLUSH_READ_BUFFER; | ||||||
|  |  | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_finish_base(struct isal_zstream *stream) | void | ||||||
|  | isal_deflate_finish_base(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         uint32_t literal = 0, hash; |         uint32_t literal = 0, hash; | ||||||
|         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; |         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; | ||||||
| @@ -145,7 +144,8 @@ void isal_deflate_finish_base(struct isal_zstream *stream) | |||||||
|                         dist = (next_in - file_start - last_seen[hash]) & 0xFFFF; |                         dist = (next_in - file_start - last_seen[hash]) & 0xFFFF; | ||||||
|                         last_seen[hash] = (uint64_t) (next_in - file_start); |                         last_seen[hash] = (uint64_t) (next_in - file_start); | ||||||
|  |  | ||||||
| 			if (dist - 1 < hist_size) {	/* The -1 are to handle the case when dist = 0 */ |                         if (dist - 1 < | ||||||
|  |                             hist_size) { /* The -1 are to handle the case when dist = 0 */ | ||||||
|                                 match_length = |                                 match_length = | ||||||
|                                         compare258(next_in - dist, next_in, end_in - next_in); |                                         compare258(next_in - dist, next_in, end_in - next_in); | ||||||
|  |  | ||||||
| @@ -167,8 +167,7 @@ void isal_deflate_finish_base(struct isal_zstream *stream) | |||||||
|  |  | ||||||
|                                         get_len_code(stream->hufftables, match_length, &code, |                                         get_len_code(stream->hufftables, match_length, &code, | ||||||
|                                                      &code_len); |                                                      &code_len); | ||||||
| 					get_dist_code(stream->hufftables, dist, &code2, |                                         get_dist_code(stream->hufftables, dist, &code2, &code_len2); | ||||||
| 						      &code_len2); |  | ||||||
|  |  | ||||||
|                                         code |= code2 << code_len; |                                         code |= code2 << code_len; | ||||||
|                                         code_len += code_len2; |                                         code_len += code_len2; | ||||||
| @@ -184,7 +183,6 @@ void isal_deflate_finish_base(struct isal_zstream *stream) | |||||||
|                         get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len); |                         get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len); | ||||||
|                         write_bits(&state->bitbuf, code, code_len); |                         write_bits(&state->bitbuf, code, code_len); | ||||||
|                         next_in++; |                         next_in++; | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 while (next_in < end_in) { |                 while (next_in < end_in) { | ||||||
| @@ -197,7 +195,6 @@ void isal_deflate_finish_base(struct isal_zstream *stream) | |||||||
|                         get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len); |                         get_lit_code(stream->hufftables, literal & 0xFF, &code, &code_len); | ||||||
|                         write_bits(&state->bitbuf, code, code_len); |                         write_bits(&state->bitbuf, code, code_len); | ||||||
|                         next_in++; |                         next_in++; | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -217,8 +214,9 @@ void isal_deflate_finish_base(struct isal_zstream *stream) | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_hash_base(uint16_t * hash_table, uint32_t hash_mask, | void | ||||||
| 			    uint32_t current_index, uint8_t * dict, uint32_t dict_len) | 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 *next_in = dict; | ||||||
|         uint8_t *end_in = dict + dict_len - SHORTEST_MATCH; |         uint8_t *end_in = dict + dict_len - SHORTEST_MATCH; | ||||||
|   | |||||||
| @@ -32,122 +32,150 @@ | |||||||
| #include "encode_df.h" | #include "encode_df.h" | ||||||
| #include "igzip_level_buf_structs.h" | #include "igzip_level_buf_structs.h" | ||||||
|  |  | ||||||
| void isal_deflate_body_base(struct isal_zstream *stream); | void | ||||||
| void isal_deflate_finish_base(struct isal_zstream *stream); | isal_deflate_body_base(struct isal_zstream *stream); | ||||||
| void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream); | void | ||||||
| void icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream); | isal_deflate_finish_base(struct isal_zstream *stream); | ||||||
| void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream); | void | ||||||
| void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream); | isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream); | ||||||
| void isal_update_histogram_base(uint8_t * start_stream, int length, | 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 isal_huff_histogram *histogram); | ||||||
| struct deflate_icf *encode_deflate_icf_base(struct deflate_icf *next_in, | struct deflate_icf * | ||||||
| 					    struct deflate_icf *end_in, struct BitBuf2 *bb, | encode_deflate_icf_base(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb, | ||||||
|                         struct hufftables_icf *hufftables); |                         struct hufftables_icf *hufftables); | ||||||
| uint32_t adler32_base(uint32_t init, const unsigned char *buf, uint64_t len); | uint32_t | ||||||
| int decode_huffman_code_block_stateless_base(struct inflate_state *s, uint8_t * start_out); | 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, | void | ||||||
| 			  struct deflate_icf *match_lookup, struct level_buf *level_buf); | set_long_icf_fg_base(uint8_t *next_in, uint8_t *end_in, struct deflate_icf *match_lookup, | ||||||
| void gen_icf_map_h1_base(struct isal_zstream *stream, |                      struct level_buf *level_buf); | ||||||
| 			 struct deflate_icf *matches_icf_lookup, uint64_t input_size); | 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, | void | ||||||
| 			   struct isal_huff_histogram *histogram) | 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 * | ||||||
| 				       struct deflate_icf *end_in, struct BitBuf2 *bb, | encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in, struct BitBuf2 *bb, | ||||||
|                    struct hufftables_icf *hufftables) |                    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, | void | ||||||
| 			    uint32_t current_index, uint8_t * dict, uint32_t dict_len) | 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, | void | ||||||
| 			    uint32_t current_index, uint8_t * dict, uint32_t dict_len) | 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, | void | ||||||
| 			    uint32_t current_index, uint8_t * dict, uint32_t dict_len) | 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, | void | ||||||
| 			    uint32_t current_index, uint8_t * dict, uint32_t dict_len) | 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, | void | ||||||
| 		     struct deflate_icf *match_lookup, struct level_buf *level_buf) | 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, | void | ||||||
| 		     struct deflate_icf *matches_icf_lookup, uint64_t input_size) | 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); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,9 +9,11 @@ | |||||||
|  |  | ||||||
| #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; |         int i; | ||||||
|         for (i = 0; i < size; i++) { |         for (i = 0; i < size; i++) { | ||||||
| @@ -19,7 +21,8 @@ void create_rand_data(uint8_t * data, uint32_t size) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         int time = BENCHMARK_TIME; |         int time = BENCHMARK_TIME; | ||||||
|         struct isal_zstream stream; |         struct isal_zstream stream; | ||||||
|   | |||||||
| @@ -6,7 +6,9 @@ | |||||||
| #define MAX_ADLER_BUF (1 << 28) | #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 | ||||||
| uint32_t isal_adler32_bam1(uint32_t init_crc, const unsigned char *buf, uint64_t len); | 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 | #endif | ||||||
|   | |||||||
| @@ -40,7 +40,8 @@ | |||||||
|  |  | ||||||
| struct isal_zstream stream; | struct isal_zstream stream; | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE]; |         uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE]; | ||||||
|         FILE *in, *out; |         FILE *in, *out; | ||||||
|   | |||||||
| @@ -91,10 +91,10 @@ int level_size_buf[10] = { | |||||||
| #endif | #endif | ||||||
| }; | }; | ||||||
|  |  | ||||||
| int usage(void) | int | ||||||
|  | usage(void) | ||||||
| { | { | ||||||
| 	fprintf(stderr, |         fprintf(stderr, "Usage: igzip_file_perf [options] <infile>\n" | ||||||
| 		"Usage: igzip_file_perf [options] <infile>\n" |  | ||||||
|                         "  -h        help\n" |                         "  -h        help\n" | ||||||
|                         "  -X        use compression level X with 0 <= X <= 1\n" |                         "  -X        use compression level X with 0 <= X <= 1\n" | ||||||
|                         "  -b <size> input buffer size, 0 buffers all the input\n" |                         "  -b <size> input buffer size, 0 buffers all the input\n" | ||||||
| @@ -106,10 +106,10 @@ int usage(void) | |||||||
|         exit(0); |         exit(0); | ||||||
| } | } | ||||||
|  |  | ||||||
| void deflate_perf(struct isal_zstream *stream, uint8_t * inbuf, size_t infile_size, | void | ||||||
| 		  size_t inbuf_size, uint8_t * outbuf, size_t outbuf_size, int level, | deflate_perf(struct isal_zstream *stream, uint8_t *inbuf, size_t infile_size, size_t inbuf_size, | ||||||
| 		  uint8_t * level_buf, int level_size, uint32_t hist_bits, uint8_t * dictbuf, |              uint8_t *outbuf, size_t outbuf_size, int level, uint8_t *level_buf, int level_size, | ||||||
| 		  size_t dictfile_size, struct isal_dict *dict_str, |              uint32_t hist_bits, uint8_t *dictbuf, size_t dictfile_size, struct isal_dict *dict_str, | ||||||
|              struct isal_hufftables *hufftables_custom) |              struct isal_hufftables *hufftables_custom) | ||||||
| { | { | ||||||
|         int avail_in; |         int avail_in; | ||||||
| @@ -146,7 +146,8 @@ void deflate_perf(struct isal_zstream *stream, uint8_t * inbuf, size_t infile_si | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         FILE *in = NULL, *out = NULL, *dict = NULL; |         FILE *in = NULL, *out = NULL, *dict = NULL; | ||||||
|         unsigned char *inbuf, *outbuf, *level_buf = NULL, *dictbuf = NULL; |         unsigned char *inbuf, *outbuf, *level_buf = NULL, *dictbuf = NULL; | ||||||
| @@ -296,22 +297,21 @@ int main(int argc, char *argv[]) | |||||||
|         struct perf start; |         struct perf start; | ||||||
|         if (time > 0) { |         if (time > 0) { | ||||||
|                 BENCHMARK(&start, time, |                 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, |                           deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size, | ||||||
|                                        level, level_buf, level_size, hist_bits, dictbuf, |                                        level, level_buf, level_size, hist_bits, dictbuf, | ||||||
| 			     dictfile_size, &dict_str, NULL); |                                        dictfile_size, &dict_str, NULL)); | ||||||
|  |         } else { | ||||||
|  |                 deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size, level, | ||||||
|  |                              level_buf, level_size, hist_bits, dictbuf, dictfile_size, &dict_str, | ||||||
|  |                              NULL); | ||||||
|         } |         } | ||||||
|         if (stream.avail_in != 0) { |         if (stream.avail_in != 0) { | ||||||
|                 fprintf(stderr, "Could not compress all of inbuf\n"); |                 fprintf(stderr, "Could not compress all of inbuf\n"); | ||||||
|                 exit(0); |                 exit(0); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	printf("  file %s - in_size=%lu out_size=%d ratio=%3.1f%%", |         printf("  file %s - in_size=%lu out_size=%d ratio=%3.1f%%", in_file_name, infile_size, | ||||||
| 	       in_file_name, infile_size, stream.total_out, |                stream.total_out, 100.0 * stream.total_out / infile_size); | ||||||
| 	       100.0 * stream.total_out / infile_size); |  | ||||||
|  |  | ||||||
|         if (level == 0) { |         if (level == 0) { | ||||||
|                 memset(&histogram, 0, sizeof(histogram)); |                 memset(&histogram, 0, sizeof(histogram)); | ||||||
| @@ -319,9 +319,9 @@ int main(int argc, char *argv[]) | |||||||
|                 isal_update_histogram(inbuf, infile_size, &histogram); |                 isal_update_histogram(inbuf, infile_size, &histogram); | ||||||
|                 isal_create_hufftables(&hufftables_custom, &histogram); |                 isal_create_hufftables(&hufftables_custom, &histogram); | ||||||
|  |  | ||||||
| 		deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size, |                 deflate_perf(&stream, inbuf, infile_size, inbuf_size, outbuf, outbuf_size, level, | ||||||
| 			     level, level_buf, level_size, hist_bits, dictbuf, |                              level_buf, level_size, hist_bits, dictbuf, dictfile_size, &dict_str, | ||||||
| 			     dictfile_size, &dict_str, &hufftables_custom); |                              &hufftables_custom); | ||||||
|  |  | ||||||
|                 printf(" ratio_custom=%3.1f%%", 100.0 * stream.total_out / infile_size); |                 printf(" ratio_custom=%3.1f%%", 100.0 * stream.total_out / infile_size); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -41,7 +41,8 @@ | |||||||
| #define RUN_MEM_SIZE 2000000000 | #define RUN_MEM_SIZE 2000000000 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| void print_histogram(struct isal_huff_histogram *histogram) | void | ||||||
|  | print_histogram(struct isal_huff_histogram *histogram) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|         printf("Lit Len histogram"); |         printf("Lit Len histogram"); | ||||||
| @@ -65,7 +66,8 @@ void print_histogram(struct isal_huff_histogram *histogram) | |||||||
|         printf("\n"); |         printf("\n"); | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         FILE *in; |         FILE *in; | ||||||
|         unsigned char *inbuf; |         unsigned char *inbuf; | ||||||
| @@ -115,8 +117,7 @@ int main(int argc, char *argv[]) | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         struct perf start; |         struct perf start; | ||||||
| 	BENCHMARK(&start, BENCHMARK_TIME, |         BENCHMARK(&start, BENCHMARK_TIME, isal_update_histogram(inbuf, infile_size, &histogram1)); | ||||||
| 		  isal_update_histogram(inbuf, infile_size, &histogram1)); |  | ||||||
|         printf("  file %s - in_size=%lu\n", argv[1], infile_size); |         printf("  file %s - in_size=%lu\n", argv[1], infile_size); | ||||||
|         printf("igzip_hist_file: "); |         printf("igzip_hist_file: "); | ||||||
|         perf_print(start, (long long) infile_size); |         perf_print(start, (long long) infile_size); | ||||||
|   | |||||||
| @@ -6,16 +6,16 @@ | |||||||
| #include "igzip_level_buf_structs.h" | #include "igzip_level_buf_structs.h" | ||||||
| #include "unaligned.h" | #include "unaligned.h" | ||||||
|  |  | ||||||
| static inline void write_deflate_icf(struct deflate_icf *icf, uint32_t lit_len, | static inline void | ||||||
| 				     uint32_t lit_dist, uint32_t extra_bits) | 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_len = lit_len; | ||||||
|         icf->lit_dist = lit_dist; |         icf->lit_dist = lit_dist; | ||||||
|         icf->dist_extra = extra_bits; |         icf->dist_extra = extra_bits; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void update_state(struct isal_zstream *stream, uint8_t * start_in, | static inline void | ||||||
| 				uint8_t * next_in, uint8_t * end_in, | 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 *start_out, struct deflate_icf *next_out, | ||||||
|              struct deflate_icf *end_out) |              struct deflate_icf *end_out) | ||||||
| { | { | ||||||
| @@ -33,7 +33,8 @@ static inline void update_state(struct isal_zstream *stream, uint8_t * start_in, | |||||||
|         level_buf->icf_buf_avail_out = end_out - next_out; |         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; |         uint32_t literal, hash; | ||||||
|         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; |         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; | ||||||
| @@ -59,8 +60,7 @@ void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream) | |||||||
|         next_in = start_in; |         next_in = start_in; | ||||||
|  |  | ||||||
|         start_out = ((struct level_buf *) stream->level_buf)->icf_buf_next; |         start_out = ((struct level_buf *) stream->level_buf)->icf_buf_next; | ||||||
| 	end_out = |         end_out = start_out + ((struct level_buf *) stream->level_buf)->icf_buf_avail_out / | ||||||
| 	    start_out + ((struct level_buf *)stream->level_buf)->icf_buf_avail_out / |  | ||||||
|                                       sizeof(struct deflate_icf); |                                       sizeof(struct deflate_icf); | ||||||
|         next_out = start_out; |         next_out = start_out; | ||||||
|  |  | ||||||
| @@ -127,10 +127,10 @@ void isal_deflate_icf_body_hash_hist_base(struct isal_zstream *stream) | |||||||
|                 state->state = ZSTATE_FLUSH_READ_BUFFER; |                 state->state = ZSTATE_FLUSH_READ_BUFFER; | ||||||
|  |  | ||||||
|         return; |         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; |         uint32_t literal = 0, hash; | ||||||
|         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; |         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; | ||||||
| @@ -211,7 +211,6 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream) | |||||||
|                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); |                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); | ||||||
|                 next_out++; |                 next_out++; | ||||||
|                 next_in++; |                 next_in++; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         while (next_in < end_in) { |         while (next_in < end_in) { | ||||||
| @@ -228,7 +227,6 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream) | |||||||
|                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); |                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); | ||||||
|                 next_out++; |                 next_out++; | ||||||
|                 next_in++; |                 next_in++; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (next_in == end_in) { |         if (next_in == end_in) { | ||||||
| @@ -241,7 +239,8 @@ void isal_deflate_icf_finish_hash_hist_base(struct isal_zstream *stream) | |||||||
|         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; |         uint32_t literal = 0, hash; | ||||||
|         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; |         uint8_t *start_in, *next_in, *end_in, *end, *next_hash; | ||||||
| @@ -321,7 +320,6 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream) | |||||||
|                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); |                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); | ||||||
|                 next_out++; |                 next_out++; | ||||||
|                 next_in++; |                 next_in++; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         while (next_in < end_in) { |         while (next_in < end_in) { | ||||||
| @@ -338,7 +336,6 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream) | |||||||
|                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); |                 write_deflate_icf(next_out, code, NULL_DIST_SYM, 0); | ||||||
|                 next_out++; |                 next_out++; | ||||||
|                 next_in++; |                 next_in++; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (next_in == end_in) { |         if (next_in == end_in) { | ||||||
| @@ -351,8 +348,9 @@ void isal_deflate_icf_finish_hash_map_base(struct isal_zstream *stream) | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_deflate_hash_mad_base(uint16_t * hash_table, uint32_t hash_mask, | void | ||||||
| 				uint32_t current_index, uint8_t * dict, uint32_t dict_len) | 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 *next_in = dict; | ||||||
|         uint8_t *end_in = dict + dict_len - SHORTEST_MATCH; |         uint8_t *end_in = dict + dict_len - SHORTEST_MATCH; | ||||||
|   | |||||||
| @@ -3,40 +3,45 @@ | |||||||
| #include "encode_df.h" | #include "encode_df.h" | ||||||
| #include "igzip_level_buf_structs.h" | #include "igzip_level_buf_structs.h" | ||||||
|  |  | ||||||
| extern uint64_t gen_icf_map_lh1(struct isal_zstream *, struct deflate_icf *, uint32_t); | extern uint64_t | ||||||
| extern void set_long_icf_fg(uint8_t *, uint64_t, uint64_t, struct deflate_icf *); | gen_icf_map_lh1(struct isal_zstream *, struct deflate_icf *, uint32_t); | ||||||
| extern void isal_deflate_icf_body_lvl1(struct isal_zstream *); | extern void | ||||||
| extern void isal_deflate_icf_body_lvl2(struct isal_zstream *); | set_long_icf_fg(uint8_t *, uint64_t, uint64_t, struct deflate_icf *); | ||||||
| extern void isal_deflate_icf_body_lvl3(struct isal_zstream *); | 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, | static inline void | ||||||
| 				     uint32_t lit_dist, uint32_t extra_bits) | 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_len = lit_len; */ | ||||||
|         /* icf->lit_dist = lit_dist; */ |         /* icf->lit_dist = lit_dist; */ | ||||||
|         /* icf->dist_extra = extra_bits; */ |         /* icf->dist_extra = extra_bits; */ | ||||||
|  |  | ||||||
| 	store_native_u32((uint8_t *) icf, lit_len | (lit_dist << LIT_LEN_BIT_COUNT) |         store_native_u32((uint8_t *) icf, | ||||||
| 			 | (extra_bits << (LIT_LEN_BIT_COUNT + DIST_LIT_BIT_COUNT))); |                          lit_len | (lit_dist << LIT_LEN_BIT_COUNT) | | ||||||
|  |                                  (extra_bits << (LIT_LEN_BIT_COUNT + DIST_LIT_BIT_COUNT))); | ||||||
| } | } | ||||||
|  |  | ||||||
| void set_long_icf_fg_base(uint8_t * next_in, uint64_t processed, uint64_t input_size, | void | ||||||
|  | set_long_icf_fg_base(uint8_t *next_in, uint64_t processed, uint64_t input_size, | ||||||
|                      struct deflate_icf *match_lookup) |                      struct deflate_icf *match_lookup) | ||||||
| { | { | ||||||
|         uint8_t *end_processed = next_in + processed; |         uint8_t *end_processed = next_in + processed; | ||||||
|         uint8_t *end_in = next_in + input_size; |         uint8_t *end_in = next_in + input_size; | ||||||
|         uint32_t dist_code, dist_extra, dist, len; |         uint32_t dist_code, dist_extra, dist, len; | ||||||
|         uint32_t match_len; |         uint32_t match_len; | ||||||
| 	uint32_t dist_start[] = { |         uint32_t dist_start[] = { 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, | ||||||
| 		0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, |  | ||||||
|                                   0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, |                                   0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, | ||||||
|                                   0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, |                                   0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, | ||||||
| 		0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 |                                   0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 }; | ||||||
| 	}; |  | ||||||
|  |  | ||||||
|         if (end_in > end_processed + ISAL_LOOK_AHEAD) |         if (end_in > end_processed + ISAL_LOOK_AHEAD) | ||||||
|                 end_in = end_processed + ISAL_LOOK_AHEAD; |                 end_in = end_processed + ISAL_LOOK_AHEAD; | ||||||
| @@ -47,11 +52,12 @@ void set_long_icf_fg_base(uint8_t * next_in, uint64_t processed, uint64_t input_ | |||||||
|                 dist = dist_start[dist_code] + dist_extra; |                 dist = dist_start[dist_code] + dist_extra; | ||||||
|                 len = match_lookup->lit_len; |                 len = match_lookup->lit_len; | ||||||
|                 if (len >= 8 + LEN_OFFSET) { |                 if (len >= 8 + LEN_OFFSET) { | ||||||
| 			match_len = compare((next_in + 8) - dist, next_in + 8, |                         match_len = | ||||||
| 					    end_in - (next_in + 8)) + LEN_OFFSET + 8; |                                 compare((next_in + 8) - dist, next_in + 8, end_in - (next_in + 8)) + | ||||||
|  |                                 LEN_OFFSET + 8; | ||||||
|  |  | ||||||
| 			while (match_len > match_lookup->lit_len |                         while (match_len > match_lookup->lit_len && | ||||||
| 			       && match_len >= LEN_OFFSET + SHORTEST_MATCH) { |                                match_len >= LEN_OFFSET + SHORTEST_MATCH) { | ||||||
|                                 write_deflate_icf(match_lookup, |                                 write_deflate_icf(match_lookup, | ||||||
|                                                   match_len > LEN_MAX ? LEN_MAX : match_len, |                                                   match_len > LEN_MAX ? LEN_MAX : match_len, | ||||||
|                                                   dist_code, dist_extra); |                                                   dist_code, dist_extra); | ||||||
| @@ -71,8 +77,9 @@ void set_long_icf_fg_base(uint8_t * next_in, uint64_t processed, uint64_t input_ | |||||||
| * Methods for generating one pass match lookup table | * Methods for generating one pass match lookup table | ||||||
| ************************************************************ | ************************************************************ | ||||||
| */ | */ | ||||||
| uint64_t gen_icf_map_h1_base(struct isal_zstream *stream, | uint64_t | ||||||
| 			     struct deflate_icf *matches_icf_lookup, uint64_t input_size) | 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; |         uint32_t dist, len, extra_bits; | ||||||
| @@ -133,8 +140,8 @@ uint64_t gen_icf_map_h1_base(struct isal_zstream *stream, | |||||||
| * One pass methods for parsing provided match lookup table | * One pass methods for parsing provided match lookup table | ||||||
| ************************************************************ | ************************************************************ | ||||||
| */ | */ | ||||||
| static struct deflate_icf *compress_icf_map_g(struct isal_zstream *stream, | static struct deflate_icf * | ||||||
| 					      struct deflate_icf *matches_next, | compress_icf_map_g(struct isal_zstream *stream, struct deflate_icf *matches_next, | ||||||
|                    struct deflate_icf *matches_end) |                    struct deflate_icf *matches_end) | ||||||
| { | { | ||||||
|         uint32_t lit_len, lit_len2, dist; |         uint32_t lit_len, lit_len2, dist; | ||||||
| @@ -143,8 +150,7 @@ static struct deflate_icf *compress_icf_map_g(struct isal_zstream *stream, | |||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
|         struct deflate_icf *matches_start = matches_next; |         struct deflate_icf *matches_start = matches_next; | ||||||
|         struct deflate_icf *icf_buf_end = |         struct deflate_icf *icf_buf_end = | ||||||
| 	    level_buf->icf_buf_next + |                 level_buf->icf_buf_next + level_buf->icf_buf_avail_out / sizeof(struct deflate_icf); | ||||||
| 	    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__ | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | ||||||
| @@ -222,7 +228,6 @@ static struct deflate_icf *compress_icf_map_g(struct isal_zstream *stream, | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         return matches_next; |         return matches_next; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -230,7 +235,8 @@ static struct deflate_icf *compress_icf_map_g(struct isal_zstream *stream, | |||||||
| * Compression functions combining different methods | * Compression functions combining different methods | ||||||
| ************************************************************ | ************************************************************ | ||||||
| */ | */ | ||||||
| static inline void icf_body_next_state(struct isal_zstream *stream) | static inline void | ||||||
|  | icf_body_next_state(struct isal_zstream *stream) | ||||||
| { | { | ||||||
|         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; |         struct level_buf *level_buf = (struct level_buf *) stream->level_buf; | ||||||
|         struct isal_zstate *state = &stream->internal_state; |         struct isal_zstate *state = &stream->internal_state; | ||||||
| @@ -238,12 +244,13 @@ static inline void icf_body_next_state(struct isal_zstream *stream) | |||||||
|         if (level_buf->icf_buf_avail_out <= 0) |         if (level_buf->icf_buf_avail_out <= 0) | ||||||
|                 state->state = ZSTATE_CREATE_HDR; |                 state->state = ZSTATE_CREATE_HDR; | ||||||
|  |  | ||||||
| 	else if (stream->avail_in <= ISAL_LOOK_AHEAD |         else if (stream->avail_in <= ISAL_LOOK_AHEAD && | ||||||
| 		 && (stream->end_of_stream || stream->flush != NO_FLUSH)) |                  (stream->end_of_stream || stream->flush != NO_FLUSH)) | ||||||
|                 state->state = ZSTATE_FLUSH_READ_BUFFER; |                 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, *matches_next_icf, *matches_end_icf; | ||||||
|         struct deflate_icf *matches_icf_lookup; |         struct deflate_icf *matches_icf_lookup; | ||||||
| @@ -282,7 +289,8 @@ void icf_body_hash1_fillgreedy_lazy(struct isal_zstream *stream) | |||||||
|         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, *matches_next_icf, *matches_end_icf; | ||||||
|         struct deflate_icf *matches_icf_lookup; |         struct deflate_icf *matches_icf_lookup; | ||||||
| @@ -321,7 +329,8 @@ void icf_body_lazyhash1_fillgreedy_greedy(struct isal_zstream *stream) | |||||||
|         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) { |         switch (stream->level) { | ||||||
|         case 3: |         case 3: | ||||||
|   | |||||||
| @@ -39,7 +39,8 @@ | |||||||
| #include "static_inflate.h" | #include "static_inflate.h" | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| extern int decode_huffman_code_block_stateless(struct inflate_state *, uint8_t * start_out); | extern int | ||||||
|  | decode_huffman_code_block_stateless(struct inflate_state *, uint8_t *start_out); | ||||||
| extern struct isal_hufftables hufftables_default; /* For known header detection */ | extern struct isal_hufftables hufftables_default; /* For known header detection */ | ||||||
|  |  | ||||||
| #define LARGE_SHORT_SYM_LEN         25 | #define LARGE_SHORT_SYM_LEN         25 | ||||||
| @@ -95,32 +96,25 @@ struct rfc1951_tables { | |||||||
|         uint32_t dist_start[32]; |         uint32_t dist_start[32]; | ||||||
|         uint8_t len_extra_bit_count[32]; |         uint8_t len_extra_bit_count[32]; | ||||||
|         uint16_t len_start[32]; |         uint16_t len_start[32]; | ||||||
|  |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /* The following tables are based on the tables in the deflate standard, | /* The following tables are based on the tables in the deflate standard, | ||||||
|  * RFC 1951 page 11. */ |  * RFC 1951 page 11. */ | ||||||
| static struct rfc1951_tables rfc_lookup_table = { | static struct rfc1951_tables rfc_lookup_table = { | ||||||
| 	.dist_extra_bit_count = { |         .dist_extra_bit_count = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, | ||||||
| 				 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, |                                   0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x09, | ||||||
| 				 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, |                                   0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x00, 0x00 }, | ||||||
| 				 0x07, 0x07, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, |  | ||||||
| 				 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x00, 0x00}, |  | ||||||
|  |  | ||||||
| 	.dist_start = { |         .dist_start = { 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, | ||||||
| 		       0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, |  | ||||||
|                         0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, |                         0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, | ||||||
|                         0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, |                         0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, | ||||||
|                         0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 }, |                         0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001, 0x0000, 0x0000 }, | ||||||
|  |  | ||||||
| 	.len_extra_bit_count = { |         .len_extra_bit_count = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, | ||||||
| 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |                                  0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, | ||||||
| 				0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, |                                  0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00 }, | ||||||
| 				0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, |  | ||||||
| 				0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00}, |  | ||||||
|  |  | ||||||
| 	.len_start = { |         .len_start = { 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, | ||||||
| 		      0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, |  | ||||||
|                        0x000b, 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, |                        0x000b, 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, | ||||||
|                        0x0023, 0x002b, 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, |                        0x0023, 0x002b, 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, | ||||||
|                        0x0083, 0x00a3, 0x00c3, 0x00e3, 0x0102, 0x0103, 0x0000, 0x0000 } |                        0x0083, 0x00a3, 0x00c3, 0x00e3, 0x0102, 0x0103, 0x0000, 0x0000 } | ||||||
| @@ -137,7 +131,8 @@ static void inline byte_copy(uint8_t * dest, uint64_t lookback_distance, int rep | |||||||
|                 *dest++ = *src++; |                 *dest++ = *src++; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void update_checksum(struct inflate_state *state, uint8_t * start_in, uint64_t length) | static void | ||||||
|  | update_checksum(struct inflate_state *state, uint8_t *start_in, uint64_t length) | ||||||
| { | { | ||||||
|         switch (state->crc_flag) { |         switch (state->crc_flag) { | ||||||
|         case ISAL_GZIP: |         case ISAL_GZIP: | ||||||
| @@ -153,45 +148,32 @@ static void update_checksum(struct inflate_state *state, uint8_t * start_in, uin | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void finalize_adler32(struct inflate_state *state) | static void | ||||||
|  | finalize_adler32(struct inflate_state *state) | ||||||
| { | { | ||||||
|  |  | ||||||
|         state->crc = (state->crc & 0xffff0000) | (((state->crc & 0xffff) + 1) % ADLER_MOD); |         state->crc = (state->crc & 0xffff0000) | (((state->crc & 0xffff) + 1) % ADLER_MOD); | ||||||
| } | } | ||||||
|  |  | ||||||
| static const uint8_t bitrev_table[] = { | static const uint8_t bitrev_table[] = { | ||||||
| 	0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, |         0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, | ||||||
| 	0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, |         0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, | ||||||
| 	0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, |         0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, | ||||||
| 	0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, |         0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, | ||||||
| 	0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, |         0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, | ||||||
| 	0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, |         0xd2, 0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, | ||||||
| 	0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, |         0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, | ||||||
| 	0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, |         0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, | ||||||
| 	0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, |         0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, | ||||||
| 	0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, |         0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, | ||||||
| 	0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, |         0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, | ||||||
| 	0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, |         0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd, | ||||||
| 	0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, |         0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x03, 0x83, 0x43, | ||||||
| 	0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, |         0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0x0b, 0x8b, | ||||||
| 	0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, |         0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, | ||||||
| 	0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, |         0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, | ||||||
| 	0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, |         0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, | ||||||
| 	0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, |         0xff, | ||||||
| 	0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, |  | ||||||
| 	0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, |  | ||||||
| 	0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, |  | ||||||
| 	0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, |  | ||||||
| 	0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, |  | ||||||
| 	0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, |  | ||||||
| 	0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, |  | ||||||
| 	0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, |  | ||||||
| 	0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, |  | ||||||
| 	0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, |  | ||||||
| 	0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, |  | ||||||
| 	0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, |  | ||||||
| 	0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, |  | ||||||
| 	0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, |  | ||||||
|  |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -235,13 +217,11 @@ static void inline inflate_in_load(struct inflate_state *state, int min_required | |||||||
|                         state->next_in++; |                         state->next_in++; | ||||||
|                         state->avail_in--; |                         state->avail_in--; | ||||||
|                         state->read_in_length += 8; |                         state->read_in_length += 8; | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static uint64_t inline inflate_in_read_bits_unsafe(struct inflate_state *state, | static uint64_t inline inflate_in_read_bits_unsafe(struct inflate_state *state, uint8_t bit_count) | ||||||
| 						   uint8_t bit_count) |  | ||||||
| { | { | ||||||
|         uint64_t ret; |         uint64_t ret; | ||||||
|  |  | ||||||
| @@ -266,8 +246,7 @@ static void inline write_huff_code(struct huff_code *huff_code, uint32_t code, u | |||||||
|         huff_code->code_and_length = code | length << 24; |         huff_code->code_and_length = code | length << 24; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int inline set_codes(struct huff_code *huff_code_table, int table_length, | static int inline set_codes(struct huff_code *huff_code_table, int table_length, uint16_t *count) | ||||||
| 			    uint16_t * count) |  | ||||||
| { | { | ||||||
|         uint32_t max, code, length; |         uint32_t max, code, length; | ||||||
|         uint32_t next_code[MAX_HUFF_TREE_DEPTH + 1]; |         uint32_t next_code[MAX_HUFF_TREE_DEPTH + 1]; | ||||||
| @@ -300,10 +279,8 @@ static int inline set_codes(struct huff_code *huff_code_table, int table_length, | |||||||
| } | } | ||||||
|  |  | ||||||
| static int inline set_and_expand_lit_len_huffcode(struct huff_code *lit_len_huff, | static int inline set_and_expand_lit_len_huffcode(struct huff_code *lit_len_huff, | ||||||
| 						  uint32_t table_length, |                                                   uint32_t table_length, uint16_t *count, | ||||||
| 						  uint16_t * count, |                                                   uint16_t *expand_count, uint32_t *code_list) | ||||||
| 						  uint16_t * expand_count, |  | ||||||
| 						  uint32_t * code_list) |  | ||||||
| { | { | ||||||
|         int len_sym, len_size, extra_count, extra; |         int len_sym, len_size, extra_count, extra; | ||||||
|         uint32_t count_total, count_tmp; |         uint32_t count_total, count_tmp; | ||||||
| @@ -401,18 +378,15 @@ static int inline set_and_expand_lit_len_huffcode(struct huff_code *lit_len_huff | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int inline index_to_sym(int index) | static int inline index_to_sym(int index) { return (index != 513) ? index : 512; } | ||||||
| { |  | ||||||
| 	return (index != 513) ? index : 512; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /* Sets result to the inflate_huff_code corresponding to the huffcode defined by | /* Sets result to the inflate_huff_code corresponding to the huffcode defined by | ||||||
|  * the lengths in huff_code_table,where count is a histogram of the appearance |  * the lengths in huff_code_table,where count is a histogram of the appearance | ||||||
|  * of each code length */ |  * of each code length */ | ||||||
| static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *result, | static void | ||||||
| 					   struct huff_code *huff_code_table, | make_inflate_huff_code_lit_len(struct inflate_huff_code_large *result, | ||||||
| 					   uint32_t table_length, uint16_t * count_total, |                                struct huff_code *huff_code_table, uint32_t table_length, | ||||||
| 					   uint32_t * code_list, uint32_t multisym) |                                uint16_t *count_total, uint32_t *code_list, uint32_t multisym) | ||||||
| { | { | ||||||
|         int i, j; |         int i, j; | ||||||
|         uint16_t code = 0; |         uint16_t code = 0; | ||||||
| @@ -460,8 +434,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                 copy_size *= 2; |                 copy_size *= 2; | ||||||
|  |  | ||||||
|                 /* Encode code singletons */ |                 /* Encode code singletons */ | ||||||
| 		for (index1 = count_total[last_length]; |                 for (index1 = count_total[last_length]; index1 < count_total[last_length + 1]; | ||||||
| 		     index1 < count_total[last_length + 1]; index1++) { |                      index1++) { | ||||||
|                         sym1_index = code_list[index1]; |                         sym1_index = code_list[index1]; | ||||||
|                         sym1 = index_to_sym(sym1_index); |                         sym1 = index_to_sym(sym1_index); | ||||||
|                         sym1_len = huff_code_table[sym1_index].length; |                         sym1_len = huff_code_table[sym1_index].length; | ||||||
| @@ -471,8 +445,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                                 continue; |                                 continue; | ||||||
|  |  | ||||||
|                         /* Set new codes */ |                         /* Set new codes */ | ||||||
| 			short_code_lookup[sym1_code] = |                         short_code_lookup[sym1_code] = sym1 | | ||||||
| 			    sym1 | sym1_len << LARGE_SHORT_CODE_LEN_OFFSET | |                                                        sym1_len << LARGE_SHORT_CODE_LEN_OFFSET | | ||||||
|                                                        (1 << LARGE_SYM_COUNT_OFFSET); |                                                        (1 << LARGE_SYM_COUNT_OFFSET); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -495,8 +469,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         sym2_len = last_length - sym1_len; |                         sym2_len = last_length - sym1_len; | ||||||
| 			for (index2 = count_total[sym2_len]; |                         for (index2 = count_total[sym2_len]; index2 < count_total[sym2_len + 1]; | ||||||
| 			     index2 < count_total[sym2_len + 1]; index2++) { |                              index2++) { | ||||||
|                                 sym2_index = code_list[index2]; |                                 sym2_index = code_list[index2]; | ||||||
|                                 sym2 = index_to_sym(sym2_index); |                                 sym2 = index_to_sym(sym2_index); | ||||||
|  |  | ||||||
| @@ -509,8 +483,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                                 code_length = sym1_len + sym2_len; |                                 code_length = sym1_len + sym2_len; | ||||||
|                                 short_code_lookup[code] = |                                 short_code_lookup[code] = | ||||||
|                                         sym1 | (sym2 << 8) | |                                         sym1 | (sym2 << 8) | | ||||||
| 				    (code_length << LARGE_SHORT_CODE_LEN_OFFSET) |                                         (code_length << LARGE_SHORT_CODE_LEN_OFFSET) | | ||||||
| 				    | (2 << LARGE_SYM_COUNT_OFFSET); |                                         (2 << LARGE_SYM_COUNT_OFFSET); | ||||||
|                         } |                         } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -564,14 +538,11 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                                         code_length = sym1_len + sym2_len + sym3_len; |                                         code_length = sym1_len + sym2_len + sym3_len; | ||||||
|                                         short_code_lookup[code] = |                                         short_code_lookup[code] = | ||||||
|                                                 sym1 | (sym2 << 8) | sym3 << 16 | |                                                 sym1 | (sym2 << 8) | sym3 << 16 | | ||||||
| 					    (code_length << LARGE_SHORT_CODE_LEN_OFFSET) |                                                 (code_length << LARGE_SHORT_CODE_LEN_OFFSET) | | ||||||
| 					    | (3 << LARGE_SYM_COUNT_OFFSET); |                                                 (3 << LARGE_SYM_COUNT_OFFSET); | ||||||
|  |                                 } | ||||||
| 				} |  | ||||||
|  |  | ||||||
|                         } |                         } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         index1 = count_total[ISAL_DECODE_LONG_BITS + 1]; |         index1 = count_total[ISAL_DECODE_LONG_BITS + 1]; | ||||||
| @@ -585,9 +556,8 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                         continue; |                         continue; | ||||||
|  |  | ||||||
|                 max_length = huff_code_table[long_code_list[i]].length; |                 max_length = huff_code_table[long_code_list[i]].length; | ||||||
| 		first_bits = |                 first_bits = huff_code_table[long_code_list[i]].code_and_extra & | ||||||
| 		    huff_code_table[long_code_list[i]].code_and_extra |                              ((1 << ISAL_DECODE_LONG_BITS) - 1); | ||||||
| 		    & ((1 << ISAL_DECODE_LONG_BITS) - 1); |  | ||||||
|  |  | ||||||
|                 temp_code_list[0] = long_code_list[i]; |                 temp_code_list[0] = long_code_list[i]; | ||||||
|                 temp_code_length = 1; |                 temp_code_length = 1; | ||||||
| @@ -620,10 +590,10 @@ static void make_inflate_huff_code_lit_len(struct inflate_huff_code_large *resul | |||||||
|                                         sym1 | (sym1_len << LARGE_LONG_CODE_LEN_OFFSET); |                                         sym1 | (sym1_len << LARGE_LONG_CODE_LEN_OFFSET); | ||||||
|                         } |                         } | ||||||
|                         huff_code_table[sym1_index].code_and_extra = INVALID_CODE; |                         huff_code_table[sym1_index].code_and_extra = INVALID_CODE; | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|                 result->short_code_lookup[first_bits] = long_code_lookup_length | |                 result->short_code_lookup[first_bits] = long_code_lookup_length | | ||||||
| 		    (max_length << LARGE_SHORT_MAX_LEN_OFFSET) | LARGE_FLAG_BIT; |                                                         (max_length << LARGE_SHORT_MAX_LEN_OFFSET) | | ||||||
|  |                                                         LARGE_FLAG_BIT; | ||||||
|                 long_code_lookup_length += 1 << (max_length - ISAL_DECODE_LONG_BITS); |                 long_code_lookup_length += 1 << (max_length - ISAL_DECODE_LONG_BITS); | ||||||
|         } |         } | ||||||
| } | } | ||||||
| @@ -705,7 +675,8 @@ static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *r | |||||||
|                          * address are the same as the code for the current symbol. The |                          * address are the same as the code for the current symbol. The | ||||||
|                          * first 9 bits are the code, bits 14:10 are the code length, |                          * first 9 bits are the code, bits 14:10 are the code length, | ||||||
|                          * bit 15 is a flag representing this is a symbol*/ |                          * bit 15 is a flag representing this is a symbol*/ | ||||||
| 			short_code_lookup[huff_code_table[i].code] = i | |                         short_code_lookup[huff_code_table[i].code] = | ||||||
|  |                                 i | | ||||||
|                                 rfc_lookup_table.dist_extra_bit_count[i] << DIST_SYM_EXTRA_OFFSET | |                                 rfc_lookup_table.dist_extra_bit_count[i] << DIST_SYM_EXTRA_OFFSET | | ||||||
|                                 (huff_code_table[i].length) << SMALL_SHORT_CODE_LEN_OFFSET; |                                 (huff_code_table[i].length) << SMALL_SHORT_CODE_LEN_OFFSET; | ||||||
|                 } |                 } | ||||||
| @@ -722,9 +693,8 @@ static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *r | |||||||
|                         continue; |                         continue; | ||||||
|  |  | ||||||
|                 max_length = huff_code_table[long_code_list[i]].length; |                 max_length = huff_code_table[long_code_list[i]].length; | ||||||
| 		first_bits = |                 first_bits = huff_code_table[long_code_list[i]].code & | ||||||
| 		    huff_code_table[long_code_list[i]].code |                              ((1 << ISAL_DECODE_SHORT_BITS) - 1); | ||||||
| 		    & ((1 << ISAL_DECODE_SHORT_BITS) - 1); |  | ||||||
|  |  | ||||||
|                 temp_code_list[0] = long_code_list[i]; |                 temp_code_list[0] = long_code_list[i]; | ||||||
|                 temp_code_length = 1; |                 temp_code_length = 1; | ||||||
| @@ -758,16 +728,16 @@ static void inline make_inflate_huff_code_dist(struct inflate_huff_code_small *r | |||||||
|                                 } |                                 } | ||||||
|                                 result->long_code_lookup[long_code_lookup_length + long_bits] = |                                 result->long_code_lookup[long_code_lookup_length + long_bits] = | ||||||
|                                         sym | |                                         sym | | ||||||
| 				    rfc_lookup_table.dist_extra_bit_count[sym] << |                                         rfc_lookup_table.dist_extra_bit_count[sym] | ||||||
| 				    DIST_SYM_EXTRA_OFFSET | |                                                 << DIST_SYM_EXTRA_OFFSET | | ||||||
|                                         (code_length << SMALL_LONG_CODE_LEN_OFFSET); |                                         (code_length << SMALL_LONG_CODE_LEN_OFFSET); | ||||||
|                         } |                         } | ||||||
|                         huff_code_table[sym].code = 0xFFFF; |                         huff_code_table[sym].code = 0xFFFF; | ||||||
|                 } |                 } | ||||||
| 		result->short_code_lookup[first_bits] = long_code_lookup_length | |                 result->short_code_lookup[first_bits] = | ||||||
| 		    (max_length << SMALL_SHORT_CODE_LEN_OFFSET) | SMALL_FLAG_BIT; |                         long_code_lookup_length | (max_length << SMALL_SHORT_CODE_LEN_OFFSET) | | ||||||
|  |                         SMALL_FLAG_BIT; | ||||||
|                 long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS); |                 long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS); | ||||||
|  |  | ||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -858,9 +828,8 @@ static void inline make_inflate_huff_code_header(struct inflate_huff_code_small | |||||||
|                         continue; |                         continue; | ||||||
|  |  | ||||||
|                 max_length = huff_code_table[long_code_list[i]].length; |                 max_length = huff_code_table[long_code_list[i]].length; | ||||||
| 		first_bits = |                 first_bits = huff_code_table[long_code_list[i]].code & | ||||||
| 		    huff_code_table[long_code_list[i]].code |                              ((1 << ISAL_DECODE_SHORT_BITS) - 1); | ||||||
| 		    & ((1 << ISAL_DECODE_SHORT_BITS) - 1); |  | ||||||
|  |  | ||||||
|                 temp_code_list[0] = long_code_list[i]; |                 temp_code_list[0] = long_code_list[i]; | ||||||
|                 temp_code_length = 1; |                 temp_code_length = 1; | ||||||
| @@ -891,14 +860,15 @@ static void inline make_inflate_huff_code_header(struct inflate_huff_code_small | |||||||
|                         } |                         } | ||||||
|                         huff_code_table[temp_code_list[j]].code = 0xFFFF; |                         huff_code_table[temp_code_list[j]].code = 0xFFFF; | ||||||
|                 } |                 } | ||||||
| 		result->short_code_lookup[first_bits] = long_code_lookup_length | |                 result->short_code_lookup[first_bits] = | ||||||
| 		    (max_length << SMALL_SHORT_CODE_LEN_OFFSET) | SMALL_FLAG_BIT; |                         long_code_lookup_length | (max_length << SMALL_SHORT_CODE_LEN_OFFSET) | | ||||||
|  |                         SMALL_FLAG_BIT; | ||||||
|                 long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS); |                 long_code_lookup_length += 1 << (max_length - ISAL_DECODE_SHORT_BITS); | ||||||
|  |  | ||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static int header_matches_pregen(struct inflate_state *state) | static int | ||||||
|  | header_matches_pregen(struct inflate_state *state) | ||||||
| { | { | ||||||
| #ifndef ISAL_STATIC_INFLATE_TABLE | #ifndef ISAL_STATIC_INFLATE_TABLE | ||||||
|         return 0; |         return 0; | ||||||
| @@ -958,7 +928,8 @@ static int header_matches_pregen(struct inflate_state *state) | |||||||
| #endif // ISAL_STATIC_INFLATE_TABLE | #endif // ISAL_STATIC_INFLATE_TABLE | ||||||
| } | } | ||||||
|  |  | ||||||
| static int setup_pregen_header(struct inflate_state *state) | static int | ||||||
|  | setup_pregen_header(struct inflate_state *state) | ||||||
| { | { | ||||||
| #ifdef ISAL_STATIC_INFLATE_TABLE | #ifdef ISAL_STATIC_INFLATE_TABLE | ||||||
|         memcpy(&state->lit_huff_code, &pregen_lit_huff_code, sizeof(pregen_lit_huff_code)); |         memcpy(&state->lit_huff_code, &pregen_lit_huff_code, sizeof(pregen_lit_huff_code)); | ||||||
| @@ -979,7 +950,8 @@ static int inline setup_static_header(struct inflate_state *state) | |||||||
|  |  | ||||||
| #ifndef NO_STATIC_INFLATE_H | #ifndef NO_STATIC_INFLATE_H | ||||||
| #warning "Defaulting to static inflate table fallback." | #warning "Defaulting to static inflate table fallback." | ||||||
| # warning "For best performance, run generate_static_inflate, replace static_inflate.h, and recompile" | #warning                                                                                           \ | ||||||
|  |         "For best performance, run generate_static_inflate, replace static_inflate.h, and recompile" | ||||||
| #endif | #endif | ||||||
|         int i; |         int i; | ||||||
|         struct huff_code lit_code[LIT_LEN_ELEMS]; |         struct huff_code lit_code[LIT_LEN_ELEMS]; | ||||||
| @@ -987,17 +959,14 @@ static int inline setup_static_header(struct inflate_state *state) | |||||||
|         uint32_t multisym = SINGLE_SYM_FLAG, max_dist = DIST_LEN; |         uint32_t multisym = SINGLE_SYM_FLAG, max_dist = DIST_LEN; | ||||||
|         /* These tables are based on the static huffman tree described in RFC |         /* These tables are based on the static huffman tree described in RFC | ||||||
|          * 1951 */ |          * 1951 */ | ||||||
| 	uint16_t lit_count[MAX_LIT_LEN_COUNT] = { |         uint16_t lit_count[MAX_LIT_LEN_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 24, 152, 112, 0, | ||||||
| 		0, 0, 0, 0, 0, 0, 0, 24, 152, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |                                                   0, 0, 0, 0, 0, 0, 0, 0,  0,   0,   0 }; | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	uint16_t lit_expand_count[MAX_LIT_LEN_COUNT] = { |         uint16_t lit_expand_count[MAX_LIT_LEN_COUNT] = { 0,  0,  0,   0, 0, 0, 0, -15, 1, 16, 32, | ||||||
| 		0, 0, 0, 0, 0, 0, 0, -15, 1, 16, 32, 48, 16, 128, 0, 0, 0, 0, 0, 0, 0, 0 |                                                          48, 16, 128, 0, 0, 0, 0, 0,   0, 0,  0 }; | ||||||
| 	}; |         uint16_t dist_count[16] = { 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||||||
| 	uint16_t dist_count[16] = { |         uint32_t code_list[LIT_LEN_ELEMS + | ||||||
| 		0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |                            2]; /* The +2 is for the extra codes in the static header */ | ||||||
| 	}; |  | ||||||
| 	uint32_t code_list[LIT_LEN_ELEMS + 2];	/* The +2 is for the extra codes in the static header */ |  | ||||||
|         /* These for loops set the code lengths for the static literal/length |         /* These for loops set the code lengths for the static literal/length | ||||||
|          * and distance codes defined in the deflate standard RFC 1951 */ |          * and distance codes defined in the deflate standard RFC 1951 */ | ||||||
|         for (i = 0; i < 144; i++) |         for (i = 0; i < 144; i++) | ||||||
| @@ -1020,14 +989,14 @@ static int inline setup_static_header(struct inflate_state *state) | |||||||
|  |  | ||||||
|         set_codes(dist_code, DIST_LEN + 2, dist_count); |         set_codes(dist_code, DIST_LEN + 2, dist_count); | ||||||
|  |  | ||||||
| 	make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_code, LIT_LEN_ELEMS, |         make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_code, LIT_LEN_ELEMS, lit_count, | ||||||
| 				       lit_count, code_list, multisym); |                                        code_list, multisym); | ||||||
|  |  | ||||||
|         if (state->hist_bits && state->hist_bits < 15) |         if (state->hist_bits && state->hist_bits < 15) | ||||||
|                 max_dist = 2 * state->hist_bits; |                 max_dist = 2 * state->hist_bits; | ||||||
|  |  | ||||||
| 	make_inflate_huff_code_dist(&state->dist_huff_code, dist_code, DIST_LEN + 2, |         make_inflate_huff_code_dist(&state->dist_huff_code, dist_code, DIST_LEN + 2, dist_count, | ||||||
| 				    dist_count, max_dist); |                                     max_dist); | ||||||
| #endif | #endif | ||||||
|         state->block_state = ISAL_BLOCK_CODED; |         state->block_state = ISAL_BLOCK_CODED; | ||||||
|  |  | ||||||
| @@ -1077,8 +1046,7 @@ static void inline decode_next_lit_len(uint32_t * next_lits, uint32_t * sym_coun | |||||||
|                 bit_mask = next_sym >> LARGE_SHORT_MAX_LEN_OFFSET; |                 bit_mask = next_sym >> LARGE_SHORT_MAX_LEN_OFFSET; | ||||||
|                 bit_mask = (1 << bit_mask) - 1; |                 bit_mask = (1 << bit_mask) - 1; | ||||||
|                 next_bits = state->read_in & bit_mask; |                 next_bits = state->read_in & bit_mask; | ||||||
| 		next_sym = |                 next_sym = huff_code->long_code_lookup[(next_sym & LARGE_SHORT_SYM_MASK) + | ||||||
| 		    huff_code->long_code_lookup[(next_sym & LARGE_SHORT_SYM_MASK) + |  | ||||||
|                                                        (next_bits >> ISAL_DECODE_LONG_BITS)]; |                                                        (next_bits >> ISAL_DECODE_LONG_BITS)]; | ||||||
|                 bit_count = next_sym >> LARGE_LONG_CODE_LEN_OFFSET; |                 bit_count = next_sym >> LARGE_LONG_CODE_LEN_OFFSET; | ||||||
|                 state->read_in >>= bit_count; |                 state->read_in >>= bit_count; | ||||||
| @@ -1133,8 +1101,7 @@ static uint16_t inline decode_next_dist(struct inflate_state *state, | |||||||
|                 bit_mask = (next_sym - SMALL_FLAG_BIT) >> SMALL_SHORT_CODE_LEN_OFFSET; |                 bit_mask = (next_sym - SMALL_FLAG_BIT) >> SMALL_SHORT_CODE_LEN_OFFSET; | ||||||
|                 bit_mask = (1 << bit_mask) - 1; |                 bit_mask = (1 << bit_mask) - 1; | ||||||
|                 next_bits = state->read_in & bit_mask; |                 next_bits = state->read_in & bit_mask; | ||||||
| 		next_sym = |                 next_sym = huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) + | ||||||
| 		    huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) + |  | ||||||
|                                                        (next_bits >> ISAL_DECODE_SHORT_BITS)]; |                                                        (next_bits >> ISAL_DECODE_SHORT_BITS)]; | ||||||
|                 bit_count = next_sym >> SMALL_LONG_CODE_LEN_OFFSET; |                 bit_count = next_sym >> SMALL_LONG_CODE_LEN_OFFSET; | ||||||
|                 state->read_in >>= bit_count; |                 state->read_in >>= bit_count; | ||||||
| @@ -1188,14 +1155,12 @@ static uint16_t inline decode_next_header(struct inflate_state *state, | |||||||
|                 bit_mask = (next_sym - SMALL_FLAG_BIT) >> SMALL_SHORT_CODE_LEN_OFFSET; |                 bit_mask = (next_sym - SMALL_FLAG_BIT) >> SMALL_SHORT_CODE_LEN_OFFSET; | ||||||
|                 bit_mask = (1 << bit_mask) - 1; |                 bit_mask = (1 << bit_mask) - 1; | ||||||
|                 next_bits = state->read_in & bit_mask; |                 next_bits = state->read_in & bit_mask; | ||||||
| 		next_sym = |                 next_sym = huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) + | ||||||
| 		    huff_code->long_code_lookup[(next_sym & SMALL_SHORT_SYM_MASK) + |  | ||||||
|                                                        (next_bits >> ISAL_DECODE_SHORT_BITS)]; |                                                        (next_bits >> ISAL_DECODE_SHORT_BITS)]; | ||||||
|                 bit_count = next_sym >> SMALL_LONG_CODE_LEN_OFFSET; |                 bit_count = next_sym >> SMALL_LONG_CODE_LEN_OFFSET; | ||||||
|                 state->read_in >>= bit_count; |                 state->read_in >>= bit_count; | ||||||
|                 state->read_in_length -= bit_count; |                 state->read_in_length -= bit_count; | ||||||
|                 return next_sym & SMALL_LONG_SYM_MASK; |                 return next_sym & SMALL_LONG_SYM_MASK; | ||||||
|  |  | ||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1209,8 +1174,8 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|         struct huff_code *previous = NULL, *current, *end, rep_code; |         struct huff_code *previous = NULL, *current, *end, rep_code; | ||||||
|         struct inflate_huff_code_small inflate_code_huff; |         struct inflate_huff_code_small inflate_code_huff; | ||||||
|         uint64_t hclen, hdist, hlit; |         uint64_t hclen, hdist, hlit; | ||||||
| 	uint16_t code_count[16], lit_count[MAX_LIT_LEN_COUNT], |         uint16_t code_count[16], lit_count[MAX_LIT_LEN_COUNT], lit_expand_count[MAX_LIT_LEN_COUNT], | ||||||
| 	    lit_expand_count[MAX_LIT_LEN_COUNT], dist_count[16]; |                 dist_count[16]; | ||||||
|         uint16_t *count; |         uint16_t *count; | ||||||
|         uint16_t symbol; |         uint16_t symbol; | ||||||
|         uint32_t multisym = DEFAULT_SYM_FLAG, length, max_dist = DIST_LEN; |         uint32_t multisym = DEFAULT_SYM_FLAG, length, max_dist = DIST_LEN; | ||||||
| @@ -1218,17 +1183,18 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|         uint64_t flag = 0; |         uint64_t flag = 0; | ||||||
|  |  | ||||||
|         int extra_count; |         int extra_count; | ||||||
| 	uint32_t code_list[LIT_LEN_ELEMS + 2];	/* The +2 is for the extra codes in the static header */ |         uint32_t code_list[LIT_LEN_ELEMS + | ||||||
|  |                            2]; /* The +2 is for the extra codes in the static header */ | ||||||
|  |  | ||||||
|         /* This order is defined in RFC 1951 page 13 */ |         /* This order is defined in RFC 1951 page 13 */ | ||||||
| 	const uint8_t code_length_order[CODE_LEN_CODES] = { |         const uint8_t code_length_order[CODE_LEN_CODES] = { 0x10, 0x11, 0x12, 0x00, 0x08, | ||||||
| 		0x10, 0x11, 0x12, 0x00, 0x08, 0x07, 0x09, 0x06, |                                                             0x07, 0x09, 0x06, 0x0a, 0x05, | ||||||
| 		0x0a, 0x05, 0x0b, 0x04, 0x0c, 0x03, 0x0d, 0x02, 0x0e, 0x01, 0x0f |                                                             0x0b, 0x04, 0x0c, 0x03, 0x0d, | ||||||
| 	}; |                                                             0x02, 0x0e, 0x01, 0x0f }; | ||||||
|  |  | ||||||
|         /* If you are given a whole header and it matches the pregen header */ |         /* If you are given a whole header and it matches the pregen header */ | ||||||
| 	if (state->avail_in > (hufftables_default.deflate_hdr_count + sizeof(uint64_t)) |         if (state->avail_in > (hufftables_default.deflate_hdr_count + sizeof(uint64_t)) && | ||||||
| 	    && header_matches_pregen(state)) |             header_matches_pregen(state)) | ||||||
|                 return setup_pregen_header(state); |                 return setup_pregen_header(state); | ||||||
|  |  | ||||||
|         if (state->bfinal && state->avail_in <= SINGLE_SYM_THRESH) { |         if (state->bfinal && state->avail_in <= SINGLE_SYM_THRESH) { | ||||||
| @@ -1281,8 +1247,8 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|         if (!flag || set_codes(code_huff, CODE_LEN_CODES, code_count)) |         if (!flag || set_codes(code_huff, CODE_LEN_CODES, code_count)) | ||||||
|                 return ISAL_INVALID_BLOCK; |                 return ISAL_INVALID_BLOCK; | ||||||
|  |  | ||||||
| 	make_inflate_huff_code_header(&inflate_code_huff, code_huff, CODE_LEN_CODES, |         make_inflate_huff_code_header(&inflate_code_huff, code_huff, CODE_LEN_CODES, code_count, | ||||||
| 				      code_count, CODE_LEN_CODES); |                                       CODE_LEN_CODES); | ||||||
|  |  | ||||||
|         /* Decode the lit/len and dist huffman codes using the code huffman code */ |         /* Decode the lit/len and dist huffman codes using the code huffman code */ | ||||||
|         count = lit_count; |         count = lit_count; | ||||||
| @@ -1293,8 +1259,7 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|                 symbol = decode_next_header(state, &inflate_code_huff); |                 symbol = decode_next_header(state, &inflate_code_huff); | ||||||
|  |  | ||||||
|                 if (state->read_in_length < 0) { |                 if (state->read_in_length < 0) { | ||||||
| 			if (current > &lit_and_dist_huff[256] |                         if (current > &lit_and_dist_huff[256] && lit_and_dist_huff[256].length <= 0) | ||||||
| 			    && lit_and_dist_huff[256].length <= 0) |  | ||||||
|                                 return ISAL_INVALID_BLOCK; |                                 return ISAL_INVALID_BLOCK; | ||||||
|                         return ISAL_END_INPUT; |                         return ISAL_END_INPUT; | ||||||
|                 } |                 } | ||||||
| @@ -1347,17 +1312,19 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|                                 current++; |                                 current++; | ||||||
|  |  | ||||||
|                                 if (rep_code.length == 0 // No symbol |                                 if (rep_code.length == 0 // No symbol | ||||||
| 				    || (previous >= lit_and_dist_huff + LIT_TABLE_SIZE + hlit)	// Dist table |                                     || (previous >= | ||||||
| 				    || (previous < lit_and_dist_huff + 264))	// Lit/Len with no extra |                                         lit_and_dist_huff + LIT_TABLE_SIZE + hlit) // Dist table | ||||||
|  |                                     || | ||||||
|  |                                     (previous < lit_and_dist_huff + 264)) // Lit/Len with no extra | ||||||
|                                         continue; |                                         continue; | ||||||
|  |  | ||||||
|                                 extra_count = |                                 extra_count = | ||||||
| 				    rfc_lookup_table.len_extra_bit_count |                                         rfc_lookup_table | ||||||
| 				    [previous - lit_and_dist_huff - LIT_TABLE_SIZE]; |                                                 .len_extra_bit_count[previous - lit_and_dist_huff - | ||||||
|  |                                                                      LIT_TABLE_SIZE]; | ||||||
|                                 lit_expand_count[rep_code.length]--; |                                 lit_expand_count[rep_code.length]--; | ||||||
| 				lit_expand_count[rep_code.length + |                                 lit_expand_count[rep_code.length + extra_count] += | ||||||
| 						 extra_count] += (1 << extra_count); |                                         (1 << extra_count); | ||||||
|  |  | ||||||
|                         } |                         } | ||||||
|                 } else if (symbol == 17) { |                 } else if (symbol == 17) { | ||||||
|                         /* If a repeat zeroes if found, update then next |                         /* If a repeat zeroes if found, update then next | ||||||
| @@ -1368,8 +1335,8 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|                         current = current + i; |                         current = current + i; | ||||||
|                         previous = current - 1; |                         previous = current - 1; | ||||||
|  |  | ||||||
| 			if (count != dist_count |                         if (count != dist_count && | ||||||
| 			    && current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) { |                             current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) { | ||||||
|                                 /* Switch code upon completion of lit_len table */ |                                 /* Switch code upon completion of lit_len table */ | ||||||
|                                 current += LIT_LEN - LIT_TABLE_SIZE - hlit; |                                 current += LIT_LEN - LIT_TABLE_SIZE - hlit; | ||||||
|                                 count = dist_count; |                                 count = dist_count; | ||||||
| @@ -1386,8 +1353,8 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|                         current = current + i; |                         current = current + i; | ||||||
|                         previous = current - 1; |                         previous = current - 1; | ||||||
|  |  | ||||||
| 			if (count != dist_count |                         if (count != dist_count && | ||||||
| 			    && current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) { |                             current > lit_and_dist_huff + LIT_TABLE_SIZE + hlit) { | ||||||
|                                 /* Switch code upon completion of lit_len table */ |                                 /* Switch code upon completion of lit_len table */ | ||||||
|                                 current += LIT_LEN - LIT_TABLE_SIZE - hlit; |                                 current += LIT_LEN - LIT_TABLE_SIZE - hlit; | ||||||
|                                 count = dist_count; |                                 count = dist_count; | ||||||
| @@ -1397,7 +1364,6 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|  |  | ||||||
|                 } else |                 } else | ||||||
|                         return ISAL_INVALID_BLOCK; |                         return ISAL_INVALID_BLOCK; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (current > end || lit_and_dist_huff[256].length <= 0) |         if (current > end || lit_and_dist_huff[256].length <= 0) | ||||||
| @@ -1412,11 +1378,11 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|         if (state->hist_bits && state->hist_bits < 15) |         if (state->hist_bits && state->hist_bits < 15) | ||||||
|                 max_dist = 2 * state->hist_bits; |                 max_dist = 2 * state->hist_bits; | ||||||
|  |  | ||||||
| 	make_inflate_huff_code_dist(&state->dist_huff_code, &lit_and_dist_huff[LIT_LEN], |         make_inflate_huff_code_dist(&state->dist_huff_code, &lit_and_dist_huff[LIT_LEN], DIST_LEN, | ||||||
| 				    DIST_LEN, dist_count, max_dist); |                                     dist_count, max_dist); | ||||||
|  |  | ||||||
| 	if (set_and_expand_lit_len_huffcode |         if (set_and_expand_lit_len_huffcode(lit_and_dist_huff, LIT_LEN, lit_count, lit_expand_count, | ||||||
| 	    (lit_and_dist_huff, LIT_LEN, lit_count, lit_expand_count, code_list)) |                                             code_list)) | ||||||
|                 return ISAL_INVALID_BLOCK; |                 return ISAL_INVALID_BLOCK; | ||||||
|  |  | ||||||
|         make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_and_dist_huff, LIT_LEN_ELEMS, |         make_inflate_huff_code_lit_len(&state->lit_huff_code, lit_and_dist_huff, LIT_LEN_ELEMS, | ||||||
| @@ -1429,7 +1395,8 @@ static int inline setup_dynamic_header(struct inflate_state *state) | |||||||
|  |  | ||||||
| /* Reads in the header pointed to by in_stream and sets up state to reflect that | /* Reads in the header pointed to by in_stream and sets up state to reflect that | ||||||
|  * header information*/ |  * header information*/ | ||||||
| static int read_header(struct inflate_state *state) | static int | ||||||
|  | read_header(struct inflate_state *state) | ||||||
| { | { | ||||||
|         uint8_t bytes; |         uint8_t bytes; | ||||||
|         uint32_t btype; |         uint32_t btype; | ||||||
| @@ -1485,7 +1452,8 @@ static int read_header(struct inflate_state *state) | |||||||
|  |  | ||||||
| /* Reads in the header pointed to by in_stream and sets up state to reflect that | /* Reads in the header pointed to by in_stream and sets up state to reflect that | ||||||
|  * header information*/ |  * header information*/ | ||||||
| static int read_header_stateful(struct inflate_state *state) | static int | ||||||
|  | read_header_stateful(struct inflate_state *state) | ||||||
| { | { | ||||||
|         uint64_t read_in_start = state->read_in; |         uint64_t read_in_start = state->read_in; | ||||||
|         int32_t read_in_length_start = state->read_in_length; |         int32_t read_in_length_start = state->read_in_length; | ||||||
| @@ -1522,8 +1490,7 @@ static int read_header_stateful(struct inflate_state *state) | |||||||
|                 /* Save off data so header can be decoded again with more data */ |                 /* Save off data so header can be decoded again with more data */ | ||||||
|                 state->read_in = read_in_start; |                 state->read_in = read_in_start; | ||||||
|                 state->read_in_length = read_in_length_start; |                 state->read_in_length = read_in_length_start; | ||||||
| 		memcpy(&state->tmp_in_buffer[state->tmp_in_size], next_in_start, |                 memcpy(&state->tmp_in_buffer[state->tmp_in_size], next_in_start, avail_in_start); | ||||||
| 		       avail_in_start); |  | ||||||
|                 state->tmp_in_size += avail_in_start; |                 state->tmp_in_size += avail_in_start; | ||||||
|                 state->avail_in = 0; |                 state->avail_in = 0; | ||||||
|                 state->next_in = next_in_start + avail_in_start; |                 state->next_in = next_in_start + avail_in_start; | ||||||
| @@ -1532,7 +1499,6 @@ static int read_header_stateful(struct inflate_state *state) | |||||||
|                 state->tmp_in_size = 0; |                 state->tmp_in_size = 0; | ||||||
|  |  | ||||||
|         return ret; |         return ret; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static int inline decode_literal_block(struct inflate_state *state) | static int inline decode_literal_block(struct inflate_state *state) | ||||||
| @@ -1598,11 +1564,11 @@ static int inline decode_literal_block(struct inflate_state *state) | |||||||
|                 return ISAL_OUT_OVERFLOW; |                 return ISAL_OUT_OVERFLOW; | ||||||
|  |  | ||||||
|         return 0; |         return 0; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Decodes the next block if it was encoded using a huffman code */ | /* Decodes the next block if it was encoded using a huffman code */ | ||||||
| int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_t * start_out) | int | ||||||
|  | decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_t *start_out) | ||||||
| { | { | ||||||
|         uint16_t next_lit; |         uint16_t next_lit; | ||||||
|         uint8_t next_dist; |         uint8_t next_dist; | ||||||
| @@ -1660,8 +1626,9 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_ | |||||||
|                                                 return ISAL_OUT_OVERFLOW; |                                                 return ISAL_OUT_OVERFLOW; | ||||||
|                                         else if (next_lits == 256) { |                                         else if (next_lits == 256) { | ||||||
|                                                 state->write_overflow_len -= 1; |                                                 state->write_overflow_len -= 1; | ||||||
| 						state->block_state = state->bfinal ? |                                                 state->block_state = state->bfinal | ||||||
| 						    ISAL_BLOCK_INPUT_DONE : ISAL_BLOCK_NEW_HDR; |                                                                              ? ISAL_BLOCK_INPUT_DONE | ||||||
|  |                                                                              : ISAL_BLOCK_NEW_HDR; | ||||||
|                                                 return ISAL_OUT_OVERFLOW; |                                                 return ISAL_OUT_OVERFLOW; | ||||||
|                                         } else { |                                         } else { | ||||||
|                                                 state->write_overflow_len -= 1; |                                                 state->write_overflow_len -= 1; | ||||||
| @@ -1678,8 +1645,8 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_ | |||||||
|                                 /* If the next symbol is the end of |                                 /* If the next symbol is the end of | ||||||
|                                  * block, update the state data |                                  * block, update the state data | ||||||
|                                  * accordingly */ |                                  * accordingly */ | ||||||
| 				state->block_state = state->bfinal ? |                                 state->block_state = | ||||||
| 				    ISAL_BLOCK_INPUT_DONE : ISAL_BLOCK_NEW_HDR; |                                         state->bfinal ? ISAL_BLOCK_INPUT_DONE : ISAL_BLOCK_NEW_HDR; | ||||||
|  |  | ||||||
|                         } else if (next_lit <= MAX_LIT_LEN_SYM) { |                         } else if (next_lit <= MAX_LIT_LEN_SYM) { | ||||||
|                                 /* Else if the next symbol is a repeat |                                 /* Else if the next symbol is a repeat | ||||||
| @@ -1695,10 +1662,11 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_ | |||||||
|                                         if (next_dist >= DIST_LEN) |                                         if (next_dist >= DIST_LEN) | ||||||
|                                                 return ISAL_INVALID_SYMBOL; |                                                 return ISAL_INVALID_SYMBOL; | ||||||
|  |  | ||||||
| 					look_back_dist = rfc->dist_start[next_dist] + |                                         look_back_dist = | ||||||
| 					    inflate_in_read_bits(state, |                                                 rfc->dist_start[next_dist] + | ||||||
| 								 rfc->dist_extra_bit_count |                                                 inflate_in_read_bits( | ||||||
| 								 [next_dist]); |                                                         state, | ||||||
|  |                                                         rfc->dist_extra_bit_count[next_dist]); | ||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|                                 if (state->read_in_length < 0) { |                                 if (state->read_in_length < 0) { | ||||||
| @@ -1725,12 +1693,10 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_ | |||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|                                 if (look_back_dist > repeat_length) |                                 if (look_back_dist > repeat_length) | ||||||
| 					memcpy(state->next_out, |                                         memcpy(state->next_out, state->next_out - look_back_dist, | ||||||
| 					       state->next_out - look_back_dist, |  | ||||||
|                                                repeat_length); |                                                repeat_length); | ||||||
|                                 else |                                 else | ||||||
| 					byte_copy(state->next_out, look_back_dist, |                                         byte_copy(state->next_out, look_back_dist, repeat_length); | ||||||
| 						  repeat_length); |  | ||||||
|  |  | ||||||
|                                 state->next_out += repeat_length; |                                 state->next_out += repeat_length; | ||||||
|                                 state->avail_out -= repeat_length; |                                 state->avail_out -= repeat_length; | ||||||
| @@ -1746,12 +1712,12 @@ int decode_huffman_code_block_stateless_base(struct inflate_state *state, uint8_ | |||||||
|                         next_lits >>= 8; |                         next_lits >>= 8; | ||||||
|                         sym_count--; |                         sym_count--; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_inflate_init(struct inflate_state *state) | void | ||||||
|  | isal_inflate_init(struct inflate_state *state) | ||||||
| { | { | ||||||
|  |  | ||||||
|         state->read_in = 0; |         state->read_in = 0; | ||||||
| @@ -1778,7 +1744,8 @@ void isal_inflate_init(struct inflate_state *state) | |||||||
|         state->tmp_out_valid = 0; |         state->tmp_out_valid = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void isal_inflate_reset(struct inflate_state *state) | void | ||||||
|  | isal_inflate_reset(struct inflate_state *state) | ||||||
| { | { | ||||||
|         state->read_in = 0; |         state->read_in = 0; | ||||||
|         state->read_in_length = 0; |         state->read_in_length = 0; | ||||||
| @@ -1798,8 +1765,8 @@ void isal_inflate_reset(struct inflate_state *state) | |||||||
|         state->tmp_out_valid = 0; |         state->tmp_out_valid = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t fixed_size_read(struct inflate_state *state, | static inline uint32_t | ||||||
| 				       uint8_t ** read_buf, int read_size) | fixed_size_read(struct inflate_state *state, uint8_t **read_buf, int read_size) | ||||||
| { | { | ||||||
|         uint32_t tmp_in_size = state->tmp_in_size; |         uint32_t tmp_in_size = state->tmp_in_size; | ||||||
|  |  | ||||||
| @@ -1815,8 +1782,7 @@ static inline uint32_t fixed_size_read(struct inflate_state *state, | |||||||
|  |  | ||||||
|         *read_buf = state->next_in; |         *read_buf = state->next_in; | ||||||
|         if (tmp_in_size) { |         if (tmp_in_size) { | ||||||
| 		memcpy(state->tmp_in_buffer + tmp_in_size, state->next_in, |                 memcpy(state->tmp_in_buffer + tmp_in_size, state->next_in, read_size - tmp_in_size); | ||||||
| 		       read_size - tmp_in_size); |  | ||||||
|                 *read_buf = state->tmp_in_buffer; |                 *read_buf = state->tmp_in_buffer; | ||||||
|                 state->tmp_in_size = 0; |                 state->tmp_in_size = 0; | ||||||
|         } |         } | ||||||
| @@ -1826,12 +1792,11 @@ static inline uint32_t fixed_size_read(struct inflate_state *state, | |||||||
|         tmp_in_size = 0; |         tmp_in_size = 0; | ||||||
|  |  | ||||||
|         return 0; |         return 0; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t buffer_header_copy(struct inflate_state *state, uint32_t in_len, | static inline uint32_t | ||||||
| 					  uint8_t * buf, uint32_t buffer_len, uint32_t offset, | buffer_header_copy(struct inflate_state *state, uint32_t in_len, uint8_t *buf, uint32_t buffer_len, | ||||||
| 					  uint32_t buf_error) |                    uint32_t offset, uint32_t buf_error) | ||||||
| { | { | ||||||
|         uint32_t len = in_len; |         uint32_t len = in_len; | ||||||
|         uint32_t buf_len = buffer_len - offset; |         uint32_t buf_len = buffer_len - offset; | ||||||
| @@ -1859,9 +1824,9 @@ static inline uint32_t buffer_header_copy(struct inflate_state *state, uint32_t | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline uint32_t string_header_copy(struct inflate_state *state, | static inline uint32_t | ||||||
| 					  char *str_buf, uint32_t str_len, | string_header_copy(struct inflate_state *state, char *str_buf, uint32_t str_len, uint32_t offset, | ||||||
| 					  uint32_t offset, uint32_t str_error) |                    uint32_t str_error) | ||||||
| { | { | ||||||
|         uint32_t len, max_len = str_len - offset; |         uint32_t len, max_len = str_len - offset; | ||||||
|  |  | ||||||
| @@ -1892,7 +1857,8 @@ static inline uint32_t string_header_copy(struct inflate_state *state, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int check_gzip_checksum(struct inflate_state *state) | static int | ||||||
|  | check_gzip_checksum(struct inflate_state *state) | ||||||
| { | { | ||||||
|         uint64_t trailer, crc, total_out; |         uint64_t trailer, crc, total_out; | ||||||
|         uint8_t *next_in; |         uint8_t *next_in; | ||||||
| @@ -1913,8 +1879,7 @@ static int check_gzip_checksum(struct inflate_state *state) | |||||||
|                         byte_count = state->read_in_length / 8; |                         byte_count = state->read_in_length / 8; | ||||||
|                         offset = state->read_in_length % 8; |                         offset = state->read_in_length % 8; | ||||||
|  |  | ||||||
| 			store_le_u64(state->tmp_in_buffer + tmp_in_size, |                         store_le_u64(state->tmp_in_buffer + tmp_in_size, state->read_in >> offset); | ||||||
| 				     state->read_in >> offset); |  | ||||||
|                         state->read_in = 0; |                         state->read_in = 0; | ||||||
|                         state->read_in_length = 0; |                         state->read_in_length = 0; | ||||||
|  |  | ||||||
| @@ -1942,7 +1907,8 @@ static int check_gzip_checksum(struct inflate_state *state) | |||||||
|                 return ISAL_DECOMP_OK; |                 return ISAL_DECOMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int check_zlib_checksum(struct inflate_state *state) | static int | ||||||
|  | check_zlib_checksum(struct inflate_state *state) | ||||||
| { | { | ||||||
|  |  | ||||||
|         uint32_t trailer; |         uint32_t trailer; | ||||||
| @@ -1964,8 +1930,7 @@ static int check_zlib_checksum(struct inflate_state *state) | |||||||
|                         byte_count = state->read_in_length / 8; |                         byte_count = state->read_in_length / 8; | ||||||
|                         offset = state->read_in_length % 8; |                         offset = state->read_in_length % 8; | ||||||
|  |  | ||||||
| 			store_le_u64(state->tmp_in_buffer + tmp_in_size, |                         store_le_u64(state->tmp_in_buffer + tmp_in_size, state->read_in >> offset); | ||||||
| 				     state->read_in >> offset); |  | ||||||
|                         state->read_in = 0; |                         state->read_in = 0; | ||||||
|                         state->read_in_length = 0; |                         state->read_in_length = 0; | ||||||
|  |  | ||||||
| @@ -1990,7 +1955,8 @@ static int check_zlib_checksum(struct inflate_state *state) | |||||||
|                 return ISAL_DECOMP_OK; |                 return ISAL_DECOMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *gz_hdr) | int | ||||||
|  | isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         int cm, flags = gz_hdr->flags, id1, id2; |         int cm, flags = gz_hdr->flags, id1, id2; | ||||||
|         uint16_t xlen = gz_hdr->extra_len; |         uint16_t xlen = gz_hdr->extra_len; | ||||||
| @@ -2049,9 +2015,7 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header * | |||||||
|  |  | ||||||
|                 case ISAL_GZIP_EXTRA: |                 case ISAL_GZIP_EXTRA: | ||||||
|                         offset = gz_hdr->extra_len - count; |                         offset = gz_hdr->extra_len - count; | ||||||
| 			ret = |                         ret = buffer_header_copy(state, count, gz_hdr->extra, gz_hdr->extra_buf_len, | ||||||
| 			    buffer_header_copy(state, count, gz_hdr->extra, |  | ||||||
| 					       gz_hdr->extra_buf_len, |  | ||||||
|                                                  offset, ISAL_EXTRA_OVERFLOW); |                                                  offset, ISAL_EXTRA_OVERFLOW); | ||||||
|  |  | ||||||
|                         if (ret) { |                         if (ret) { | ||||||
| @@ -2065,9 +2029,8 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header * | |||||||
|                 if (flags & NAME_FLAG) { |                 if (flags & NAME_FLAG) { | ||||||
|                 case ISAL_GZIP_NAME: |                 case ISAL_GZIP_NAME: | ||||||
|                         offset = state->count; |                         offset = state->count; | ||||||
| 			ret = string_header_copy(state, gz_hdr->name, |                         ret = string_header_copy(state, gz_hdr->name, gz_hdr->name_buf_len, offset, | ||||||
| 						 gz_hdr->name_buf_len, |                                                  ISAL_NAME_OVERFLOW); | ||||||
| 						 offset, ISAL_NAME_OVERFLOW); |  | ||||||
|                         if (ret) { |                         if (ret) { | ||||||
|                                 state->block_state = ISAL_GZIP_NAME; |                                 state->block_state = ISAL_GZIP_NAME; | ||||||
|                                 break; |                                 break; | ||||||
| @@ -2077,8 +2040,7 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header * | |||||||
|                 if (flags & COMMENT_FLAG) { |                 if (flags & COMMENT_FLAG) { | ||||||
|                 case ISAL_GZIP_COMMENT: |                 case ISAL_GZIP_COMMENT: | ||||||
|                         offset = state->count; |                         offset = state->count; | ||||||
| 			ret = string_header_copy(state, gz_hdr->comment, |                         ret = string_header_copy(state, gz_hdr->comment, gz_hdr->comment_buf_len, | ||||||
| 						 gz_hdr->comment_buf_len, |  | ||||||
|                                                  offset, ISAL_COMMENT_OVERFLOW); |                                                  offset, ISAL_COMMENT_OVERFLOW); | ||||||
|                         if (ret) { |                         if (ret) { | ||||||
|                                 state->block_state = ISAL_GZIP_COMMENT; |                                 state->block_state = ISAL_GZIP_COMMENT; | ||||||
| @@ -2112,7 +2074,8 @@ int isal_read_gzip_header(struct inflate_state *state, struct isal_gzip_header * | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_read_zlib_header(struct inflate_state *state, struct isal_zlib_header *zlib_hdr) | int | ||||||
|  | isal_read_zlib_header(struct inflate_state *state, struct isal_zlib_header *zlib_hdr) | ||||||
| { | { | ||||||
|         int cmf, method, flags; |         int cmf, method, flags; | ||||||
|         uint32_t block_state = state->block_state; |         uint32_t block_state = state->block_state; | ||||||
| @@ -2158,11 +2121,12 @@ int isal_read_zlib_header(struct inflate_state *state, struct isal_zlib_header * | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate_set_dict(struct inflate_state *state, uint8_t * dict, uint32_t dict_len) | int | ||||||
|  | isal_inflate_set_dict(struct inflate_state *state, uint8_t *dict, uint32_t dict_len) | ||||||
| { | { | ||||||
|  |  | ||||||
| 	if (state->block_state != ISAL_BLOCK_NEW_HDR |         if (state->block_state != ISAL_BLOCK_NEW_HDR || | ||||||
| 	    || state->tmp_out_processed != state->tmp_out_valid) |             state->tmp_out_processed != state->tmp_out_valid) | ||||||
|                 return ISAL_INVALID_STATE; |                 return ISAL_INVALID_STATE; | ||||||
|  |  | ||||||
|         if (dict_len > IGZIP_HIST_SIZE) { |         if (dict_len > IGZIP_HIST_SIZE) { | ||||||
| @@ -2178,7 +2142,8 @@ int isal_inflate_set_dict(struct inflate_state *state, uint8_t * dict, uint32_t | |||||||
|         return COMP_OK; |         return COMP_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate_stateless(struct inflate_state *state) | int | ||||||
|  | isal_inflate_stateless(struct inflate_state *state) | ||||||
| { | { | ||||||
|         uint32_t ret = 0; |         uint32_t ret = 0; | ||||||
|         uint8_t *start_out = state->next_out; |         uint8_t *start_out = state->next_out; | ||||||
| @@ -2209,7 +2174,6 @@ int isal_inflate_stateless(struct inflate_state *state) | |||||||
|                         return ret; |                         return ret; | ||||||
|                 if (z_hdr.dict_flag) |                 if (z_hdr.dict_flag) | ||||||
|                         return ISAL_NEED_DICT; |                         return ISAL_NEED_DICT; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         while (state->block_state != ISAL_BLOCK_FINISH) { |         while (state->block_state != ISAL_BLOCK_FINISH) { | ||||||
| @@ -2260,7 +2224,8 @@ int isal_inflate_stateless(struct inflate_state *state) | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate(struct inflate_state *state) | int | ||||||
|  | isal_inflate(struct inflate_state *state) | ||||||
| { | { | ||||||
|  |  | ||||||
|         uint8_t *start_out = state->next_out; |         uint8_t *start_out = state->next_out; | ||||||
| @@ -2313,8 +2278,7 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                 if (state->tmp_out_valid < 2 * ISAL_DEF_HIST_SIZE) { |                 if (state->tmp_out_valid < 2 * ISAL_DEF_HIST_SIZE) { | ||||||
|                         /* Setup to start decoding into temp buffer */ |                         /* Setup to start decoding into temp buffer */ | ||||||
|                         state->next_out = &state->tmp_out_buffer[state->tmp_out_valid]; |                         state->next_out = &state->tmp_out_buffer[state->tmp_out_valid]; | ||||||
| 			state->avail_out = |                         state->avail_out = sizeof(state->tmp_out_buffer) - ISAL_LOOK_AHEAD - | ||||||
| 			    sizeof(state->tmp_out_buffer) - ISAL_LOOK_AHEAD - |  | ||||||
|                                            state->tmp_out_valid; |                                            state->tmp_out_valid; | ||||||
|  |  | ||||||
|                         if ((int32_t) state->avail_out < 0) |                         if ((int32_t) state->avail_out < 0) | ||||||
| @@ -2322,8 +2286,8 @@ int isal_inflate(struct inflate_state *state) | |||||||
|  |  | ||||||
|                         /* Decode into internal buffer until exit */ |                         /* Decode into internal buffer until exit */ | ||||||
|                         while (state->block_state != ISAL_BLOCK_INPUT_DONE) { |                         while (state->block_state != ISAL_BLOCK_INPUT_DONE) { | ||||||
| 				if (state->block_state == ISAL_BLOCK_NEW_HDR |                                 if (state->block_state == ISAL_BLOCK_NEW_HDR || | ||||||
| 				    || state->block_state == ISAL_BLOCK_HDR) { |                                     state->block_state == ISAL_BLOCK_HDR) { | ||||||
|                                         ret = read_header_stateful(state); |                                         ret = read_header_stateful(state); | ||||||
|  |  | ||||||
|                                         if (ret) |                                         if (ret) | ||||||
| @@ -2372,15 +2336,15 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                 if (copy_size > avail_out) |                 if (copy_size > avail_out) | ||||||
|                         copy_size = avail_out; |                         copy_size = avail_out; | ||||||
|  |  | ||||||
| 		memcpy(state->next_out, |                 memcpy(state->next_out, &state->tmp_out_buffer[state->tmp_out_processed], | ||||||
| 		       &state->tmp_out_buffer[state->tmp_out_processed], copy_size); |                        copy_size); | ||||||
|  |  | ||||||
|                 state->tmp_out_processed += copy_size; |                 state->tmp_out_processed += copy_size; | ||||||
|                 state->avail_out -= copy_size; |                 state->avail_out -= copy_size; | ||||||
|                 state->next_out += copy_size; |                 state->next_out += copy_size; | ||||||
|  |  | ||||||
| 		if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK |                 if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK || | ||||||
| 		    || ret == ISAL_INVALID_SYMBOL) { |                     ret == ISAL_INVALID_SYMBOL) { | ||||||
|                         /* Set total_out to not count data in tmp_out_buffer */ |                         /* Set total_out to not count data in tmp_out_buffer */ | ||||||
|                         state->total_out -= state->tmp_out_valid - state->tmp_out_processed; |                         state->total_out -= state->tmp_out_valid - state->tmp_out_processed; | ||||||
|                         if (state->crc_flag) |                         if (state->crc_flag) | ||||||
| @@ -2392,8 +2356,8 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                  * decompressing into the out buffer */ |                  * decompressing into the out buffer */ | ||||||
|                 if (state->tmp_out_processed == state->tmp_out_valid) { |                 if (state->tmp_out_processed == state->tmp_out_valid) { | ||||||
|                         while (state->block_state != ISAL_BLOCK_INPUT_DONE) { |                         while (state->block_state != ISAL_BLOCK_INPUT_DONE) { | ||||||
| 				if (state->block_state == ISAL_BLOCK_NEW_HDR |                                 if (state->block_state == ISAL_BLOCK_NEW_HDR || | ||||||
| 				    || state->block_state == ISAL_BLOCK_HDR) { |                                     state->block_state == ISAL_BLOCK_HDR) { | ||||||
|                                         ret = read_header_stateful(state); |                                         ret = read_header_stateful(state); | ||||||
|                                         if (ret) |                                         if (ret) | ||||||
|                                                 break; |                                                 break; | ||||||
| @@ -2402,9 +2366,7 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                                 if (state->block_state == ISAL_BLOCK_TYPE0) |                                 if (state->block_state == ISAL_BLOCK_TYPE0) | ||||||
|                                         ret = decode_literal_block(state); |                                         ret = decode_literal_block(state); | ||||||
|                                 else |                                 else | ||||||
| 					ret = |                                         ret = decode_huffman_code_block_stateless(state, start_out); | ||||||
| 					    decode_huffman_code_block_stateless(state, |  | ||||||
| 										start_out); |  | ||||||
|                                 if (ret) |                                 if (ret) | ||||||
|                                         break; |                                         break; | ||||||
|                         } |                         } | ||||||
| @@ -2413,14 +2375,13 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                 if (state->crc_flag) |                 if (state->crc_flag) | ||||||
|                         update_checksum(state, start_out, state->next_out - start_out); |                         update_checksum(state, start_out, state->next_out - start_out); | ||||||
|  |  | ||||||
| 		if (state->block_state != ISAL_BLOCK_INPUT_DONE |                 if (state->block_state != ISAL_BLOCK_INPUT_DONE || | ||||||
| 		    || state->copy_overflow_length + state->write_overflow_len + |                     state->copy_overflow_length + state->write_overflow_len + state->tmp_out_valid > | ||||||
| 		    state->tmp_out_valid > sizeof(state->tmp_out_buffer)) { |                             sizeof(state->tmp_out_buffer)) { | ||||||
|                         /* Save decompression history in tmp_out buffer */ |                         /* Save decompression history in tmp_out buffer */ | ||||||
| 			if (state->tmp_out_valid == state->tmp_out_processed |                         if (state->tmp_out_valid == state->tmp_out_processed && | ||||||
| 			    && avail_out - state->avail_out >= ISAL_DEF_HIST_SIZE) { |                             avail_out - state->avail_out >= ISAL_DEF_HIST_SIZE) { | ||||||
| 				memcpy(state->tmp_out_buffer, |                                 memcpy(state->tmp_out_buffer, state->next_out - ISAL_DEF_HIST_SIZE, | ||||||
| 				       state->next_out - ISAL_DEF_HIST_SIZE, |  | ||||||
|                                        ISAL_DEF_HIST_SIZE); |                                        ISAL_DEF_HIST_SIZE); | ||||||
|                                 state->tmp_out_valid = ISAL_DEF_HIST_SIZE; |                                 state->tmp_out_valid = ISAL_DEF_HIST_SIZE; | ||||||
|                                 state->tmp_out_processed = ISAL_DEF_HIST_SIZE; |                                 state->tmp_out_processed = ISAL_DEF_HIST_SIZE; | ||||||
| @@ -2430,12 +2391,10 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                                 if (shift_size > state->tmp_out_processed) |                                 if (shift_size > state->tmp_out_processed) | ||||||
|                                         shift_size = state->tmp_out_processed; |                                         shift_size = state->tmp_out_processed; | ||||||
|  |  | ||||||
| 				memmove(state->tmp_out_buffer, |                                 memmove(state->tmp_out_buffer, &state->tmp_out_buffer[shift_size], | ||||||
| 					&state->tmp_out_buffer[shift_size], |  | ||||||
|                                         state->tmp_out_valid - shift_size); |                                         state->tmp_out_valid - shift_size); | ||||||
|                                 state->tmp_out_valid -= shift_size; |                                 state->tmp_out_valid -= shift_size; | ||||||
|                                 state->tmp_out_processed -= shift_size; |                                 state->tmp_out_processed -= shift_size; | ||||||
|  |  | ||||||
|                         } |                         } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -2458,14 +2417,14 @@ int isal_inflate(struct inflate_state *state) | |||||||
|                         state->copy_overflow_length = 0; |                         state->copy_overflow_length = 0; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| 		if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK |                 if (ret == ISAL_INVALID_LOOKBACK || ret == ISAL_INVALID_BLOCK || | ||||||
| 		    || ret == ISAL_INVALID_SYMBOL) { |                     ret == ISAL_INVALID_SYMBOL) { | ||||||
|                         state->total_out -= state->tmp_out_valid - state->tmp_out_processed; |                         state->total_out -= state->tmp_out_valid - state->tmp_out_processed; | ||||||
|                         return ret; |                         return ret; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| 		if (state->block_state == ISAL_BLOCK_INPUT_DONE |                 if (state->block_state == ISAL_BLOCK_INPUT_DONE && | ||||||
| 		    && state->tmp_out_valid == state->tmp_out_processed) { |                     state->tmp_out_valid == state->tmp_out_processed) { | ||||||
|                         state->block_state = ISAL_BLOCK_FINISH; |                         state->block_state = ISAL_BLOCK_FINISH; | ||||||
|  |  | ||||||
|                         switch (state->crc_flag) { |                         switch (state->crc_flag) { | ||||||
|   | |||||||
| @@ -44,8 +44,9 @@ | |||||||
| #define MAX_INPUT_FILE_SIZE 512L * 1024L * 1024L | #define MAX_INPUT_FILE_SIZE 512L * 1024L * 1024L | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len, | int | ||||||
| 		       uint8_t * uncompress_buf, uint32_t * uncompress_len) | inflate_multi_pass(uint8_t *compress_buf, uint64_t compress_len, uint8_t *uncompress_buf, | ||||||
|  |                    uint32_t *uncompress_len) | ||||||
| { | { | ||||||
|         struct inflate_state *state = NULL; |         struct inflate_state *state = NULL; | ||||||
|         int ret = 0; |         int ret = 0; | ||||||
| @@ -146,23 +147,20 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len, | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int test(uint8_t * compressed_stream, | int | ||||||
| 	 uint64_t * compressed_length, | test(uint8_t *compressed_stream, uint64_t *compressed_length, uint8_t *uncompressed_stream, | ||||||
| 	 uint8_t * uncompressed_stream, uint32_t uncompressed_length, |      uint32_t uncompressed_length, uint8_t *uncompressed_test_stream, | ||||||
| 	 uint8_t * uncompressed_test_stream, uint32_t uncompressed_test_stream_length) |      uint32_t uncompressed_test_stream_length) | ||||||
| { | { | ||||||
|         int ret; |         int ret; | ||||||
| 	ret = |         ret = compress2(compressed_stream, (uLongf *) compressed_length, uncompressed_stream, | ||||||
| 	    compress2(compressed_stream, (uLongf *) compressed_length, |                         uncompressed_length, 6); | ||||||
| 		      uncompressed_stream, uncompressed_length, 6); |  | ||||||
|         if (ret) { |         if (ret) { | ||||||
|                 printf("Failed compressing input with exit code %d", ret); |                 printf("Failed compressing input with exit code %d", ret); | ||||||
|                 return ret; |                 return ret; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	ret = |         ret = inflate_multi_pass(compressed_stream + 2, *compressed_length - 2 - 4, | ||||||
| 	    inflate_multi_pass(compressed_stream + 2, |  | ||||||
| 			       *compressed_length - 2 - 4, |  | ||||||
|                                  uncompressed_test_stream, &uncompressed_test_stream_length); |                                  uncompressed_test_stream, &uncompressed_test_stream_length); | ||||||
|         switch (ret) { |         switch (ret) { | ||||||
|         case 0: |         case 0: | ||||||
| @@ -195,8 +193,8 @@ int test(uint8_t * compressed_stream, | |||||||
|  |  | ||||||
|         if (uncompressed_test_stream_length != uncompressed_length) { |         if (uncompressed_test_stream_length != uncompressed_length) { | ||||||
|                 printf("incorrect amount of data was decompressed from compressed data\n"); |                 printf("incorrect amount of data was decompressed from compressed data\n"); | ||||||
| 		printf("%d decompressed of %d compressed", |                 printf("%d decompressed of %d compressed", uncompressed_test_stream_length, | ||||||
| 		       uncompressed_test_stream_length, uncompressed_length); |                        uncompressed_length); | ||||||
|                 return -1; |                 return -1; | ||||||
|         } |         } | ||||||
|         if (memcmp(uncompressed_stream, uncompressed_test_stream, uncompressed_length)) { |         if (memcmp(uncompressed_stream, uncompressed_test_stream, uncompressed_length)) { | ||||||
| @@ -214,7 +212,8 @@ int test(uint8_t * compressed_stream, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char **argv) | int | ||||||
|  | main(int argc, char **argv) | ||||||
| { | { | ||||||
|         int i, j, ret = 0, fin_ret = 0; |         int i, j, ret = 0, fin_ret = 0; | ||||||
|         FILE *file = NULL; |         FILE *file = NULL; | ||||||
| @@ -272,12 +271,11 @@ int main(int argc, char **argv) | |||||||
|                         exit(0); |                         exit(0); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| 		uncompressed_length = |                 uncompressed_length = (uncompressed_stream == NULL) | ||||||
| 		    (uncompressed_stream == NULL) ? 0 : fread(uncompressed_stream, 1, |                                               ? 0 | ||||||
| 							      file_length, file); |                                               : fread(uncompressed_stream, 1, file_length, file); | ||||||
|                 uncompressed_test_stream_length = uncompressed_length; |                 uncompressed_test_stream_length = uncompressed_length; | ||||||
| 		ret = |                 ret = test(compressed_stream, &compressed_length, uncompressed_stream, | ||||||
| 		    test(compressed_stream, &compressed_length, uncompressed_stream, |  | ||||||
|                            uncompressed_length, uncompressed_test_stream, |                            uncompressed_length, uncompressed_test_stream, | ||||||
|                            uncompressed_test_stream_length); |                            uncompressed_test_stream_length); | ||||||
|                 if (ret) { |                 if (ret) { | ||||||
|   | |||||||
| @@ -106,12 +106,7 @@ int level_size_buf[10] = { | |||||||
| #endif | #endif | ||||||
| }; | }; | ||||||
|  |  | ||||||
| enum { | enum { ISAL_STATELESS, ISAL_STATEFUL, ISAL_WITH_DICTIONARY, ZLIB }; | ||||||
| 	ISAL_STATELESS, |  | ||||||
| 	ISAL_STATEFUL, |  | ||||||
| 	ISAL_WITH_DICTIONARY, |  | ||||||
| 	ZLIB |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct compress_strategy { | struct compress_strategy { | ||||||
|         int32_t mode; |         int32_t mode; | ||||||
| @@ -138,24 +133,29 @@ struct perf_info { | |||||||
|         struct perf start; |         struct perf start; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| void init_perf_info(struct perf_info *info) | void | ||||||
|  | init_perf_info(struct perf_info *info) | ||||||
| { | { | ||||||
|         memset(info, 0, sizeof(*info)); |         memset(info, 0, sizeof(*info)); | ||||||
|         info->deflate_time = BENCHMARK_TIME; |         info->deflate_time = BENCHMARK_TIME; | ||||||
|         info->inflate_time = BENCHMARK_TIME; |         info->inflate_time = BENCHMARK_TIME; | ||||||
| } | } | ||||||
|  |  | ||||||
| int usage(void) | int | ||||||
|  | usage(void) | ||||||
| { | { | ||||||
|         fprintf(stderr, |         fprintf(stderr, | ||||||
|                 "Usage: igzip_perf [options] <infile>\n" |                 "Usage: igzip_perf [options] <infile>\n" | ||||||
|                 "  -h          help, print this message\n" |                 "  -h          help, print this message\n" | ||||||
| 		"  The options -l, -f, -z may be used up to " |                 "  The options -l, -f, -z may be used up to " xstr( | ||||||
| 		xstr(COMPRESSION_QUEUE_LIMIT) " times\n" |                         COMPRESSION_QUEUE_LIMIT) " times\n" | ||||||
| 		"  -l <level>  isa-l stateless deflate level to test (" |                                                  "  -l <level>  isa-l stateless deflate level to " | ||||||
| 		xstr(ISAL_DEF_MIN_LEVEL) "-" xstr(ISAL_DEF_MAX_LEVEL) ")\n" |                                                  "test (" xstr(ISAL_DEF_MIN_LEVEL) "-" xstr( | ||||||
| 		"  -f <level>  isa-l stateful deflate level to test (" |                                                          ISAL_DEF_MAX_LEVEL) ")\n" | ||||||
| 		xstr(ISAL_DEF_MIN_LEVEL) "-" xstr(ISAL_DEF_MAX_LEVEL) ")\n" |                                                                              "  -f <level>  isa-l " | ||||||
|  |                                                                              "stateful deflate " | ||||||
|  |                                                                              "level to test (" xstr(ISAL_DEF_MIN_LEVEL) "-" xstr( | ||||||
|  |                                                                                      ISAL_DEF_MAX_LEVEL) ")\n" | ||||||
|                                                                                                          "  -z <level>  zlib  deflate level to test\n" |                                                                                                          "  -z <level>  zlib  deflate level to test\n" | ||||||
|                                                                                                          "  -d <time>   approx time in seconds for deflate (at least 0)\n" |                                                                                                          "  -d <time>   approx time in seconds for deflate (at least 0)\n" | ||||||
|                                                                                                          "  -i <time>   approx time in seconds for inflate (at least 0)\n" |                                                                                                          "  -i <time>   approx time in seconds for inflate (at least 0)\n" | ||||||
| @@ -170,20 +170,23 @@ int usage(void) | |||||||
|         exit(0); |         exit(0); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_perf_info_line(struct perf_info *info) | void | ||||||
|  | print_perf_info_line(struct perf_info *info) | ||||||
| { | { | ||||||
|         printf("igzip_perf-> compress level: %d flush_type: %d block_size: %d\n", |         printf("igzip_perf-> compress level: %d flush_type: %d block_size: %d\n", | ||||||
|                info->strategy.level, info->flush_type, info->inblock_size); |                info->strategy.level, info->flush_type, info->inblock_size); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_file_line(struct perf_info *info) | void | ||||||
|  | print_file_line(struct perf_info *info) | ||||||
| { | { | ||||||
|         printf("  file info-> name: %s file_size: %lu compress_size: %lu ratio: %2.02f%%\n", |         printf("  file info-> name: %s file_size: %lu compress_size: %lu ratio: %2.02f%%\n", | ||||||
|                info->file_name, info->file_size, info->deflate_size, |                info->file_name, info->file_size, info->deflate_size, | ||||||
|                100.0 * info->deflate_size / info->file_size); |                100.0 * info->deflate_size / info->file_size); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_deflate_perf_line(struct perf_info *info) | void | ||||||
|  | print_deflate_perf_line(struct perf_info *info) | ||||||
| { | { | ||||||
|         if (info->strategy.mode == ISAL_STATELESS) |         if (info->strategy.mode == ISAL_STATELESS) | ||||||
|                 printf("    isal_stateless_deflate-> "); |                 printf("    isal_stateless_deflate-> "); | ||||||
| @@ -197,7 +200,8 @@ void print_deflate_perf_line(struct perf_info *info) | |||||||
|         perf_print(info->start, info->file_size); |         perf_print(info->start, info->file_size); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_inflate_perf_line(struct perf_info *info) | void | ||||||
|  | print_inflate_perf_line(struct perf_info *info) | ||||||
| { | { | ||||||
|         if (info->inflate_mode == ISAL_STATELESS) |         if (info->inflate_mode == ISAL_STATELESS) | ||||||
|                 printf("    isal_stateless_inflate-> "); |                 printf("    isal_stateless_inflate-> "); | ||||||
| @@ -211,10 +215,10 @@ void print_inflate_perf_line(struct perf_info *info) | |||||||
|         perf_print(info->start, info->file_size); |         perf_print(info->start, info->file_size); | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_round(struct isal_zstream *stream, uint8_t * outbuf, uint32_t outbuf_size, | int | ||||||
| 		       uint8_t * inbuf, uint32_t inbuf_size, | isal_deflate_round(struct isal_zstream *stream, uint8_t *outbuf, uint32_t outbuf_size, | ||||||
| 		       uint32_t level, uint8_t * level_buf, uint32_t level_buf_size, |                    uint8_t *inbuf, uint32_t inbuf_size, uint32_t level, uint8_t *level_buf, | ||||||
| 		       int flush_type, int hist_bits) |                    uint32_t level_buf_size, int flush_type, int hist_bits) | ||||||
| { | { | ||||||
|         int check; |         int check; | ||||||
|  |  | ||||||
| @@ -241,11 +245,11 @@ int isal_deflate_round(struct isal_zstream *stream, uint8_t * outbuf, uint32_t o | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_dict_round(struct isal_zstream *stream, uint8_t * outbuf, | int | ||||||
| 			    uint32_t outbuf_size, uint8_t * inbuf, | isal_deflate_dict_round(struct isal_zstream *stream, uint8_t *outbuf, uint32_t outbuf_size, | ||||||
| 			    uint32_t inbuf_size, uint32_t level, |                         uint8_t *inbuf, uint32_t inbuf_size, uint32_t level, uint8_t *level_buf, | ||||||
| 			    uint8_t * level_buf, uint32_t level_buf_size, int flush_type, |                         uint32_t level_buf_size, int flush_type, int hist_bits, | ||||||
| 			    int hist_bits, struct isal_dict *dict_str) |                         struct isal_dict *dict_str) | ||||||
| { | { | ||||||
|         int check; |         int check; | ||||||
|  |  | ||||||
| @@ -275,7 +279,8 @@ int isal_deflate_dict_round(struct isal_zstream *stream, uint8_t * outbuf, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate_round(struct inflate_state *state, uint8_t * inbuf, uint32_t inbuf_size, | int | ||||||
|  | isal_inflate_round(struct inflate_state *state, uint8_t *inbuf, uint32_t inbuf_size, | ||||||
|                    uint8_t *outbuf, uint32_t outbuf_size, int hist_bits) |                    uint8_t *outbuf, uint32_t outbuf_size, int hist_bits) | ||||||
| { | { | ||||||
|         int check = 0; |         int check = 0; | ||||||
| @@ -298,11 +303,11 @@ int isal_inflate_round(struct inflate_state *state, uint8_t * inbuf, uint32_t in | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_stateful_round(struct isal_zstream *stream, uint8_t * outbuf, | int | ||||||
| 				uint32_t outbuf_size, uint8_t * inbuf, | isal_deflate_stateful_round(struct isal_zstream *stream, uint8_t *outbuf, uint32_t outbuf_size, | ||||||
| 				uint32_t inbuf_size, uint32_t in_block_size, uint32_t level, |                             uint8_t *inbuf, uint32_t inbuf_size, uint32_t in_block_size, | ||||||
| 				uint8_t * level_buf, uint32_t level_buf_size, int flush_type, |                             uint32_t level, uint8_t *level_buf, uint32_t level_buf_size, | ||||||
| 				int hist_bits) |                             int flush_type, int hist_bits) | ||||||
| { | { | ||||||
|         uint64_t inbuf_remaining; |         uint64_t inbuf_remaining; | ||||||
|         int check = COMP_OK; |         int check = COMP_OK; | ||||||
| @@ -345,10 +350,10 @@ int isal_deflate_stateful_round(struct isal_zstream *stream, uint8_t * outbuf, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate_stateful_round(struct inflate_state *state, uint8_t * inbuf, | int | ||||||
| 				uint32_t inbuf_size, uint32_t in_block_size, uint8_t * outbuf, | isal_inflate_stateful_round(struct inflate_state *state, uint8_t *inbuf, uint32_t inbuf_size, | ||||||
| 				uint32_t outbuf_size, int hist_bits, |                             uint32_t in_block_size, uint8_t *outbuf, uint32_t outbuf_size, | ||||||
| 				uint8_t * dict_buf, int dict_file_size) |                             int hist_bits, uint8_t *dict_buf, int dict_file_size) | ||||||
| { | { | ||||||
|         int check = ISAL_DECOMP_OK; |         int check = ISAL_DECOMP_OK; | ||||||
|         uint64_t inbuf_remaining; |         uint64_t inbuf_remaining; | ||||||
| @@ -379,9 +384,9 @@ int isal_inflate_stateful_round(struct inflate_state *state, uint8_t * inbuf, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int zlib_deflate_round(z_stream * gstream, uint8_t * outbuf, uInt outbuf_size, | int | ||||||
| 		       uint8_t * inbuf, uLong inbuf_size, | zlib_deflate_round(z_stream *gstream, uint8_t *outbuf, uInt outbuf_size, uint8_t *inbuf, | ||||||
| 		       uLong in_block_size, int level, int flush_type) |                    uLong inbuf_size, uLong in_block_size, int level, int flush_type) | ||||||
| { | { | ||||||
|         uLong inbuf_remaining; |         uLong inbuf_remaining; | ||||||
|         int check = Z_OK; |         int check = Z_OK; | ||||||
| @@ -417,8 +422,9 @@ int zlib_deflate_round(z_stream * gstream, uint8_t * outbuf, uInt outbuf_size, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int zlib_inflate_round(z_stream * gstream, uint8_t * inbuf, | int | ||||||
| 		       uLong inbuf_size, uint8_t * outbuf, uInt outbuf_size) | zlib_inflate_round(z_stream *gstream, uint8_t *inbuf, uLong inbuf_size, uint8_t *outbuf, | ||||||
|  |                    uInt outbuf_size) | ||||||
| { | { | ||||||
|         int check = 0; |         int check = 0; | ||||||
|  |  | ||||||
| @@ -436,9 +442,9 @@ int zlib_inflate_round(z_stream * gstream, uint8_t * inbuf, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | int | ||||||
| 		      uint64_t inbuf_size, int level, int flush_type, int hist_bits, int time, | isal_deflate_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, uint64_t inbuf_size, | ||||||
| 		      struct perf *start) |                   int level, int flush_type, int hist_bits, int time, struct perf *start) | ||||||
| { | { | ||||||
|         struct isal_zstream stream; |         struct isal_zstream stream; | ||||||
|         uint8_t *level_buf = NULL; |         uint8_t *level_buf = NULL; | ||||||
| @@ -450,18 +456,18 @@ int isal_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | |||||||
|                         return 1; |                         return 1; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	BENCHMARK(start, time, check = |         BENCHMARK(start, time, | ||||||
| 		  isal_deflate_round(&stream, outbuf, *outbuf_size, inbuf, |                   check = isal_deflate_round(&stream, outbuf, *outbuf_size, inbuf, inbuf_size, | ||||||
| 				     inbuf_size, level, level_buf, |                                              level, level_buf, level_size_buf[level], flush_type, | ||||||
| 				     level_size_buf[level], flush_type, hist_bits)); |                                              hist_bits)); | ||||||
|         *outbuf_size = stream.total_out; |         *outbuf_size = stream.total_out; | ||||||
|         return check; |         return check; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_dict_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | int | ||||||
| 			   uint64_t inbuf_size, int level, int flush_type, int hist_bits, | isal_deflate_dict_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, uint64_t inbuf_size, | ||||||
| 			   int time, struct perf *start, uint8_t * dict_buf, |                        int level, int flush_type, int hist_bits, int time, struct perf *start, | ||||||
| 			   int dict_file_size) |                        uint8_t *dict_buf, int dict_file_size) | ||||||
| { | { | ||||||
|         struct isal_zstream stream; |         struct isal_zstream stream; | ||||||
|         struct isal_dict dict_str; |         struct isal_dict dict_str; | ||||||
| @@ -481,21 +487,20 @@ int isal_deflate_dict_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * i | |||||||
|                 return 1; |                 return 1; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	BENCHMARK(start, time, check = |         BENCHMARK(start, time, | ||||||
| 		  isal_deflate_dict_round(&stream, outbuf, *outbuf_size, inbuf, |                   check = isal_deflate_dict_round(&stream, outbuf, *outbuf_size, inbuf, inbuf_size, | ||||||
| 					  inbuf_size, level, level_buf, |                                                   level, level_buf, level_size_buf[level], | ||||||
| 					  level_size_buf[level], flush_type, hist_bits, |                                                   flush_type, hist_bits, &dict_str)); | ||||||
| 					  &dict_str)); |  | ||||||
|         if (level_buf != NULL) |         if (level_buf != NULL) | ||||||
|                 free(level_buf); |                 free(level_buf); | ||||||
|         *outbuf_size = stream.total_out; |         *outbuf_size = stream.total_out; | ||||||
|         return check; |         return check; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_deflate_stateful_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | int | ||||||
| 			       uint64_t inbuf_size, int level, int flush_type, | isal_deflate_stateful_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, | ||||||
| 			       uint64_t in_block_size, int hist_bits, int time, |                            uint64_t inbuf_size, int level, int flush_type, uint64_t in_block_size, | ||||||
| 			       struct perf *start) |                            int hist_bits, int time, struct perf *start) | ||||||
| { | { | ||||||
|         struct isal_zstream stream; |         struct isal_zstream stream; | ||||||
|         uint8_t *level_buf = NULL; |         uint8_t *level_buf = NULL; | ||||||
| @@ -510,18 +515,18 @@ int isal_deflate_stateful_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t | |||||||
|                         return 1; |                         return 1; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| 	BENCHMARK(start, time, check = |         BENCHMARK(start, time, | ||||||
| 		  isal_deflate_stateful_round(&stream, outbuf, *outbuf_size, inbuf, inbuf_size, |                   check = isal_deflate_stateful_round( | ||||||
| 					      in_block_size, level, level_buf, |                           &stream, outbuf, *outbuf_size, inbuf, inbuf_size, in_block_size, level, | ||||||
| 					      level_size_buf[level], flush_type, hist_bits)); |                           level_buf, level_size_buf[level], flush_type, hist_bits)); | ||||||
|         *outbuf_size = stream.total_out; |         *outbuf_size = stream.total_out; | ||||||
|         return check; |         return check; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int zlib_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | int | ||||||
| 		      uint64_t inbuf_size, int level, int flush_type, | zlib_deflate_perf(uint8_t *outbuf, uint64_t *outbuf_size, uint8_t *inbuf, uint64_t inbuf_size, | ||||||
| 		      uint64_t in_block_size, int hist_bits, int time, struct perf *start) |                   int level, int flush_type, uint64_t in_block_size, int hist_bits, int time, | ||||||
|  |                   struct perf *start) | ||||||
| { | { | ||||||
|         int check; |         int check; | ||||||
|         z_stream gstream; |         z_stream gstream; | ||||||
| @@ -547,8 +552,8 @@ int zlib_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | |||||||
|         if (0 != deflateInit2(&gstream, level, Z_DEFLATED, hist_bits, 9, Z_DEFAULT_STRATEGY)) |         if (0 != deflateInit2(&gstream, level, Z_DEFLATED, hist_bits, 9, Z_DEFAULT_STRATEGY)) | ||||||
|                 return 1; |                 return 1; | ||||||
|  |  | ||||||
| 	BENCHMARK(start, time, check = |         BENCHMARK(start, time, | ||||||
| 		  zlib_deflate_round(&gstream, outbuf, *outbuf_size, inbuf, inbuf_size, |                   check = zlib_deflate_round(&gstream, outbuf, *outbuf_size, inbuf, inbuf_size, | ||||||
|                                              in_block_size, level, flush_type)); |                                              in_block_size, level, flush_type)); | ||||||
|  |  | ||||||
|         *outbuf_size = gstream.total_out; |         *outbuf_size = gstream.total_out; | ||||||
| @@ -557,9 +562,9 @@ int zlib_deflate_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * inbuf, | |||||||
|         return check; |         return check; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf, | int | ||||||
| 		      uint64_t outbuf_size, uint8_t * filebuf, uint64_t file_size, | isal_inflate_perf(uint8_t *inbuf, uint64_t inbuf_size, uint8_t *outbuf, uint64_t outbuf_size, | ||||||
| 		      int hist_bits, int time, struct perf *start) |                   uint8_t *filebuf, uint64_t file_size, int hist_bits, int time, struct perf *start) | ||||||
| { | { | ||||||
|         struct inflate_state state; |         struct inflate_state state; | ||||||
|         int check; |         int check; | ||||||
| @@ -569,16 +574,17 @@ int isal_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf, | |||||||
|         if (check || state.total_out != file_size || memcmp(outbuf, filebuf, file_size)) |         if (check || state.total_out != file_size || memcmp(outbuf, filebuf, file_size)) | ||||||
|                 return 1; |                 return 1; | ||||||
|  |  | ||||||
| 	BENCHMARK(start, time, isal_inflate_round(&state, inbuf, inbuf_size, |         BENCHMARK(start, time, | ||||||
| 						  outbuf, outbuf_size, hist_bits)); |                   isal_inflate_round(&state, inbuf, inbuf_size, outbuf, outbuf_size, hist_bits)); | ||||||
|  |  | ||||||
|         return check; |         return check; | ||||||
| } | } | ||||||
|  |  | ||||||
| int isal_inflate_stateful_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf, | int | ||||||
|  | isal_inflate_stateful_perf(uint8_t *inbuf, uint64_t inbuf_size, uint8_t *outbuf, | ||||||
|                            uint64_t outbuf_size, uint8_t *filebuf, uint64_t file_size, |                            uint64_t outbuf_size, uint8_t *filebuf, uint64_t file_size, | ||||||
| 			       uint64_t in_block_size, int hist_bits, int time, |                            uint64_t in_block_size, int hist_bits, int time, struct perf *start, | ||||||
| 			       struct perf *start, uint8_t * dict_buf, int dict_file_size) |                            uint8_t *dict_buf, int dict_file_size) | ||||||
| { | { | ||||||
|         struct inflate_state state; |         struct inflate_state state; | ||||||
|         int check; |         int check; | ||||||
| @@ -593,16 +599,14 @@ int isal_inflate_stateful_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * o | |||||||
|  |  | ||||||
|         BENCHMARK(start, time, |         BENCHMARK(start, time, | ||||||
|                   isal_inflate_stateful_round(&state, inbuf, inbuf_size, in_block_size, outbuf, |                   isal_inflate_stateful_round(&state, inbuf, inbuf_size, in_block_size, outbuf, | ||||||
| 					      outbuf_size, hist_bits, dict_buf, |                                               outbuf_size, hist_bits, dict_buf, dict_file_size)); | ||||||
| 					      dict_file_size)); |  | ||||||
|  |  | ||||||
|         return 0; |         return 0; | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int zlib_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf, | int | ||||||
| 		      uint64_t outbuf_size, uint8_t * filebuf, uint64_t file_size, | zlib_inflate_perf(uint8_t *inbuf, uint64_t inbuf_size, uint8_t *outbuf, uint64_t outbuf_size, | ||||||
| 		      int hist_bits, int time, struct perf *start) |                   uint8_t *filebuf, uint64_t file_size, int hist_bits, int time, struct perf *start) | ||||||
| { | { | ||||||
|         int check; |         int check; | ||||||
|         z_stream gstream; |         z_stream gstream; | ||||||
| @@ -632,7 +636,8 @@ int zlib_inflate_perf(uint8_t * inbuf, uint64_t inbuf_size, uint8_t * outbuf, | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         FILE *in = NULL; |         FILE *in = NULL; | ||||||
|         FILE *dict_fn = NULL; |         FILE *dict_fn = NULL; | ||||||
| @@ -744,8 +749,8 @@ int main(int argc, char *argv[]) | |||||||
|                         break; |                         break; | ||||||
|                 case 'y': |                 case 'y': | ||||||
|                         info.flush_type = atoi(optarg); |                         info.flush_type = atoi(optarg); | ||||||
| 			if (info.flush_type != NO_FLUSH && info.flush_type != SYNC_FLUSH |                         if (info.flush_type != NO_FLUSH && info.flush_type != SYNC_FLUSH && | ||||||
| 			    && info.flush_type != FULL_FLUSH) { |                             info.flush_type != FULL_FLUSH) { | ||||||
|                                 printf("Unsupported flush type\n"); |                                 printf("Unsupported flush type\n"); | ||||||
|                                 exit(0); |                                 exit(0); | ||||||
|                         } |                         } | ||||||
| @@ -848,32 +853,26 @@ int main(int argc, char *argv[]) | |||||||
|  |  | ||||||
|                 if (dict_file_size != 0) { |                 if (dict_file_size != 0) { | ||||||
|                         info.strategy.mode = ISAL_WITH_DICTIONARY; |                         info.strategy.mode = ISAL_WITH_DICTIONARY; | ||||||
| 			ret = isal_deflate_dict_perf(compressbuf, &info.deflate_size, |                         ret = isal_deflate_dict_perf( | ||||||
| 						     filebuf, info.file_size, |                                 compressbuf, &info.deflate_size, filebuf, info.file_size, | ||||||
| 						     compression_queue[i].level, |                                 compression_queue[i].level, info.flush_type, info.hist_bits, | ||||||
| 						     info.flush_type, info.hist_bits, |                                 info.deflate_time, &info.start, dict_buf, dict_file_size); | ||||||
| 						     info.deflate_time, &info.start, |  | ||||||
| 						     dict_buf, dict_file_size); |  | ||||||
|                 } else if (info.strategy.mode == ISAL_STATELESS) |                 } else if (info.strategy.mode == ISAL_STATELESS) | ||||||
|                         ret = isal_deflate_perf(compressbuf, &info.deflate_size, filebuf, |                         ret = isal_deflate_perf(compressbuf, &info.deflate_size, filebuf, | ||||||
| 						info.file_size, |                                                 info.file_size, compression_queue[i].level, | ||||||
| 						compression_queue[i].level, |                                                 info.flush_type, info.hist_bits, info.deflate_time, | ||||||
| 						info.flush_type, info.hist_bits, |                                                 &info.start); | ||||||
| 						info.deflate_time, &info.start); |  | ||||||
|  |  | ||||||
|                 else if (info.strategy.mode == ISAL_STATEFUL) |                 else if (info.strategy.mode == ISAL_STATEFUL) | ||||||
| 			ret = isal_deflate_stateful_perf(compressbuf, &info.deflate_size, |                         ret = isal_deflate_stateful_perf( | ||||||
| 							 filebuf, info.file_size, |                                 compressbuf, &info.deflate_size, filebuf, info.file_size, | ||||||
| 							 compression_queue[i].level, |                                 compression_queue[i].level, info.flush_type, info.inblock_size, | ||||||
| 							 info.flush_type, info.inblock_size, |                                 info.hist_bits, info.deflate_time, &info.start); | ||||||
| 							 info.hist_bits, info.deflate_time, |  | ||||||
| 							 &info.start); |  | ||||||
|                 else if (info.strategy.mode == ZLIB) |                 else if (info.strategy.mode == ZLIB) | ||||||
|                         ret = zlib_deflate_perf(compressbuf, &info.deflate_size, filebuf, |                         ret = zlib_deflate_perf(compressbuf, &info.deflate_size, filebuf, | ||||||
|                                                 info.file_size, compression_queue[i].level, |                                                 info.file_size, compression_queue[i].level, | ||||||
| 						info.flush_type, info.inblock_size, |                                                 info.flush_type, info.inblock_size, info.hist_bits, | ||||||
| 						info.hist_bits, info.deflate_time, |                                                 info.deflate_time, &info.start); | ||||||
| 						&info.start); |  | ||||||
|                 if (ret) { |                 if (ret) { | ||||||
|                         printf("  Error in compression\n"); |                         printf("  Error in compression\n"); | ||||||
|                         continue; |                         continue; | ||||||
| @@ -906,8 +905,7 @@ int main(int argc, char *argv[]) | |||||||
|                         info.inflate_mode = ISAL_STATELESS; |                         info.inflate_mode = ISAL_STATELESS; | ||||||
|                         ret = isal_inflate_perf(compressbuf, info.deflate_size, decompbuf, |                         ret = isal_inflate_perf(compressbuf, info.deflate_size, decompbuf, | ||||||
|                                                 decompbuf_size, filebuf, info.file_size, |                                                 decompbuf_size, filebuf, info.file_size, | ||||||
| 						info.hist_bits, info.inflate_time, |                                                 info.hist_bits, info.inflate_time, &info.start); | ||||||
| 						&info.start); |  | ||||||
|                         if (ret) |                         if (ret) | ||||||
|                                 printf("    Error in isal stateless inflate\n"); |                                 printf("    Error in isal stateless inflate\n"); | ||||||
|                         else |                         else | ||||||
| @@ -918,12 +916,10 @@ int main(int argc, char *argv[]) | |||||||
|                         info.inflate_mode = |                         info.inflate_mode = | ||||||
|                                 (dict_file_size == 0) ? ISAL_STATEFUL : ISAL_WITH_DICTIONARY; |                                 (dict_file_size == 0) ? ISAL_STATEFUL : ISAL_WITH_DICTIONARY; | ||||||
|  |  | ||||||
| 			ret = isal_inflate_stateful_perf(compressbuf, info.deflate_size, |                         ret = isal_inflate_stateful_perf( | ||||||
| 							 decompbuf, decompbuf_size, filebuf, |                                 compressbuf, info.deflate_size, decompbuf, decompbuf_size, filebuf, | ||||||
| 							 info.file_size, info.inblock_size, |                                 info.file_size, info.inblock_size, info.hist_bits, | ||||||
| 							 info.hist_bits, info.inflate_time, |                                 info.inflate_time, &info.start, dict_buf, dict_file_size); | ||||||
| 							 &info.start, dict_buf, |  | ||||||
| 							 dict_file_size); |  | ||||||
|  |  | ||||||
|                         if (ret) |                         if (ret) | ||||||
|                                 printf("    Error in isal stateful inflate\n"); |                                 printf("    Error in isal stateful inflate\n"); | ||||||
| @@ -935,8 +931,7 @@ int main(int argc, char *argv[]) | |||||||
|                         info.inflate_mode = ZLIB; |                         info.inflate_mode = ZLIB; | ||||||
|                         ret = zlib_inflate_perf(compressbuf, info.deflate_size, decompbuf, |                         ret = zlib_inflate_perf(compressbuf, info.deflate_size, decompbuf, | ||||||
|                                                 decompbuf_size, filebuf, info.file_size, |                                                 decompbuf_size, filebuf, info.file_size, | ||||||
| 						info.hist_bits, info.inflate_time, |                                                 info.hist_bits, info.inflate_time, &info.start); | ||||||
| 						&info.start); |  | ||||||
|                         if (ret) |                         if (ret) | ||||||
|                                 printf("    Error in zlib inflate\n"); |                                 printf("    Error in zlib inflate\n"); | ||||||
|                         else |                         else | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -44,7 +44,8 @@ | |||||||
| #define DEFAULT_SEG_SIZE    (512 * 1024) | #define DEFAULT_SEG_SIZE    (512 * 1024) | ||||||
| #define DEFAULT_SAMPLE_SIZE (32 * 1024) | #define DEFAULT_SAMPLE_SIZE (32 * 1024) | ||||||
|  |  | ||||||
| int usage(void) | int | ||||||
|  | usage(void) | ||||||
| { | { | ||||||
|         fprintf(stderr, |         fprintf(stderr, | ||||||
|                 "Usage: igzip_semi_dynamic [options] <infile>\n" |                 "Usage: igzip_semi_dynamic [options] <infile>\n" | ||||||
| @@ -53,11 +54,13 @@ int usage(void) | |||||||
|                 "  -t <type> 1:stateless 0:(default)stateful\n" |                 "  -t <type> 1:stateless 0:(default)stateful\n" | ||||||
|                 "  -c <size> chunk size default=%d\n" |                 "  -c <size> chunk size default=%d\n" | ||||||
|                 "  -s <size> sample size default=%d\n" |                 "  -s <size> sample size default=%d\n" | ||||||
| 		"  -o <file> output file\n", DEFAULT_SEG_SIZE, DEFAULT_SAMPLE_SIZE); |                 "  -o <file> output file\n", | ||||||
|  |                 DEFAULT_SEG_SIZE, DEFAULT_SAMPLE_SIZE); | ||||||
|         exit(0); |         exit(0); | ||||||
| } | } | ||||||
|  |  | ||||||
| int str_to_i(char *s) | int | ||||||
|  | str_to_i(char *s) | ||||||
| { | { | ||||||
| #define ARG_MAX 32 | #define ARG_MAX 32 | ||||||
|  |  | ||||||
| @@ -89,9 +92,9 @@ int str_to_i(char *s) | |||||||
|         return i; |         return i; | ||||||
| } | } | ||||||
|  |  | ||||||
| void semi_dyn_stateless_perf(struct isal_zstream *stream, uint8_t * inbuf, | void | ||||||
| 			     uint64_t infile_size, uint8_t * outbuf, uint64_t outbuf_size, | semi_dyn_stateless_perf(struct isal_zstream *stream, uint8_t *inbuf, uint64_t infile_size, | ||||||
| 			     int segment_size, int hist_size) |                         uint8_t *outbuf, uint64_t outbuf_size, int segment_size, int hist_size) | ||||||
| { | { | ||||||
|         struct isal_huff_histogram histogram; |         struct isal_huff_histogram histogram; | ||||||
|         struct isal_hufftables hufftable; |         struct isal_hufftables hufftable; | ||||||
| @@ -130,9 +133,9 @@ void semi_dyn_stateless_perf(struct isal_zstream *stream, uint8_t * inbuf, | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| void semi_dyn_stateful_perf(struct isal_zstream *stream, uint8_t * inbuf, | void | ||||||
| 			    uint64_t infile_size, uint8_t * outbuf, uint64_t outbuf_size, | semi_dyn_stateful_perf(struct isal_zstream *stream, uint8_t *inbuf, uint64_t infile_size, | ||||||
| 			    int segment_size, int hist_size) |                        uint8_t *outbuf, uint64_t outbuf_size, int segment_size, int hist_size) | ||||||
| { | { | ||||||
|         struct isal_huff_histogram histogram; |         struct isal_huff_histogram histogram; | ||||||
|         struct isal_hufftables hufftable; |         struct isal_hufftables hufftable; | ||||||
| @@ -171,7 +174,8 @@ void semi_dyn_stateful_perf(struct isal_zstream *stream, uint8_t * inbuf, | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         FILE *in = stdin, *out = NULL; |         FILE *in = stdin, *out = NULL; | ||||||
|         unsigned char *inbuf, *outbuf; |         unsigned char *inbuf, *outbuf; | ||||||
| @@ -269,15 +273,14 @@ int main(int argc, char *argv[]) | |||||||
|  |  | ||||||
|         if (do_stateful) { |         if (do_stateful) { | ||||||
|                 BENCHMARK(&start, BENCHMARK_TIME, |                 BENCHMARK(&start, BENCHMARK_TIME, | ||||||
| 			  semi_dyn_stateful_perf(&stream, inbuf, infile_size, outbuf, |                           semi_dyn_stateful_perf(&stream, inbuf, infile_size, outbuf, outbuf_size, | ||||||
| 						 outbuf_size, segment_size, hist_size) |                                                  segment_size, hist_size)); | ||||||
| 		    ); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (do_stateless) { |         if (do_stateless) { | ||||||
|                 BENCHMARK(&start, BENCHMARK_TIME, |                 BENCHMARK(&start, BENCHMARK_TIME, | ||||||
| 			  semi_dyn_stateless_perf(&stream, inbuf, infile_size, outbuf, |                           semi_dyn_stateless_perf(&stream, inbuf, infile_size, outbuf, outbuf_size, | ||||||
| 						  outbuf_size, segment_size, hist_size)); |                                                   segment_size, hist_size)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (stream.avail_in != 0) { |         if (stream.avail_in != 0) { | ||||||
|   | |||||||
| @@ -36,7 +36,8 @@ | |||||||
|  |  | ||||||
| struct isal_zstream stream; | struct isal_zstream stream; | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE]; |         uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE]; | ||||||
|         FILE *in, *out; |         FILE *in, *out; | ||||||
|   | |||||||
| @@ -48,7 +48,8 @@ enum { | |||||||
|         MALLOC_FAILED |         MALLOC_FAILED | ||||||
| }; | }; | ||||||
|  |  | ||||||
| void print_error(int32_t error) | void | ||||||
|  | print_error(int32_t error) | ||||||
| { | { | ||||||
|         printf("Error Code %d: ", error); |         printf("Error Code %d: ", error); | ||||||
|         switch (error) { |         switch (error) { | ||||||
| @@ -126,7 +127,8 @@ void print_error(int32_t error) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_uint8_t(uint8_t * array, uint64_t length, char *prepend) | void | ||||||
|  | print_uint8_t(uint8_t *array, uint64_t length, char *prepend) | ||||||
| { | { | ||||||
|         const int line_size = 16; |         const int line_size = 16; | ||||||
|         int i; |         int i; | ||||||
| @@ -151,7 +153,8 @@ void print_uint8_t(uint8_t * array, uint64_t length, char *prepend) | |||||||
|         printf("\n"); |         printf("\n"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_string(char *str, uint32_t str_max_len, char *prepend) | void | ||||||
|  | print_string(char *str, uint32_t str_max_len, char *prepend) | ||||||
| { | { | ||||||
|         const int line_size = 64; |         const int line_size = 64; | ||||||
|         uint32_t i = 0; |         uint32_t i = 0; | ||||||
| @@ -168,10 +171,11 @@ void print_string(char *str, uint32_t str_max_len, char *prepend) | |||||||
|         printf("\n"); |         printf("\n"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_gzip_header(struct isal_gzip_header *gz_hdr, char *prepend1, char *prepend2) | void | ||||||
|  | print_gzip_header(struct isal_gzip_header *gz_hdr, char *prepend1, char *prepend2) | ||||||
| { | { | ||||||
| 	printf("%sText: %d, Time: 0x%08x, Xflags: 0x%x, OS: 0x%x\n", prepend1, |         printf("%sText: %d, Time: 0x%08x, Xflags: 0x%x, OS: 0x%x\n", prepend1, gz_hdr->text, | ||||||
| 	       gz_hdr->text, gz_hdr->time, gz_hdr->xflags, gz_hdr->os); |                gz_hdr->time, gz_hdr->xflags, gz_hdr->os); | ||||||
|  |  | ||||||
|         printf("%sExtra:  Extra_len = 0x%x\n", prepend1, gz_hdr->extra_len); |         printf("%sExtra:  Extra_len = 0x%x\n", prepend1, gz_hdr->extra_len); | ||||||
|         if (gz_hdr->extra_len < EXTRA_SIZE_MAX) |         if (gz_hdr->extra_len < EXTRA_SIZE_MAX) | ||||||
| @@ -192,17 +196,17 @@ void print_gzip_header(struct isal_gzip_header *gz_hdr, char *prepend1, char *pr | |||||||
|                 printf("%sComment field larger than COMMENT_SIZE_MAX\n", prepend2); |                 printf("%sComment field larger than COMMENT_SIZE_MAX\n", prepend2); | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_zlib_header(struct isal_zlib_header *z_hdr, char *prepend) | void | ||||||
|  | print_zlib_header(struct isal_zlib_header *z_hdr, char *prepend) | ||||||
| { | { | ||||||
|         printf("%sInfo: 0x%x\n", prepend, z_hdr->info); |         printf("%sInfo: 0x%x\n", prepend, z_hdr->info); | ||||||
|         printf("%sLevel: 0x%x\n", prepend, z_hdr->level); |         printf("%sLevel: 0x%x\n", prepend, z_hdr->level); | ||||||
| 	printf("%sDictionary: Flag = 0x%x, Id =0x%x\n", prepend, z_hdr->dict_flag, |         printf("%sDictionary: Flag = 0x%x, Id =0x%x\n", prepend, z_hdr->dict_flag, z_hdr->dict_id); | ||||||
| 	       z_hdr->dict_id); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_gzip_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len, | void | ||||||
| 			      struct isal_gzip_header *gz_hdr_orig, | print_gzip_final_verbose(uint8_t *hdr_buf, uint32_t hdr_buf_len, | ||||||
| 			      struct isal_gzip_header *gz_hdr) |                          struct isal_gzip_header *gz_hdr_orig, struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
| #ifdef VERBOSE | #ifdef VERBOSE | ||||||
|         printf("\n"); |         printf("\n"); | ||||||
| @@ -227,9 +231,9 @@ void print_gzip_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len, | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| void print_zlib_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len, | void | ||||||
| 			      struct isal_zlib_header *z_hdr_orig, | print_zlib_final_verbose(uint8_t *hdr_buf, uint32_t hdr_buf_len, | ||||||
| 			      struct isal_zlib_header *z_hdr) |                          struct isal_zlib_header *z_hdr_orig, struct isal_zlib_header *z_hdr) | ||||||
| { | { | ||||||
| #ifdef VERBOSE | #ifdef VERBOSE | ||||||
|         printf("\n"); |         printf("\n"); | ||||||
| @@ -254,7 +258,8 @@ void print_zlib_final_verbose(uint8_t * hdr_buf, uint32_t hdr_buf_len, | |||||||
|         return; |         return; | ||||||
| } | } | ||||||
|  |  | ||||||
| int gzip_header_size(struct isal_gzip_header *gz_hdr) | int | ||||||
|  | gzip_header_size(struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         int hdr_size = 10; |         int hdr_size = 10; | ||||||
|         if (gz_hdr->extra != NULL) { |         if (gz_hdr->extra != NULL) { | ||||||
| @@ -274,7 +279,8 @@ int gzip_header_size(struct isal_gzip_header *gz_hdr) | |||||||
|         return hdr_size; |         return hdr_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| int zlib_header_size(struct isal_zlib_header *z_hdr) | int | ||||||
|  | zlib_header_size(struct isal_zlib_header *z_hdr) | ||||||
| { | { | ||||||
|         if (z_hdr->dict_flag) |         if (z_hdr->dict_flag) | ||||||
|                 return 6; |                 return 6; | ||||||
| @@ -282,7 +288,8 @@ int zlib_header_size(struct isal_zlib_header *z_hdr) | |||||||
|                 return 2; |                 return 2; | ||||||
| } | } | ||||||
|  |  | ||||||
| void rand_string(char *string, uint32_t str_len) | void | ||||||
|  | rand_string(char *string, uint32_t str_len) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|  |  | ||||||
| @@ -294,7 +301,8 @@ void rand_string(char *string, uint32_t str_len) | |||||||
|         string[str_len - 1] = 0; |         string[str_len - 1] = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void rand_buf(uint8_t * buf, uint32_t buf_len) | void | ||||||
|  | rand_buf(uint8_t *buf, uint32_t buf_len) | ||||||
| { | { | ||||||
|         int i; |         int i; | ||||||
|  |  | ||||||
| @@ -306,7 +314,8 @@ void rand_buf(uint8_t * buf, uint32_t buf_len) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| int malloc_gzip_header(struct isal_gzip_header *gz_hdr) | int | ||||||
|  | malloc_gzip_header(struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         gz_hdr->extra = NULL; |         gz_hdr->extra = NULL; | ||||||
|         if (gz_hdr->extra_buf_len) { |         if (gz_hdr->extra_buf_len) { | ||||||
| @@ -337,7 +346,8 @@ int malloc_gzip_header(struct isal_gzip_header *gz_hdr) | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| void free_gzip_header(struct isal_gzip_header *gz_hdr) | void | ||||||
|  | free_gzip_header(struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         if (gz_hdr->extra != NULL) { |         if (gz_hdr->extra != NULL) { | ||||||
|                 free(gz_hdr->extra); |                 free(gz_hdr->extra); | ||||||
| @@ -353,10 +363,10 @@ void free_gzip_header(struct isal_gzip_header *gz_hdr) | |||||||
|                 free(gz_hdr->comment); |                 free(gz_hdr->comment); | ||||||
|                 gz_hdr->comment = NULL; |                 gz_hdr->comment = NULL; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int gen_rand_gzip_header(struct isal_gzip_header *gz_hdr) | int | ||||||
|  | gen_rand_gzip_header(struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|         int ret = 0; |         int ret = 0; | ||||||
|         int field_set_space = 8; |         int field_set_space = 8; | ||||||
| @@ -396,7 +406,8 @@ int gen_rand_gzip_header(struct isal_gzip_header *gz_hdr) | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| void gen_rand_zlib_header(struct isal_zlib_header *z_hdr) | void | ||||||
|  | gen_rand_zlib_header(struct isal_zlib_header *z_hdr) | ||||||
| { | { | ||||||
|         z_hdr->info = rand() % 16; |         z_hdr->info = rand() % 16; | ||||||
|         z_hdr->level = rand() % 4; |         z_hdr->level = rand() % 4; | ||||||
| @@ -404,7 +415,8 @@ void gen_rand_zlib_header(struct isal_zlib_header *z_hdr) | |||||||
|         z_hdr->dict_id = rand(); |         z_hdr->dict_id = rand(); | ||||||
| } | } | ||||||
|  |  | ||||||
| int write_gzip_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_gzip_header *gz_hdr) | int | ||||||
|  | write_gzip_header(uint8_t *hdr_buf, uint32_t hdr_buf_len, struct isal_gzip_header *gz_hdr) | ||||||
| { | { | ||||||
|  |  | ||||||
|         struct isal_zstream stream; |         struct isal_zstream stream; | ||||||
| @@ -436,13 +448,15 @@ int write_gzip_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_gzip_ | |||||||
|         if (len) { |         if (len) { | ||||||
|                 print_gzip_final_verbose(hdr_buf, hdr_buf_len, gz_hdr, NULL); |                 print_gzip_final_verbose(hdr_buf, hdr_buf_len, gz_hdr, NULL); | ||||||
|                 print_error(INCORRECT_WRITE_RETURN); |                 print_error(INCORRECT_WRITE_RETURN); | ||||||
| 		return INCORRECT_WRITE_RETURN;; |                 return INCORRECT_WRITE_RETURN; | ||||||
|  |                 ; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int write_zlib_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_header *z_hdr) | int | ||||||
|  | write_zlib_header(uint8_t *hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_header *z_hdr) | ||||||
| { | { | ||||||
|         struct isal_zstream stream; |         struct isal_zstream stream; | ||||||
|         uint32_t hdr_len = zlib_header_size(z_hdr); |         uint32_t hdr_len = zlib_header_size(z_hdr); | ||||||
| @@ -472,13 +486,15 @@ int write_zlib_header(uint8_t * hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_ | |||||||
|         if (len) { |         if (len) { | ||||||
|                 print_zlib_final_verbose(hdr_buf, hdr_buf_len, z_hdr, NULL); |                 print_zlib_final_verbose(hdr_buf, hdr_buf_len, z_hdr, NULL); | ||||||
|                 print_error(INCORRECT_WRITE_RETURN); |                 print_error(INCORRECT_WRITE_RETURN); | ||||||
| 		return INCORRECT_WRITE_RETURN;; |                 return INCORRECT_WRITE_RETURN; | ||||||
|  |                 ; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int compare_gzip_headers(struct isal_gzip_header *gz_hdr1, struct isal_gzip_header *gz_hdr2) | int | ||||||
|  | compare_gzip_headers(struct isal_gzip_header *gz_hdr1, struct isal_gzip_header *gz_hdr2) | ||||||
| { | { | ||||||
|         int ret = 0; |         int ret = 0; | ||||||
|         uint32_t max_len; |         uint32_t max_len; | ||||||
| @@ -526,7 +542,8 @@ int compare_gzip_headers(struct isal_gzip_header *gz_hdr1, struct isal_gzip_head | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int compare_zlib_headers(struct isal_zlib_header *z_hdr1, struct isal_zlib_header *z_hdr2) | int | ||||||
|  | compare_zlib_headers(struct isal_zlib_header *z_hdr1, struct isal_zlib_header *z_hdr2) | ||||||
| { | { | ||||||
|         if (z_hdr1->info != z_hdr2->info) |         if (z_hdr1->info != z_hdr2->info) | ||||||
|                 return INCORRECT_INFO; |                 return INCORRECT_INFO; | ||||||
| @@ -543,7 +560,8 @@ int compare_zlib_headers(struct isal_zlib_header *z_hdr1, struct isal_zlib_heade | |||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int read_gzip_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len, | int | ||||||
|  | read_gzip_header_simple(uint8_t *hdr_buf, uint32_t hdr_buf_len, | ||||||
|                         struct isal_gzip_header *gz_hdr_orig) |                         struct isal_gzip_header *gz_hdr_orig) | ||||||
| { | { | ||||||
|  |  | ||||||
| @@ -587,8 +605,8 @@ int read_gzip_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len, | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int read_zlib_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len, | int | ||||||
| 			    struct isal_zlib_header *z_hdr_orig) | read_zlib_header_simple(uint8_t *hdr_buf, uint32_t hdr_buf_len, struct isal_zlib_header *z_hdr_orig) | ||||||
| { | { | ||||||
|  |  | ||||||
|         int ret = 0; |         int ret = 0; | ||||||
| @@ -618,7 +636,8 @@ int read_zlib_header_simple(uint8_t * hdr_buf, uint32_t hdr_buf_len, | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int read_gzip_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len, | int | ||||||
|  | read_gzip_header_streaming(uint8_t *hdr_buf, uint32_t hdr_buf_len, | ||||||
|                            struct isal_gzip_header *gz_hdr_orig) |                            struct isal_gzip_header *gz_hdr_orig) | ||||||
| { | { | ||||||
|         int ret = 0; |         int ret = 0; | ||||||
| @@ -753,7 +772,8 @@ int read_gzip_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len, | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int read_zlib_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len, | int | ||||||
|  | read_zlib_header_streaming(uint8_t *hdr_buf, uint32_t hdr_buf_len, | ||||||
|                            struct isal_zlib_header *z_hdr_orig) |                            struct isal_zlib_header *z_hdr_orig) | ||||||
| { | { | ||||||
|         int ret = ISAL_END_INPUT; |         int ret = ISAL_END_INPUT; | ||||||
| @@ -795,7 +815,8 @@ int read_zlib_header_streaming(uint8_t * hdr_buf, uint32_t hdr_buf_len, | |||||||
|         return ret; |         return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|         uint8_t *hdr_buf = NULL; |         uint8_t *hdr_buf = NULL; | ||||||
|         uint32_t hdr_buf_len; |         uint32_t hdr_buf_len; | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -31,7 +31,8 @@ | |||||||
| #include "huff_codes.h" | #include "huff_codes.h" | ||||||
| #include "unaligned.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; |         uint64_t child = 2 * index, tmp; | ||||||
|         while (child <= heap_size) { |         while (child <= heap_size) { | ||||||
| @@ -48,16 +49,17 @@ static inline void heapify(uint64_t * heap, uint64_t heap_size, uint64_t index) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| void build_heap(uint64_t * heap, uint64_t heap_size) | void | ||||||
|  | build_heap(uint64_t *heap, uint64_t heap_size) | ||||||
| { | { | ||||||
|         uint64_t i; |         uint64_t i; | ||||||
|         heap[heap_size + 1] = -1; |         heap[heap_size + 1] = -1; | ||||||
|         for (i = heap_size / 2; i > 0; i--) |         for (i = heap_size / 2; i > 0; i--) | ||||||
|                 heapify(heap, heap_size, 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 *heap = (uint64_t *) heap_space; | ||||||
|         uint64_t h1, h2; |         uint64_t h1, h2; | ||||||
| @@ -77,7 +79,6 @@ uint32_t build_huff_tree(struct heap_tree *heap_space, uint64_t heap_size, uint6 | |||||||
|                 store_native_u16_to_u64(&heap[node_ptr], h1); |                 store_native_u16_to_u64(&heap[node_ptr], h1); | ||||||
|                 store_native_u16_to_u64(&heap[node_ptr - 1], h2); |                 store_native_u16_to_u64(&heap[node_ptr - 1], h2); | ||||||
|                 node_ptr -= 2; |                 node_ptr -= 2; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|         h1 = heap[1]; |         h1 = heap[1]; | ||||||
|         store_native_u16_to_u64(&heap[node_ptr], h1); |         store_native_u16_to_u64(&heap[node_ptr], h1); | ||||||
|   | |||||||
| @@ -56,7 +56,6 @@ | |||||||
|  * smaller than 258 */ |  * smaller than 258 */ | ||||||
| #define MAX_FIXUP_CODE_LENGTH 8 | #define MAX_FIXUP_CODE_LENGTH 8 | ||||||
|  |  | ||||||
|  |  | ||||||
| /* Headers for constant 0x00 and 0xFF blocks | /* Headers for constant 0x00 and 0xFF blocks | ||||||
|  * This also contains the first literal character. */ |  * This also contains the first literal character. */ | ||||||
| const uint32_t repeated_char_header[2][5] = { | const uint32_t repeated_char_header[2][5] = { | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user