From 06cd70481ce267851772d1696273ba0d8ee3a03b Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Tue, 28 Nov 2017 17:10:46 -0700 Subject: [PATCH] igzip: Separate defines for LVL1 and LVL0 hash tables Change-Id: I19bdec8d2d0c74083bc1695763c9630516995885 Signed-off-by: Roy Oursler --- igzip/huff_codes.h | 1 + igzip/igzip_icf_base.c | 8 ++++---- igzip/igzip_icf_body_h1_gr_bt.asm | 31 +++++++++++++------------------ igzip/igzip_icf_finish.asm | 14 +++++++------- igzip/lz0a_const.asm | 5 +++++ include/igzip_lib.h | 4 ++++ 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/igzip/huff_codes.h b/igzip/huff_codes.h index fb4bf60..01f51c8 100644 --- a/igzip/huff_codes.h +++ b/igzip/huff_codes.h @@ -77,6 +77,7 @@ #define INVALID_HUFFCODE 1 #define LVL0_HASH_MASK (IGZIP_LVL0_HASH_SIZE - 1) +#define LVL1_HASH_MASK (IGZIP_LVL1_HASH_SIZE - 1) #define LVL2_HASH_MASK (IGZIP_LVL2_HASH_SIZE - 1) #define SHORTEST_MATCH 4 diff --git a/igzip/igzip_icf_base.c b/igzip/igzip_icf_base.c index 4b11e21..a9e4b4c 100644 --- a/igzip/igzip_icf_base.c +++ b/igzip/igzip_icf_base.c @@ -68,7 +68,7 @@ void isal_deflate_icf_body_lvl1_base(struct isal_zstream *stream) } literal = *(uint32_t *) next_in; - hash = compute_hash(literal) & LVL0_HASH_MASK; + hash = compute_hash(literal) & LVL1_HASH_MASK; dist = (next_in - file_start - last_seen[hash]) & 0xFFFF; last_seen[hash] = (uint64_t) (next_in - file_start); @@ -89,7 +89,7 @@ void isal_deflate_icf_body_lvl1_base(struct isal_zstream *stream) for (; next_hash < end; next_hash++) { literal = *(uint32_t *) next_hash; - hash = compute_hash(literal) & LVL0_HASH_MASK; + hash = compute_hash(literal) & LVL1_HASH_MASK; last_seen[hash] = (uint64_t) (next_hash - file_start); } @@ -160,7 +160,7 @@ void isal_deflate_icf_finish_lvl1_base(struct isal_zstream *stream) } literal = *(uint32_t *) next_in; - hash = compute_hash(literal) & LVL0_HASH_MASK; + hash = compute_hash(literal) & LVL1_HASH_MASK; dist = (next_in - file_start - last_seen[hash]) & 0xFFFF; last_seen[hash] = (uint64_t) (next_in - file_start); @@ -178,7 +178,7 @@ void isal_deflate_icf_finish_lvl1_base(struct isal_zstream *stream) for (; next_hash < end - 3; next_hash++) { literal = *(uint32_t *) next_hash; - hash = compute_hash(literal) & LVL0_HASH_MASK; + hash = compute_hash(literal) & LVL1_HASH_MASK; last_seen[hash] = (uint64_t) (next_hash - file_start); } diff --git a/igzip/igzip_icf_body_h1_gr_bt.asm b/igzip/igzip_icf_body_h1_gr_bt.asm index 14aeedd..93f43d0 100644 --- a/igzip/igzip_icf_body_h1_gr_bt.asm +++ b/igzip/igzip_icf_body_h1_gr_bt.asm @@ -190,8 +190,8 @@ MARK __body_compute_hash_ %+ ARCH shr tmp3, 8 compute_hash hash2, tmp3 - and hash, LVL0_HASH_MASK - and hash2, LVL0_HASH_MASK + and hash, LVL1_HASH_MASK + and hash2, LVL1_HASH_MASK cmp byte [stream + _internal_state_has_hist], IGZIP_NO_HIST je write_first_byte @@ -220,7 +220,7 @@ loop2: mov tmp2, curr_data shr curr_data, 16 compute_hash hash, curr_data - and hash %+ d, LVL0_HASH_MASK + and hash %+ d, LVL1_HASH_MASK mov dist2 %+ w, f_i %+ w dec dist2 @@ -233,7 +233,7 @@ loop2: shr tmp2, 24 compute_hash hash2, tmp2 - and hash2 %+ d, LVL0_HASH_MASK + and hash2 %+ d, LVL1_HASH_MASK and dist2 %+ d, (D-1) neg dist2 @@ -286,7 +286,7 @@ len_dist_lit_huffman: shr curr_data, 24 compute_hash hash3, curr_data - and hash3, LVL0_HASH_MASK + and hash3, LVL1_HASH_MASK mov curr_data, tmp1 shr tmp1, 8 @@ -318,9 +318,9 @@ len_dist_lit_huffman: and dist_code2, 0x1F inc word [stream + _internal_state_hist_dist + HIST_ELEM_SIZE*dist_code2] - ; hash = compute_hash(state->file_start + f_i) & LVL0_HASH_MASK; - and hash %+ d, LVL0_HASH_MASK - and hash2 %+ d, LVL0_HASH_MASK + ; hash = compute_hash(state->file_start + f_i) & LVL1_HASH_MASK; + and hash %+ d, LVL1_HASH_MASK + and hash2 %+ d, LVL1_HASH_MASK ; continue cmp f_i, file_length @@ -371,9 +371,9 @@ len_dist_huffman: and dist_code, 0x1F inc word [stream + _internal_state_hist_dist + HIST_ELEM_SIZE*dist_code] - ; hash = compute_hash(state->file_start + f_i) & LVL0_HASH_MASK; - and hash %+ d, LVL0_HASH_MASK - and hash2 %+ d, LVL0_HASH_MASK + ; hash = compute_hash(state->file_start + f_i) & LVL1_HASH_MASK; + and hash %+ d, LVL1_HASH_MASK + and hash2 %+ d, LVL1_HASH_MASK ; continue cmp f_i, file_length @@ -501,14 +501,9 @@ write_first_byte: MOVDQU xdata, [file_start + f_i + 1] add f_i, 1 mov curr_data, [file_start + f_i] - and hash %+ d, LVL0_HASH_MASK - and hash2 %+ d, LVL0_HASH_MASK + and hash %+ d, LVL1_HASH_MASK + and hash2 %+ d, LVL1_HASH_MASK cmp f_i, file_length jl loop2 jmp input_end - -section .data - align 16 -mask: dd LVL0_HASH_MASK, LVL0_HASH_MASK, LVL0_HASH_MASK, LVL0_HASH_MASK -const_D: dq D diff --git a/igzip/igzip_icf_finish.asm b/igzip/igzip_icf_finish.asm index 864da5f..4093550 100644 --- a/igzip/igzip_icf_finish.asm +++ b/igzip/igzip_icf_finish.asm @@ -129,7 +129,7 @@ isal_deflate_icf_finish_lvl1_01: ja end_loop_2 compute_hash hash, curr_data - and hash %+ d, LVL0_HASH_MASK + and hash %+ d, LVL1_HASH_MASK mov [stream + _internal_state_head + 2 * hash], f_i %+ w mov byte [stream + _internal_state_has_hist], IGZIP_HIST jmp encode_literal @@ -141,10 +141,10 @@ loop2: cmp m_out_buf, [rsp + m_out_end] ja end_loop_2 - ; hash = compute_hash(state->file_start + f_i) & LVL0_HASH_MASK; + ; hash = compute_hash(state->file_start + f_i) & LVL1_HASH_MASK; mov curr_data %+ d, [file_start + f_i] compute_hash hash, curr_data - and hash %+ d, LVL0_HASH_MASK + and hash %+ d, LVL1_HASH_MASK ; f_index = state->head[hash]; movzx f_index %+ d, word [stream + _internal_state_head + 2 * hash] @@ -203,19 +203,19 @@ loop2: ; only update hash twice - ; hash = compute_hash(state->file_start + k) & LVL0_HASH_MASK; + ; hash = compute_hash(state->file_start + k) & LVL1_HASH_MASK; mov tmp6 %+ d, dword [file_start + tmp3] compute_hash hash, tmp6 - and hash %+ d, LVL0_HASH_MASK + and hash %+ d, LVL1_HASH_MASK ; state->head[hash] = k; mov [stream + _internal_state_head + 2 * hash], tmp3 %+ w add tmp3, 1 - ; hash = compute_hash(state->file_start + k) & LVL0_HASH_MASK; + ; hash = compute_hash(state->file_start + k) & LVL1_HASH_MASK; mov tmp6 %+ d, dword [file_start + tmp3] compute_hash hash, tmp6 - and hash %+ d, LVL0_HASH_MASK + and hash %+ d, LVL1_HASH_MASK ; state->head[hash] = k; mov [stream + _internal_state_head + 2 * hash], tmp3 %+ w diff --git a/igzip/lz0a_const.asm b/igzip/lz0a_const.asm index aac1f2a..6fce70b 100644 --- a/igzip/lz0a_const.asm +++ b/igzip/lz0a_const.asm @@ -42,11 +42,16 @@ %assign IGZIP_LVL0_HASH_SIZE (8 * K) %endif +%ifndef IGZIP_LVL1_HASH_SIZE +%assign IGZIP_LVL1_HASH_SIZE (8 * K) +%endif + %ifndef IGZIP_LVL2_HASH_SIZE %assign IGZIP_LVL2_HASH_SIZE IGZIP_HIST_SIZE %endif %assign LVL0_HASH_MASK (IGZIP_LVL0_HASH_SIZE - 1) +%assign LVL1_HASH_MASK (IGZIP_LVL1_HASH_SIZE - 1) %assign LVL2_HASH_MASK (IGZIP_LVL2_HASH_SIZE - 1) %assign MIN_DEF_MATCH 3 ; Minimum length of a match in deflate diff --git a/include/igzip_lib.h b/include/igzip_lib.h index 23c4b64..2c3cfed 100644 --- a/include/igzip_lib.h +++ b/include/igzip_lib.h @@ -119,6 +119,10 @@ extern "C" { #define IGZIP_LVL0_HASH_SIZE (8 * IGZIP_K) #endif +#ifndef IGZIP_LVL1_HASH_SIZE +#define IGZIP_LVL1_HASH_SIZE (8 * IGZIP_K) +#endif + #ifndef IGZIP_LVL2_HASH_SIZE #define IGZIP_LVL2_HASH_SIZE IGZIP_HIST_SIZE #endif