From 80bfbb33df5d75e94dde276cb2eeab4ecf0562a3 Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Thu, 20 Jul 2017 13:26:26 -0700 Subject: [PATCH] igzip: Remove DECLARE_ALIGNED and optimize structure layout Change-Id: I95bc3b8e2e30aff0d596c743158337400c4eb486 Signed-off-by: Roy Oursler --- igzip/data_struct2.asm | 24 ++++++++++++------------ igzip/igzip_body.asm | 14 +++++++------- igzip/igzip_finish.asm | 8 ++++---- igzip/igzip_icf_body.asm | 14 +++++++------- igzip/igzip_icf_finish.asm | 8 ++++---- include/igzip_lib.h | 26 +++++++++++++------------- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/igzip/data_struct2.asm b/igzip/data_struct2.asm index edac60d..0bb196e 100644 --- a/igzip/data_struct2.asm +++ b/igzip/data_struct2.asm @@ -119,23 +119,23 @@ FIELD _icf_buf_start, 0, 0 START_FIELDS ;; isal_zstate ;; name size align -FIELD _b_bytes_valid, 4, 4 -FIELD _b_bytes_processed, 4, 4 FIELD _file_start, 8, 8 -FIELD _crc, 4, 4 FIELD _bitbuf, _BitBuf2_size, _BitBuf2_align +FIELD _crc, 4, 4 FIELD _state, 4, 4 +FIELD _has_wrap_hdr, 2, 2 +FIELD _has_eob_hdr, 2, 2 +FIELD _has_eob, 2, 2 +FIELD _has_hist, 2, 2 +FIELD _hist, _isal_mod_hist_size, _isal_mod_hist_align FIELD _count, 4, 4 FIELD _tmp_out_buff, 16, 1 FIELD _tmp_out_start, 4, 4 FIELD _tmp_out_end, 4, 4 -FIELD _has_wrap_hdr, 4, 4 -FIELD _has_eob, 4, 4 -FIELD _has_eob_hdr, 4, 4 -FIELD _has_hist, 4, 4 -FIELD _hist, _isal_mod_hist_size, _isal_mod_hist_align -FIELD _buffer, BSIZE, 32 -FIELD _head, IGZIP_HASH_SIZE*2, 16 +FIELD _b_bytes_valid, 4, 4 +FIELD _b_bytes_processed, 4, 4 +FIELD _buffer, BSIZE, 1 +FIELD _head, IGZIP_HASH_SIZE*2, 2 %assign _isal_zstate_size _FIELD_OFFSET %assign _isal_zstate_align _STRUCT_ALIGN @@ -165,8 +165,8 @@ FIELD _hufftables, 8, 8 FIELD _level, 4, 4 FIELD _level_buf_size, 4, 4 FIELD _level_buf, 8, 8 -FIELD _end_of_stream, 4, 4 -FIELD _flush, 4, 4 +FIELD _end_of_stream, 2, 2 +FIELD _flush, 2, 2 FIELD _gzip_flag, 4, 4 FIELD _internal_state, _isal_zstate_size, _isal_zstate_align diff --git a/igzip/igzip_body.asm b/igzip/igzip_body.asm index 3a84d02..0e9100e 100644 --- a/igzip/igzip_body.asm +++ b/igzip/igzip_body.asm @@ -137,9 +137,9 @@ isal_deflate_body_ %+ ARCH %+ : ;; Set stream's next state mov rdx, ZSTATE_FLUSH_READ_BUFFER mov rax, ZSTATE_BODY - cmp dword [rcx + _end_of_stream], 0 + cmp word [rcx + _end_of_stream], 0 cmovne rax, rdx - cmp dword [rcx + _flush], _NO_FLUSH + cmp word [rcx + _flush], _NO_FLUSH cmovne rax, rdx mov dword [rcx + _internal_state_state], eax ret @@ -164,7 +164,7 @@ skip1: mov [rsp + gpr_save_mem_offset + 7*8], r15 mov stream, rcx - mov dword [stream + _internal_state_has_eob], 0 + mov word [stream + _internal_state_has_eob], 0 MOVDQU xmask, [mask] @@ -212,7 +212,7 @@ MARK __body_compute_hash_ %+ ARCH and hash, HASH_MASK and hash2, HASH_MASK - cmp dword [stream + _internal_state_has_hist], IGZIP_NO_HIST + cmp word [stream + _internal_state_has_hist], IGZIP_NO_HIST je write_first_byte jmp loop2 @@ -464,9 +464,9 @@ write_lit_bits: input_end: mov tmp1, ZSTATE_FLUSH_READ_BUFFER mov tmp5, ZSTATE_BODY - cmp dword [stream + _end_of_stream], 0 + cmp word [stream + _end_of_stream], 0 cmovne tmp5, tmp1 - cmp dword [stream + _flush], _NO_FLUSH + cmp word [stream + _flush], _NO_FLUSH cmovne tmp5, tmp1 mov dword [stream + _internal_state_state], tmp5 %+ d @@ -545,7 +545,7 @@ write_first_byte: cmp m_out_buf, [stream + _internal_state_bitbuf_m_out_end] ja output_end - mov dword [stream + _internal_state_has_hist], IGZIP_HIST + mov word [stream + _internal_state_has_hist], IGZIP_HIST mov [stream + _internal_state_head + 2 * hash], f_i %+ w diff --git a/igzip/igzip_finish.asm b/igzip/igzip_finish.asm index dbbe0d9..bcb552c 100644 --- a/igzip/igzip_finish.asm +++ b/igzip/igzip_finish.asm @@ -126,7 +126,7 @@ skip_SLOP: mov curr_data %+ d, [file_start + f_i] - cmp dword [stream + _internal_state_has_hist], IGZIP_NO_HIST + cmp word [stream + _internal_state_has_hist], IGZIP_NO_HIST jne skip_write_first_byte cmp m_out_buf, [stream + _internal_state_bitbuf_m_out_end] @@ -135,7 +135,7 @@ skip_SLOP: compute_hash hash, curr_data and hash %+ d, HASH_MASK mov [stream + _internal_state_head + 2 * hash], f_i %+ w - mov dword [stream + _internal_state_has_hist], IGZIP_HIST + mov word [stream + _internal_state_has_hist], IGZIP_HIST jmp encode_literal skip_write_first_byte: @@ -276,8 +276,8 @@ write_eob: write_bits m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp1 - mov dword [stream + _internal_state_has_eob], 1 - cmp dword [stream + _end_of_stream], 1 + mov word [stream + _internal_state_has_eob], 1 + cmp word [stream + _end_of_stream], 1 jne sync_flush ; state->state = ZSTATE_TRL; mov dword [stream + _internal_state_state], ZSTATE_TRL diff --git a/igzip/igzip_icf_body.asm b/igzip/igzip_icf_body.asm index abfc814..707d474 100644 --- a/igzip/igzip_icf_body.asm +++ b/igzip/igzip_icf_body.asm @@ -123,9 +123,9 @@ isal_deflate_icf_body_ %+ ARCH %+ : ;; Set stream's next state mov rdx, ZSTATE_FLUSH_READ_BUFFER mov rax, ZSTATE_CREATE_HDR - cmp dword [rcx + _end_of_stream], 0 + cmp word [rcx + _end_of_stream], 0 cmovne rax, rdx - cmp dword [rcx + _flush], _NO_FLUSH + cmp word [rcx + _flush], _NO_FLUSH cmovne rax, rdx mov dword [rcx + _internal_state_state], eax ret @@ -150,7 +150,7 @@ skip1: mov [rsp + gpr_save_mem_offset + 7*8], r15 mov stream, rcx - mov dword [stream + _internal_state_has_eob], 0 + mov word [stream + _internal_state_has_eob], 0 ; state->bitbuf.set_buf(stream->next_out, stream->avail_out); mov tmp1, [stream + _level_buf] @@ -193,7 +193,7 @@ MARK __body_compute_hash_ %+ ARCH and hash, HASH_MASK and hash2, HASH_MASK - cmp dword [stream + _internal_state_has_hist], IGZIP_NO_HIST + cmp word [stream + _internal_state_has_hist], IGZIP_NO_HIST je write_first_byte jmp loop2 @@ -401,9 +401,9 @@ write_lit_bits: input_end: mov tmp1, ZSTATE_FLUSH_READ_BUFFER mov tmp2, ZSTATE_BODY - cmp dword [stream + _end_of_stream], 0 + cmp word [stream + _end_of_stream], 0 cmovne tmp2, tmp1 - cmp dword [stream + _flush], _NO_FLUSH + cmp word [stream + _flush], _NO_FLUSH cmovne tmp2, tmp1 mov dword [stream + _internal_state_state], tmp2 %+ d @@ -482,7 +482,7 @@ write_first_byte: cmp m_out_buf, [rsp + m_out_end] ja output_end - mov dword [stream + _internal_state_has_hist], IGZIP_HIST + mov word [stream + _internal_state_has_hist], IGZIP_HIST mov [stream + _internal_state_head + 2 * hash], f_i %+ w diff --git a/igzip/igzip_icf_finish.asm b/igzip/igzip_icf_finish.asm index 15be09c..cf3a607 100644 --- a/igzip/igzip_icf_finish.asm +++ b/igzip/igzip_icf_finish.asm @@ -122,7 +122,7 @@ isal_deflate_icf_finish_01: mov curr_data %+ d, [file_start + f_i] - cmp dword [stream + _internal_state_has_hist], IGZIP_NO_HIST + cmp word [stream + _internal_state_has_hist], IGZIP_NO_HIST jne skip_write_first_byte cmp m_out_buf, [rsp + m_out_end] @@ -131,7 +131,7 @@ isal_deflate_icf_finish_01: compute_hash hash, curr_data and hash %+ d, HASH_MASK mov [stream + _internal_state_head + 2 * hash], f_i %+ w - mov dword [stream + _internal_state_has_hist], IGZIP_HIST + mov word [stream + _internal_state_has_hist], IGZIP_HIST jmp encode_literal skip_write_first_byte: @@ -263,9 +263,9 @@ final_bytes: jl final_bytes input_end: - cmp dword [stream + _end_of_stream], 0 + cmp word [stream + _end_of_stream], 0 jne out_end - cmp dword [stream + _flush], _NO_FLUSH + cmp word [stream + _flush], _NO_FLUSH jne out_end jmp end diff --git a/include/igzip_lib.h b/include/igzip_lib.h index a51a4da..d82194a 100644 --- a/include/igzip_lib.h +++ b/include/igzip_lib.h @@ -284,25 +284,25 @@ struct BitBuf2 { /** @brief Holds the internal state information for input and output compression streams*/ struct isal_zstate { - uint32_t b_bytes_valid; //!< number of bytes of valid data in buffer - uint32_t b_bytes_processed; //!< keeps track of the number of bytes processed in isal_zstate.buffer uint8_t *file_start; //!< pointer to where file would logically start - uint32_t crc; //!< Current crc struct BitBuf2 bitbuf; //!< Bit Buffer + uint32_t crc; //!< Current crc enum isal_zstate_state state; //!< Current state in processing the data stream + uint16_t has_wrap_hdr; //!< keeps track of wrapper header + uint16_t has_eob_hdr; //!< keeps track of eob hdr (with BFINAL set) + uint16_t has_eob; //!< keeps track of eob on the last deflate block + uint16_t has_hist; //!< flag to track if there is match history + struct isal_mod_hist hist; uint32_t count; //!< used for partial header/trailer writes uint8_t tmp_out_buff[16]; //!< temporary array uint32_t tmp_out_start; //!< temporary variable uint32_t tmp_out_end; //!< temporary variable - uint32_t has_wrap_hdr; //!< keeps track of wrapper header - uint32_t has_eob; //!< keeps track of eob on the last deflate block - uint32_t has_eob_hdr; //!< keeps track of eob hdr (with BFINAL set) - uint32_t has_hist; //!< flag to track if there is match history + uint32_t b_bytes_valid; //!< number of valid bytes in buffer + uint32_t b_bytes_processed; //!< number of bytes processed in buffer + uint8_t buffer[2 * IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD]; //!< Internal buffer - struct isal_mod_hist hist; - - DECLARE_ALIGNED(uint8_t buffer[2 * IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD], 32); //!< Internal buffer - DECLARE_ALIGNED(uint16_t head[IGZIP_HASH_SIZE], 16); //!< Hash array + /* Stream should be setup such that the head is cache aligned*/ + uint16_t head[IGZIP_HASH_SIZE]; //!< Hash array }; @@ -335,8 +335,8 @@ struct isal_zstream { uint32_t level; //!< Compression level to use uint32_t level_buf_size; //!< Size of level_buf uint8_t * level_buf; //!< User allocated buffer required for different compression levels - uint32_t end_of_stream; //!< non-zero if this is the last input buffer - uint32_t flush; //!< Flush type can be NO_FLUSH, SYNC_FLUSH or FULL_FLUSH + uint16_t end_of_stream; //!< non-zero if this is the last input buffer + uint16_t flush; //!< Flush type can be NO_FLUSH, SYNC_FLUSH or FULL_FLUSH uint32_t gzip_flag; //!< Indicate if gzip compression is to be performed struct isal_zstate internal_state; //!< Internal state for this stream