igzip: Increase isal_mod_hist size to stop histogram overflow

Change-Id: I1c651c9625d0fb543cd89e53e2b78b391176ef68
Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
Roy Oursler 2017-03-15 14:25:58 -07:00 committed by Greg Tucker
parent 761b207376
commit e38ed4b54e
7 changed files with 25 additions and 24 deletions

View File

@ -66,12 +66,13 @@ FIELD _m_out_start, 8, 8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%define HIST_ELEM_SIZE 4
START_FIELDS ;; isal_mod_hist
;; name size align
FIELD _d_hist, 30*2, 2
FIELD _ll_hist, 513*2, 2
FIELD _d_hist, 30*HIST_ELEM_SIZE, HIST_ELEM_SIZE
FIELD _ll_hist, 513*HIST_ELEM_SIZE, HIST_ELEM_SIZE
%assign _isal_mod_hist_size _FIELD_OFFSET
%assign _isal_mod_hist_align _STRUCT_ALIGN

View File

@ -4,10 +4,10 @@
#include "flatten_ll.h"
void flatten_ll(uint16_t * ll_hist)
void flatten_ll(uint32_t * ll_hist)
{
uint32_t i, j;
uint16_t *s = ll_hist, x, *p;
uint32_t *s = ll_hist, x, *p;
s[265] += s[266];
s[266] = s[267] + s[268];

View File

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

View File

@ -240,7 +240,7 @@ uint32_t convert_length_to_len_sym(uint32_t length)
// and bl_count is the count of the lengths
/* Init heap with the histogram, and return the histogram size */
static inline uint32_t init_heap16(struct heap_tree *heap_space, uint16_t * histogram,
static inline uint32_t init_heap32(struct heap_tree *heap_space, uint32_t * histogram,
uint32_t hist_size)
{
uint32_t heap_size, i;
@ -997,8 +997,8 @@ create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables,
struct huff_code *ll_codes = hufftables->lit_len_table;
struct huff_code *d_codes = hufftables->dist_table;
uint16_t *ll_hist = hist->ll_hist;
uint16_t *d_hist = hist->d_hist;
uint32_t *ll_hist = hist->ll_hist;
uint32_t *d_hist = hist->d_hist;
flatten_ll(hist->ll_hist);
@ -1006,12 +1006,12 @@ create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables,
if (ll_hist[256] == 0)
ll_hist[256] = 1;
heap_size = init_heap16(&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,
ll_codes, LIT_LEN, MAX_DEFLATE_CODE_LEN);
max_ll_code = set_huff_codes(ll_codes, LIT_LEN, bl_count);
heap_size = init_heap16(&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,
DIST_LEN, MAX_DEFLATE_CODE_LEN);
max_d_code = set_dist_huff_codes(d_codes, bl_count);

View File

@ -258,7 +258,7 @@ MARK __body_compare_ %+ ARCH
test len %+ d, 0xFFFFFFFF
jz len_dist_huffman_pre
inc word [stream + _internal_state_hist_lit_len + 2*lit_code]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*lit_code]
movzx lit_code2, curr_data %+ b
;; Check for len/dist match for second literal
test len2 %+ d, 0xFFFFFFFF
@ -309,14 +309,14 @@ len_dist_lit_huffman:
add dist_code2, 254
add dist_code2, len2
inc word [stream + _internal_state_hist_lit_len + 2*(len2 + 254)]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*(len2 + 254)]
movnti dword [m_out_buf + 4], dist_code2 %+ d
add m_out_buf, 8
shr dist_code2, DIST_OFFSET
and dist_code2, 0x1F
inc word [stream + _internal_state_hist_dist + 2*dist_code2]
inc word [stream + _internal_state_hist_dist + HIST_ELEM_SIZE*dist_code2]
; hash = compute_hash(state->file_start + f_i) & HASH_MASK;
and hash %+ d, HASH_MASK
@ -362,14 +362,14 @@ len_dist_huffman:
shr curr_data2, 8
compute_hash hash2, curr_data2
inc word [stream + _internal_state_hist_lit_len + 2*len_code]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*len_code]
movnti dword [m_out_buf], dist_code %+ d
add m_out_buf, 4
shr dist_code, DIST_OFFSET
and dist_code, 0x1F
inc word [stream + _internal_state_hist_dist + 2*dist_code]
inc word [stream + _internal_state_hist_dist + HIST_ELEM_SIZE*dist_code]
; hash = compute_hash(state->file_start + f_i) & HASH_MASK;
and hash %+ d, HASH_MASK
@ -386,7 +386,7 @@ write_lit_bits:
add f_i, 1
MOVQ curr_data, xdata
inc word [stream + _internal_state_hist_lit_len + 2*lit_code2]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*lit_code2]
shl lit_code2, DIST_OFFSET
lea lit_code, [lit_code + lit_code2 + (31 << DIST_OFFSET)]
@ -474,7 +474,7 @@ compare_loop2:
%endif
movzx lit_code, curr_data %+ b
shr curr_data, 8
inc word [stream + _internal_state_hist_lit_len + 2*lit_code]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*lit_code]
jmp len_dist_lit_huffman
MARK __write_first_byte_ %+ ARCH
@ -491,7 +491,7 @@ write_first_byte:
compute_hash hash2, tmp4
and curr_data, 0xff
inc word [stream + _internal_state_hist_lit_len + 2*curr_data]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*curr_data]
or curr_data, LIT
movnti dword [m_out_buf], curr_data %+ d

View File

@ -193,7 +193,7 @@ loop2:
lea code, [len + 254]
or code2, code
inc word [stream + _internal_state_hist_lit_len + 2*code]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*code]
; for (k = f_i+1, f_i += len-1; k <= f_i; k++) {
lea tmp3, [f_i + 1] ; tmp3 <= k
@ -223,7 +223,7 @@ skip_hash_update:
write_dword code2, m_out_buf
shr code2, DIST_OFFSET
and code2, 0x1F
inc word [stream + _internal_state_hist_dist + 2*code2]
inc word [stream + _internal_state_hist_dist + HIST_ELEM_SIZE*code2]
; continue
cmp f_i, [rsp + f_end_i_mem_offset]
jl loop2
@ -232,7 +232,7 @@ skip_hash_update:
encode_literal:
; get_lit_code(state->file_start[f_i], &code2, &code_len2);
movzx tmp5, byte [file_start + f_i]
inc word [stream + _internal_state_hist_lit_len + 2*tmp5]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*tmp5]
or tmp5, LIT
write_dword tmp5, m_out_buf
; continue
@ -254,7 +254,7 @@ final_bytes:
ja out_end
movzx tmp5, byte [file_start + f_i]
inc word [stream + _internal_state_hist_lit_len + 2*tmp5]
inc word [stream + _internal_state_hist_lit_len + HIST_ELEM_SIZE*tmp5]
or tmp5, LIT
write_dword tmp5, m_out_buf

View File

@ -222,8 +222,8 @@ struct isal_huff_histogram {
};
struct isal_mod_hist {
uint16_t d_hist[30];
uint16_t ll_hist[513];
uint32_t d_hist[30];
uint32_t ll_hist[513];
};
/* Data sizes for level specific data options */