optimize struct 'z_stream'

git-svn-id: svn://kolibrios.org@6797 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2016-12-14 14:54:51 +00:00
parent 7be1cdd574
commit 2c0a9cbf44
9 changed files with 291 additions and 177 deletions

View File

@ -81,7 +81,7 @@ proc png_set_packswap uses edi, png_ptr:dword
ret ret
endp endp
;void (png_structrp png_ptr, png_const_color_8p true_bits) ;void (png_structrp png_ptr, png_color_8p true_bits)
align 4 align 4
proc png_set_shift uses ecx edi, png_ptr:dword, true_bits:dword proc png_set_shift uses ecx edi, png_ptr:dword, true_bits:dword
png_debug 1, 'in png_set_shift' png_debug 1, 'in png_set_shift'
@ -139,8 +139,7 @@ proc png_set_filler uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
mov eax,[edi+png_struct.mode] mov eax,[edi+png_struct.mode]
and eax,PNG_IS_READ_STRUCT and eax,PNG_IS_READ_STRUCT
cmp eax,0 jz @f ;if (..!=0)
je @f ;if (..!=0)
if PNG_READ_FILLER_SUPPORTED eq 1 if PNG_READ_FILLER_SUPPORTED eq 1
; On read png_set_filler is always valid, regardless of the base PNG ; On read png_set_filler is always valid, regardless of the base PNG
; format, because other transformations can give a format where the ; format, because other transformations can give a format where the
@ -229,8 +228,7 @@ proc png_set_add_alpha uses eax edi, png_ptr:dword, filler:dword, filler_loc:dwo
; The above may fail to do anything. ; The above may fail to do anything.
mov eax,[edi+png_struct.transformations] mov eax,[edi+png_struct.transformations]
and eax,PNG_FILLER and eax,PNG_FILLER
cmp eax,0 jz .end_f ;if (..!=0)
je .end_f ;if (..!=0)
or dword[edi+png_struct.transformations],PNG_ADD_ALPHA or dword[edi+png_struct.transformations],PNG_ADD_ALPHA
.end_f: .end_f:
ret ret
@ -244,8 +242,7 @@ proc png_set_swap_alpha uses edi, png_ptr:dword
mov edi,[png_ptr] mov edi,[png_ptr]
cmp edi,0 cmp edi,0
je .end_f ;if (..==0) return je .end_f ;if (..==0) return
or dword[edi+png_struct.transformations], PNG_SWAP_ALPHA
; png_ptr->transformations |= PNG_SWAP_ALPHA;
.end_f: .end_f:
ret ret
endp endp
@ -259,8 +256,7 @@ proc png_set_invert_alpha uses edi, png_ptr:dword
mov edi,[png_ptr] mov edi,[png_ptr]
cmp edi,0 cmp edi,0
je .end_f ;if (..==0) return je .end_f ;if (..==0) return
or dword[edi+png_struct.transformations], PNG_INVERT_ALPHA
; png_ptr->transformations |= PNG_INVERT_ALPHA;
.end_f: .end_f:
ret ret
endp endp
@ -273,8 +269,7 @@ proc png_set_invert_mono uses edi, png_ptr:dword
mov edi,[png_ptr] mov edi,[png_ptr]
cmp edi,0 cmp edi,0
je .end_f ;if (..==0) return je .end_f ;if (..==0) return
or dword[edi+png_struct.transformations], PNG_INVERT_MONO
; png_ptr->transformations |= PNG_INVERT_MONO;
.end_f: .end_f:
ret ret
endp endp
@ -815,12 +810,10 @@ proc png_set_user_transform_info uses eax edi, png_ptr:dword, user_transform_ptr
if PNG_READ_USER_TRANSFORM_SUPPORTED eq 1 if PNG_READ_USER_TRANSFORM_SUPPORTED eq 1
mov eax,[edi+png_struct.mode] mov eax,[edi+png_struct.mode]
and eax,PNG_IS_READ_STRUCT and eax,PNG_IS_READ_STRUCT
cmp eax,0 jz @f
je @f
mov eax,[edi+png_struct.flags] mov eax,[edi+png_struct.flags]
and eax,PNG_FLAG_ROW_INIT and eax,PNG_FLAG_ROW_INIT
cmp eax,0 jz @f ;if (..!=0 && ..!=0)
je @f ;if (..!=0 && ..!=0)
cStr ,'info change after png_start_read_image or png_read_update_info' cStr ,'info change after png_start_read_image or png_read_update_info'
stdcall png_app_error, edi, eax stdcall png_app_error, edi, eax
jmp .end_f jmp .end_f
@ -842,7 +835,7 @@ endp
; associated with this pointer before png_write_destroy and png_read_destroy ; associated with this pointer before png_write_destroy and png_read_destroy
; are called. ; are called.
;voidp (png_const_structrp png_ptr) ;voidp (png_structrp png_ptr)
align 4 align 4
proc png_get_user_transform_ptr, png_ptr:dword proc png_get_user_transform_ptr, png_ptr:dword
mov eax,[png_ptr] mov eax,[png_ptr]
@ -853,7 +846,7 @@ proc png_get_user_transform_ptr, png_ptr:dword
ret ret
endp endp
;uint_32 (png_const_structrp png_ptr) ;uint_32 (png_structrp png_ptr)
align 4 align 4
proc png_get_current_row_number, png_ptr:dword proc png_get_current_row_number, png_ptr:dword
; See the comments in png.inc - this is the sub-image row when reading an ; See the comments in png.inc - this is the sub-image row when reading an
@ -870,7 +863,7 @@ proc png_get_current_row_number, png_ptr:dword
ret ret
endp endp
;byte (png_const_structrp png_ptr) ;byte (png_structrp png_ptr)
align 4 align 4
proc png_get_current_pass_number, png_ptr:dword proc png_get_current_pass_number, png_ptr:dword
mov eax,[png_ptr] mov eax,[png_ptr]

View File

@ -2939,19 +2939,18 @@ align 4
xor ecx,ecx xor ecx,ecx
align 4 align 4
.cycle4: .cycle4:
mov word[edi+png_struct.zstream.avail_out],16*1024 mov dword[edi+png_struct.zstream.avail_out],16*1024
stdcall [deflate], esi, Z_FINISH ;Z_NO_FLUSH stdcall [deflate], esi, Z_FINISH ;Z_NO_FLUSH
cmp eax,Z_STREAM_ERROR cmp eax,Z_STREAM_ERROR
je .end1 je .end1
add ecx,16*1024 add ecx,16*1024
movzx eax,word[edi+png_struct.zstream.avail_out] sub ecx,[edi+png_struct.zstream.avail_out]
sub ecx,eax cmp dword[edi+png_struct.zstream.avail_out],0
cmp word[edi+png_struct.zstream.avail_out],0
je .cycle4 ;while (strm.avail_out == 0) je .cycle4 ;while (strm.avail_out == 0)
if 0 if 0
mov word[edi+png_struct.zstream.avail_out],16*1024 mov dword[edi+png_struct.zstream.avail_out],16*1024
stdcall [deflate], esi, Z_FINISH stdcall [deflate], esi, Z_FINISH
cmp eax,Z_STREAM_ERROR cmp eax,Z_STREAM_ERROR
je .end1 je .end1

View File

@ -509,7 +509,7 @@ end if
mov dword[edi+png_struct.zstream.next_in],0 mov dword[edi+png_struct.zstream.next_in],0
mov dword[edi+png_struct.zstream.avail_in],0 mov dword[edi+png_struct.zstream.avail_in],0
mov dword[edi+png_struct.zstream.next_out],0 mov dword[edi+png_struct.zstream.next_out],0
mov word[edi+png_struct.zstream.avail_out],0 mov dword[edi+png_struct.zstream.avail_out],0
; Now initialize if required, setting the new parameters, otherwise just ; Now initialize if required, setting the new parameters, otherwise just
; to a simple reset to the previous parameters. ; to a simple reset to the previous parameters.
@ -643,7 +643,7 @@ endl
add eax,compression_state.output add eax,compression_state.output
mov [edi+png_struct.zstream.next_out],eax mov [edi+png_struct.zstream.next_out],eax
mov eax,sizeof.compression_state.output ;1024 mov eax,sizeof.compression_state.output ;1024
mov [edi+png_struct.zstream.avail_out],ax mov [edi+png_struct.zstream.avail_out],eax
mov [output_len],eax mov [output_len],eax
@ -659,7 +659,7 @@ endl
mov eax,[avail_in] mov eax,[avail_in]
mov [edi+png_struct.zstream.avail_in],eax mov [edi+png_struct.zstream.avail_in],eax
cmp word[edi+png_struct.zstream.avail_out],0 cmp dword[edi+png_struct.zstream.avail_out],0
jne .end0 ;if (..==0) jne .end0 ;if (..==0)
; Chunk data is limited to 2^31 bytes in length, so the prefix ; Chunk data is limited to 2^31 bytes in length, so the prefix
; length must be counted here. ; length must be counted here.
@ -699,7 +699,7 @@ endl
mov eax,[eax+png_compression_buffer.output] mov eax,[eax+png_compression_buffer.output]
mov [edi+png_struct.zstream.next_out],eax mov [edi+png_struct.zstream.next_out],eax
mov eax,[edi+png_struct.zbuffer_size] mov eax,[edi+png_struct.zbuffer_size]
mov [edi+png_struct.zstream.avail_out],ax mov [edi+png_struct.zstream.avail_out],eax
add [output_len],eax add [output_len],eax
; Move 'end' to the next buffer pointer. ; Move 'end' to the next buffer pointer.
@ -733,9 +733,9 @@ endl
; There may be some space left in the last output buffer. This needs to ; There may be some space left in the last output buffer. This needs to
; be subtracted from output_len. ; be subtracted from output_len.
movzx eax,word[edi+png_struct.zstream.avail_out] mov eax,[edi+png_struct.zstream.avail_out]
sub [output_len],eax sub [output_len],eax
mov word[edi+png_struct.zstream.avail_out],0 ;safety mov dword[edi+png_struct.zstream.avail_out],0 ;safety
mov eax,[output_len] mov eax,[output_len]
mov [ebx+compression_state.output_len],eax mov [ebx+compression_state.output_len],eax
@ -1216,7 +1216,7 @@ proc png_compress_IDAT uses eax ebx ecx edx, input:dword, input_len:dword, flush
add eax,png_compression_buffer.output add eax,png_compression_buffer.output
mov [edi+png_struct.zstream.next_out],eax mov [edi+png_struct.zstream.next_out],eax
mov eax,[edi+png_struct.zbuffer_size] mov eax,[edi+png_struct.zbuffer_size]
mov [edi+png_struct.zstream.avail_out],ax mov [edi+png_struct.zstream.avail_out],eax
.end0: .end0:
; Now loop reading and writing until all the input is consumed or an error ; Now loop reading and writing until all the input is consumed or an error
@ -1258,7 +1258,7 @@ align 4
; that these two zstream fields are preserved across the calls, therefore ; that these two zstream fields are preserved across the calls, therefore
; there is no need to set these up on entry to the loop. ; there is no need to set these up on entry to the loop.
cmp word[edi+png_struct.zstream.avail_out],0 cmp dword[edi+png_struct.zstream.avail_out],0
jne .end2 ;if (..==0) jne .end2 ;if (..==0)
mov edx,[edi+png_struct.zbuffer_list] mov edx,[edi+png_struct.zbuffer_list]
add edx,png_compression_buffer.output add edx,png_compression_buffer.output
@ -1283,7 +1283,7 @@ end if
or dword[edi+png_struct.mode],PNG_HAVE_IDAT or dword[edi+png_struct.mode],PNG_HAVE_IDAT
mov [edi+png_struct.zstream.next_out],edx mov [edi+png_struct.zstream.next_out],edx
mov [edi+png_struct.zstream.avail_out],cx mov [edi+png_struct.zstream.avail_out],ecx
; For SYNC_FLUSH or FINISH it is essential to keep calling zlib with ; For SYNC_FLUSH or FINISH it is essential to keep calling zlib with
; the same flush parameter until it has finished output, for NO_FLUSH ; the same flush parameter until it has finished output, for NO_FLUSH
@ -1321,7 +1321,7 @@ end if
mov edx,[edi+png_struct.zbuffer_list] mov edx,[edi+png_struct.zbuffer_list]
add edx,png_compression_buffer.output add edx,png_compression_buffer.output
mov ecx,[edi+png_struct.zbuffer_size] mov ecx,[edi+png_struct.zbuffer_size]
movzx eax,word[edi+png_struct.zstream.avail_out] mov eax,[edi+png_struct.zstream.avail_out]
sub ecx,eax sub ecx,eax
;edx = data ;edx = data
;ecx = size ;ecx = size
@ -1337,7 +1337,7 @@ if PNG_WRITE_OPTIMIZE_CMF_SUPPORTED eq 1
@@: @@:
end if end if
stdcall png_write_complete_chunk, edi, png_IDAT, edx, ecx stdcall png_write_complete_chunk, edi, png_IDAT, edx, ecx
mov word[edi+png_struct.zstream.avail_out],0 mov dword[edi+png_struct.zstream.avail_out],0
mov dword[edi+png_struct.zstream.next_out],0 mov dword[edi+png_struct.zstream.next_out],0
or dword[edi+png_struct.mode], PNG_HAVE_IDAT or PNG_AFTER_IDAT or dword[edi+png_struct.mode], PNG_HAVE_IDAT or PNG_AFTER_IDAT

View File

@ -40,17 +40,17 @@ tz14 db 'reserved',13,10,0
sv_2: sv_2:
dd z_stream.next_in,4,tz1 dd z_stream.next_in,4,tz1
dd z_stream.avail_in,2,tz2 dd z_stream.avail_in,4,tz2
dd z_stream.total_in,4,tz3 dd z_stream.total_in,4,tz3
dd z_stream.next_out,4,tz4 dd z_stream.next_out,4,tz4
dd z_stream.avail_out,2,tz5 dd z_stream.avail_out,4,tz5
dd z_stream.total_out,4,tz6 dd z_stream.total_out,4,tz6
dd z_stream.msg,4,tz7 dd z_stream.msg,4,tz7
dd z_stream.state,4,tz8 dd z_stream.state,4,tz8
dd z_stream.zalloc,4,tz9 dd z_stream.zalloc,4,tz9
dd z_stream.zfree,4,tz10 dd z_stream.zfree,4,tz10
dd z_stream.opaque,4,tz11 dd z_stream.opaque,4,tz11
dd z_stream.data_type,2,tz12 dd z_stream.data_type,4,tz12
dd z_stream.adler,4,tz13 dd z_stream.adler,4,tz13
dd z_stream.reserved,4,tz14 dd z_stream.reserved,4,tz14
dd 0,0 dd 0,0

View File

@ -439,11 +439,10 @@ endp
align 4 align 4
proc deflateSetDictionary uses ebx edi, strm:dword, dictionary:dword, dictLength:dword proc deflateSetDictionary uses ebx edi, strm:dword, dictionary:dword, dictLength:dword
locals locals
; deflate_state *s;
; uInt str, n; ; uInt str, n;
wrap dd ? ;int wrap dd ? ;int
avail dd ? ;unsigned avail dd ? ;unsigned
; z_const unsigned char *next; next dd ? ;unsigned char*
endl endl
mov ebx,[strm] mov ebx,[strm]
cmp ebx,Z_NULL cmp ebx,Z_NULL
@ -461,16 +460,31 @@ endl
mov eax,[edi+deflate_state.wrap] mov eax,[edi+deflate_state.wrap]
mov [wrap],eax mov [wrap],eax
; if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) cmp dword[wrap],2
; return Z_STREAM_ERROR; je .end1
cmp dword[edi+deflate_state.lookahead],0
jne .end1
cmp dword[wrap],1
jne @f
cmp dword[edi+deflate_state.status],INIT_STATE
je @f
.end1: ;if (..==.. || .. || (..==.. && ..!=..)) return ..
mov eax,Z_STREAM_ERROR
jmp .end_f
@@:
; when using zlib wrappers, compute Adler-32 for provided dictionary ; when using zlib wrappers, compute Adler-32 for provided dictionary
; if (wrap == 1) cmp dword[wrap],1
; strm->adler = adler32(strm->adler, dictionary, dictLength); jne @f ;if (..==..)
; s->wrap = 0; /* avoid computing Adler-32 in read_buf */ stdcall adler32, [ebx+z_stream.adler], [dictionary], [dictLength]
mov [ebx+z_stream.adler],eax
@@:
mov dword[edi+deflate_state.wrap],0 ;avoid computing Adler-32 in read_buf
; if dictionary would fill window, just replace the history ; if dictionary would fill window, just replace the history
; if (dictLength >= s->w_size) { mov eax,[edi+deflate_state.w_size]
cmp [dictLength],eax
jl .end2 ;if (..>=..)
; if (wrap == 0) { /* already empty otherwise */ ; if (wrap == 0) { /* already empty otherwise */
; CLEAR_HASH(s); ; CLEAR_HASH(s);
; s->strstart = 0; ; s->strstart = 0;
@ -478,8 +492,9 @@ endl
; s->insert = 0; ; s->insert = 0;
; } ; }
; dictionary += dictLength - s->w_size; /* use the tail */ ; dictionary += dictLength - s->w_size; /* use the tail */
; dictLength = s->w_size; mov eax,[edi+deflate_state.w_size]
; } mov [dictLength],eax
.end2:
; insert dictionary into window and hash ; insert dictionary into window and hash
; avail = strm->avail_in; ; avail = strm->avail_in;
@ -504,13 +519,19 @@ end if
; } ; }
; s->strstart += s->lookahead; ; s->strstart += s->lookahead;
; s->block_start = (long)s->strstart; ; s->block_start = (long)s->strstart;
; s->insert = s->lookahead; mov eax,[edi+deflate_state.lookahead]
; s->lookahead = 0; mov [edi+deflate_state.insert],eax
; s->match_length = s->prev_length = MIN_MATCH-1; mov dword[edi+deflate_state.lookahead],0
; s->match_available = 0; mov eax,MIN_MATCH-1
; strm->next_in = next; mov [edi+deflate_state.prev_length],eax
; strm->avail_in = avail; mov [edi+deflate_state.match_length],eax
; s->wrap = wrap; mov dword[edi+deflate_state.match_available],0
mov eax,[next]
mov [ebx+z_stream.next_in],eax
mov eax,[avail]
mov [ebx+z_stream.avail_in],eax
mov eax,[wrap]
mov [edi+deflate_state.wrap],eax
mov eax,Z_OK mov eax,Z_OK
.end_f: .end_f:
ret ret
@ -521,8 +542,6 @@ endp
; z_streamp strm ; z_streamp strm
align 4 align 4
proc deflateResetKeep uses ebx edi, strm:dword proc deflateResetKeep uses ebx edi, strm:dword
; deflate_state *s;
mov ebx,[strm] mov ebx,[strm]
cmp ebx,Z_NULL cmp ebx,Z_NULL
je @f je @f
@ -542,7 +561,7 @@ proc deflateResetKeep uses ebx edi, strm:dword
mov dword[ebx+z_stream.total_out],0 mov dword[ebx+z_stream.total_out],0
mov dword[ebx+z_stream.total_in],0 mov dword[ebx+z_stream.total_in],0
mov dword[ebx+z_stream.msg],Z_NULL ;use zfree if we ever allocate msg dynamically mov dword[ebx+z_stream.msg],Z_NULL ;use zfree if we ever allocate msg dynamically
mov word[ebx+z_stream.data_type],Z_UNKNOWN mov dword[ebx+z_stream.data_type],Z_UNKNOWN
mov dword[edi+deflate_state.pending],0 mov dword[edi+deflate_state.pending],0
mov eax,[edi+deflate_state.pending_buf] mov eax,[edi+deflate_state.pending_buf]
@ -584,7 +603,7 @@ proc deflateReset uses ebx, strm:dword
mov ebx,[strm] mov ebx,[strm]
zlib_debug 'deflateReset' zlib_debug 'deflateReset'
stdcall deflateResetKeep, ebx stdcall deflateResetKeep, ebx
cmp eax,0 cmp eax,Z_OK
jne @f ;if (..==Z_OK) jne @f ;if (..==Z_OK)
stdcall lm_init, [ebx+z_stream.state] stdcall lm_init, [ebx+z_stream.state]
@@: @@:
@ -696,8 +715,10 @@ endp
; int strategy ; int strategy
align 4 align 4
proc deflateParams uses ebx edi, strm:dword, level:dword, strategy:dword proc deflateParams uses ebx edi, strm:dword, level:dword, strategy:dword
; compress_func func; locals
; int err = Z_OK; co_func dd ?
err dd Z_OK
endl
mov ebx,[strm] mov ebx,[strm]
cmp ebx,Z_NULL cmp ebx,Z_NULL
@ -721,14 +742,26 @@ else
mov dword[level],6 mov dword[level],6
@@: @@:
end if end if
; if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { cmp dword[level],0
; return Z_STREAM_ERROR; jl @f
; } cmp dword[level],9
; func = configuration_table[s->level].func; jg @f
cmp dword[strategy],0
jl @f
cmp dword[strategy],Z_FIXED
jle .end1
@@: ;if (..<0 || ..>9 || ..<0 || ..>..)
mov eax,Z_STREAM_ERROR
jmp .end_f
.end1:
movzx eax,word[edi+deflate_state.level]
imul eax,sizeof.config_s
add eax,configuration_table+config_s.co_func
mov [co_func],eax
; if ((strategy != s->strategy || func != configuration_table[level].func) && ; if ((strategy != s->strategy || co_func != configuration_table[level].func) &&
; strm->total_in != 0) { ; strm->total_in != 0) {
; Flush the last buffer: ; Flush the last buffer:
; err = deflate(strm, Z_BLOCK); ; err = deflate(strm, Z_BLOCK);
; if (err == Z_BUF_ERROR && s->pending == 0) ; if (err == Z_BUF_ERROR && s->pending == 0)
; err = Z_OK; ; err = Z_OK;
@ -740,8 +773,9 @@ end if
; s->nice_match = configuration_table[level].nice_length; ; s->nice_match = configuration_table[level].nice_length;
; s->max_chain_length = configuration_table[level].max_chain; ; s->max_chain_length = configuration_table[level].max_chain;
; } ; }
; s->strategy = strategy; mov eax,[strategy]
; return err; mov [edi+deflate_state.strategy],ax
mov eax,[err]
.end_f: .end_f:
ret ret
endp endp
@ -893,10 +927,10 @@ proc flush_pending uses eax ebx ecx edx, strm:dword
stdcall _tr_flush_bits, edx stdcall _tr_flush_bits, edx
mov ecx,[edx+deflate_state.pending] mov ecx,[edx+deflate_state.pending]
movzx eax,word[ebx+z_stream.avail_out] mov eax,[ebx+z_stream.avail_out]
cmp ecx,eax cmp ecx,eax
jle @f ;if (..>..) jle @f ;if (..>..)
movzx ecx,word[ebx+z_stream.avail_out] mov ecx,eax
@@: @@:
cmp ecx,0 cmp ecx,0
je @f je @f
@ -905,7 +939,7 @@ proc flush_pending uses eax ebx ecx edx, strm:dword
add [ebx+z_stream.next_out],ecx add [ebx+z_stream.next_out],ecx
add [edx+deflate_state.pending_out],ecx add [edx+deflate_state.pending_out],ecx
add [ebx+z_stream.total_out],ecx add [ebx+z_stream.total_out],ecx
sub [ebx+z_stream.avail_out],cx sub [ebx+z_stream.avail_out],ecx
sub [edx+deflate_state.pending],ecx sub [edx+deflate_state.pending],ecx
cmp dword[edx+deflate_state.pending],0 cmp dword[edx+deflate_state.pending],0
jne @f ;if (..==0) jne @f ;if (..==0)
@ -955,7 +989,7 @@ zlib_debug 'deflate strm = %d',ebx
ERR_RETURN ebx, Z_STREAM_ERROR ERR_RETURN ebx, Z_STREAM_ERROR
jmp .end_f jmp .end_f
.end0: .end0:
cmp word[ebx+z_stream.avail_out],0 cmp dword[ebx+z_stream.avail_out],0
jne @f ;if (..==0) jne @f ;if (..==0)
ERR_RETURN ebx, Z_BUF_ERROR ERR_RETURN ebx, Z_BUF_ERROR
jmp .end_f jmp .end_f
@ -1319,7 +1353,7 @@ end if
cmp dword[edi+deflate_state.pending],0 cmp dword[edi+deflate_state.pending],0
je .end13 ;if (..!=0) je .end13 ;if (..!=0)
stdcall flush_pending, ebx stdcall flush_pending, ebx
cmp word[ebx+z_stream.avail_out],0 cmp dword[ebx+z_stream.avail_out],0
jne @f ;if (..==0) jne @f ;if (..==0)
; Since avail_out is 0, deflate will be called again with ; Since avail_out is 0, deflate will be called again with
; more output space, but possibly with both pending and ; more output space, but possibly with both pending and
@ -1398,7 +1432,7 @@ end if
cmp edx,finish_started cmp edx,finish_started
jne .end19 jne .end19
@@: ;if (..==.. || ..==..) @@: ;if (..==.. || ..==..)
cmp word[ebx+z_stream.avail_out],0 cmp dword[ebx+z_stream.avail_out],0
jne @f ;if (..==0) jne @f ;if (..==0)
mov dword[edi+deflate_state.last_flush],-1 ;avoid BUF_ERROR next call, see above mov dword[edi+deflate_state.last_flush],-1 ;avoid BUF_ERROR next call, see above
@@: @@:
@ -1435,13 +1469,13 @@ end if
mov dword[edi+deflate_state.insert],0 mov dword[edi+deflate_state.insert],0
.end16: .end16:
stdcall flush_pending, ebx stdcall flush_pending, ebx
cmp word[ebx+z_stream.avail_out],0 cmp dword[ebx+z_stream.avail_out],0
jne .end11 ;if (..==0) jne .end11 ;if (..==0)
mov dword[edi+deflate_state.last_flush],-1 ;avoid BUF_ERROR at next call, see above mov dword[edi+deflate_state.last_flush],-1 ;avoid BUF_ERROR at next call, see above
mov eax,Z_OK mov eax,Z_OK
jmp .end_f jmp .end_f
.end11: .end11:
cmp word[ebx+z_stream.avail_out],0 cmp dword[ebx+z_stream.avail_out],0
jg @f jg @f
zlib_assert 'bug2' ;Assert(..>0) zlib_assert 'bug2' ;Assert(..>0)
@@: @@:
@ -1676,7 +1710,7 @@ proc read_buf uses ebx ecx, strm:dword, buf:dword, size:dword
stdcall zmemcpy, [buf],[ebx+z_stream.next_in],eax stdcall zmemcpy, [buf],[ebx+z_stream.next_in],eax
mov ecx,[ebx+z_stream.state] mov ecx,[ebx+z_stream.state]
cmp [ecx+deflate_state.wrap],1 cmp dword[ecx+deflate_state.wrap],1
jne @f ;if (..==..) jne @f ;if (..==..)
push eax push eax
stdcall adler32, [ebx+z_stream.adler], [buf], eax stdcall adler32, [ebx+z_stream.adler], [buf], eax
@ -1685,7 +1719,7 @@ proc read_buf uses ebx ecx, strm:dword, buf:dword, size:dword
jmp .end0 jmp .end0
@@: @@:
if GZIP eq 1 if GZIP eq 1
cmp [ecx+deflate_state.wrap],2 cmp dword[ecx+deflate_state.wrap],2
jne .end0 ;else if (..==..) jne .end0 ;else if (..==..)
push eax push eax
stdcall calc_crc32, [ebx+z_stream.adler], [buf], eax stdcall calc_crc32, [ebx+z_stream.adler], [buf], eax
@ -1763,95 +1797,185 @@ if FASTEST eq 0
;#ifndef ASMV ;#ifndef ASMV
; For 80x86 and 680x0, an optimized version will be provided in match.asm or ; For 80x86 and 680x0, an optimized version will be provided in match.asm or
; match.S. The code will be functionally equivalent. ; match.S. The code will be functionally equivalent.
locals
chain_length dd ? ;unsigned ;max hash chain length
len dd ? ;int ;length of current match
strend dd ? ;Bytef *
best_len dd ? ;int ;best match length so far
nice_match dd ? ;int ;stop if match long enough
limit dd NIL ;IPos
prev dd ? ;Posf *
wmask dd ? ;uInt
endl
mov edx,[s]
mov eax,[edx+deflate_state.max_chain_length]
mov [chain_length],eax
mov edi,[edx+deflate_state.window]
add edi,[edx+deflate_state.strstart]
;edi - Bytef *scan ;current string
;esi - Bytef *match ;matched string
mov eax,[edx+deflate_state.prev_length]
mov [best_len],eax
mov eax,[edx+deflate_state.nice_match]
mov [nice_match],eax
; unsigned chain_length = s->max_chain_length;/* max hash chain length */ MAX_DIST edx
; register Bytef *scan = s->window + s->strstart; /* current string */ cmp [edx+deflate_state.strstart],eax
; register Bytef *match; /* matched string */ jle @f
; register int len; /* length of current match */ mov ecx,[edx+deflate_state.strstart]
; int best_len = s->prev_length; /* best match length so far */ sub ecx,eax
; int nice_match = s->nice_match; /* stop if match long enough */ mov [limit],ecx
; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? @@:
; s->strstart - (IPos)MAX_DIST(s) : NIL;
; Stop when cur_match becomes <= limit. To simplify the code, ; Stop when cur_match becomes <= limit. To simplify the code,
; we prevent matches with the string of window index 0. ; we prevent matches with the string of window index 0.
mov eax,[edx+deflate_state.prev]
; Posf *prev = s->prev; mov [prev],eax
; uInt wmask = s->w_mask; mov eax,[edx+deflate_state.w_mask]
mov [wmask],eax
; register Bytef *strend = s->window + s->strstart + MAX_MATCH; mov eax,edi
; register Byte scan_end1 = scan[best_len-1]; add eax,MAX_MATCH ;-1 ???
; register Byte scan_end = scan[best_len]; mov [strend],eax
mov eax,[best_len]
dec eax
mov bx,[edi+eax]
;bl - Byte scan_end1
;bh - Byte scan_end
; The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. ; The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
; It is easy to get rid of this optimization if necessary. ; It is easy to get rid of this optimization if necessary.
; Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); if MAX_MATCH <> 258
cmp dword[edx+deflate_state.hash_bits],8
jge @f
zlib_assert 'Code too clever' ;Assert(..>=.. && ..==..)
@@:
end if
; Do not waste too much time if we already have a good match: ; Do not waste too much time if we already have a good match:
; if (s->prev_length >= s->good_match) { mov eax,[edx+deflate_state.good_match]
; chain_length >>= 2; cmp [edx+deflate_state.prev_length],eax
; } jl @f ;if (..>=..)
shr dword[chain_length],2
@@:
; Do not look for matches beyond the end of the input. This is necessary ; Do not look for matches beyond the end of the input. This is necessary
; to make deflate deterministic. ; to make deflate deterministic.
; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; mov eax,[edx+deflate_state.lookahead]
cmp dword[nice_match],eax
jle @f ;if (..>..)
mov [nice_match],eax
@@:
; Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); mov eax,[edx+deflate_state.window_size]
sub eax,MIN_LOOKAHEAD
cmp [edx+deflate_state.strstart],eax
jle .cycle0
zlib_assert 'need lookahead' ;Assert(..<=..)
; do { align 4
; Assert(cur_match < s->strstart, "no future"); .cycle0: ;do
; match = s->window + cur_match; mov eax,[edx+deflate_state.strstart]
cmp [cur_match],eax
jl @f
zlib_assert 'no future' ;Assert(..<..)
@@:
mov esi,[edx+deflate_state.window]
add esi,[cur_match]
; Skip to next match if the match length cannot increase ; Skip to next match if the match length cannot increase
; or if the match length is less than 2. Note that the checks below ; or if the match length is less than 2. Note that the checks below
; for insufficient lookahead only occur occasionally for performance ; for insufficient lookahead only occur occasionally for performance
; reasons. Therefore uninitialized memory will be accessed, and ; reasons. Therefore uninitialized memory will be accessed, and
; conditional jumps will be made that depend on those values. ; conditional jumps will be made that depend on those values.
; However the length of the match is limited to the lookahead, so ; However the length of the match is limited to the lookahead, so
; the output of deflate is not affected by the uninitialized values. ; the output of deflate is not affected by the uninitialized values.
; if (match[best_len] != scan_end || mov eax,[best_len]
; match[best_len-1] != scan_end1 || dec eax
; *match != *scan || cmp word[esi+eax],bx
; *++match != scan[1]) continue; jne .cycle0cont
mov al,byte[esi]
cmp al,byte[edi]
jne .cycle0cont
inc esi
mov al,byte[esi]
cmp al,[edi+1]
jne .cycle0cont ;if (..!=.. || ..!=.. || ..!=.. || ..!=..) continue
; The check at best_len-1 can be removed because it will be made ; The check at best_len-1 can be removed because it will be made
; again later. (This heuristic is not always a win.) ; again later. (This heuristic is not always a win.)
; It is not necessary to compare scan[2] and match[2] since they ; It is not necessary to compare scan[2] and match[2] since they
; are always equal when the other bytes match, given that ; are always equal when the other bytes match, given that
; the hash keys are equal and that HASH_BITS >= 8. ; the hash keys are equal and that HASH_BITS >= 8.
; scan += 2, match++; add edi,2
; Assert(*scan == *match, "match[2]?"); inc esi
mov al,byte[edi]
cmp al,byte[esi]
je @f
zlib_assert 'match[2]?' ;Assert(..==..)
@@:
; We check for insufficient lookahead only every 8th comparison; ; We check for insufficient lookahead only every 8th comparison;
; the 256th check will be made at strstart+258. ; the 256th check will be made at strstart+258.
; do { inc edi
; } while (*++scan == *++match && *++scan == *++match && inc esi
; *++scan == *++match && *++scan == *++match && mov ecx,[strend]
; *++scan == *++match && *++scan == *++match && sub ecx,edi
; *++scan == *++match && *++scan == *++match && jz @f
; scan < strend); repe cmpsb
@@:
; Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); mov eax,[edx+deflate_state.window_size]
dec eax
add eax,[edx+deflate_state.window]
cmp edi,eax
jle @f
zlib_assert 'wild scan' ;Assert(..<=..)
@@:
; len = MAX_MATCH - (int)(strend - scan); mov eax,MAX_MATCH
; scan = strend - MAX_MATCH; add eax,edi
sub eax,[strend]
mov [len],eax
mov edi,[strend]
sub edi,MAX_MATCH
; if (len > best_len) { mov eax,[best_len]
; s->match_start = cur_match; cmp [len],eax
; best_len = len; jle .cycle0cont ;if (..>..)
; if (len >= nice_match) break; mov eax,[cur_match]
; scan_end1 = scan[best_len-1]; mov [edx+deflate_state.match_start],eax
; scan_end = scan[best_len]; mov eax,[len]
; } mov [best_len],eax
; } while ((cur_match = prev[cur_match & wmask]) > limit mov eax,[nice_match]
; && --chain_length != 0); cmp [len],eax
jge .cycle0end ;if (..>=..) break
mov eax,[best_len]
dec eax
mov bx,[edi+eax]
; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; .cycle0cont:
; return s->lookahead; mov eax,[cur_match]
;end if /* ASMV */ and eax,[wmask]
shl eax,2
add eax,[prev]
mov eax,[eax] ;eax = prev[cur_match & wmask]
mov [cur_match],eax
cmp eax,[limit]
jle .cycle0end
dec dword[chain_length]
cmp dword[chain_length],0
jne .cycle0
.cycle0end: ;while (..>.. && ..!=0)
mov eax,[edx+deflate_state.lookahead]
cmp [best_len],eax
jg @f ;if (..<=..)
mov eax,[best_len]
@@:
;end if ;ASMV
else ;FASTEST else ;FASTEST
@ -2054,8 +2178,8 @@ pushad
@@: @@:
loop .cycle1 ;while (..) loop .cycle1 ;while (..)
mov ecx,ebx
if FASTEST eq 0 if FASTEST eq 0
mov ecx,ebx
mov esi,ecx mov esi,ecx
shl esi,2 shl esi,2
add esi,[edi+deflate_state.prev] add esi,[edi+deflate_state.prev]
@ -2253,7 +2377,7 @@ macro FLUSH_BLOCK s, last
local .end0 local .end0
FLUSH_BLOCK_ONLY s, last FLUSH_BLOCK_ONLY s, last
mov eax,[s+deflate_state.strm] mov eax,[s+deflate_state.strm]
cmp word[eax+z_stream.avail_out],0 cmp dword[eax+z_stream.avail_out],0
jne .end0 ;if (..==0) jne .end0 ;if (..==0)
if last eq 1 if last eq 1
mov eax,finish_started mov eax,finish_started
@ -2576,10 +2700,10 @@ align 4
mov dword[edi+deflate_state.match_length],MIN_MATCH-1 mov dword[edi+deflate_state.match_length],MIN_MATCH-1
cmp ecx,NIL cmp ecx,NIL
je @f je .end1
mov eax,[edi+deflate_state.prev_length] mov eax,[edi+deflate_state.prev_length]
cmp eax,[edi+deflate_state.max_lazy_match] cmp eax,[edi+deflate_state.max_lazy_match]
jge @f jge .end1
MAX_DIST edi MAX_DIST edi
mov ebx,[edi+deflate_state.strstart] mov ebx,[edi+deflate_state.strstart]
sub ebx,ecx sub ebx,ecx
@ -2596,14 +2720,18 @@ align 4
cmp dword[edi+deflate_state.match_length],5 cmp dword[edi+deflate_state.match_length],5
jg .end1 jg .end1
cmp word[edi+deflate_state.strategy],Z_FILTERED cmp word[edi+deflate_state.strategy],Z_FILTERED
jne .end1 if TOO_FAR <= 32767
; if (..<=.. && (..==.. je @f
;#if TOO_FAR <= 32767 cmp dword[edi+deflate_state.match_length],MIN_MATCH
; || (s->match_length == MIN_MATCH && jne .end1
; s->strstart - s->match_start > TOO_FAR) mov eax,[edi+deflate_state.strstart]
;end if sub eax,[edi+deflate_state.match_start]
; )) cmp eax,TOO_FAR
jle .end1 ;if (..<=.. && (..==.. || (..==.. && ..>..)))
@@:
else
jne .end1 ;if (..<=.. && ..==..)
end if
; If prev_match is also MIN_MATCH, match_start is garbage ; If prev_match is also MIN_MATCH, match_start is garbage
; but we will ignore the current match anyway. ; but we will ignore the current match anyway.
@ -2615,9 +2743,9 @@ align 4
mov eax,[edi+deflate_state.prev_length] mov eax,[edi+deflate_state.prev_length]
cmp eax,MIN_MATCH cmp eax,MIN_MATCH
jl .end2: jl .end2
cmp [edi+deflate_state.match_length],eax cmp [edi+deflate_state.match_length],eax
jg .end2: ;if (..>=.. && ..<=..) jg .end2 ;if (..>=.. && ..<=..)
mov edx,[edi+deflate_state.strstart] mov edx,[edi+deflate_state.strstart]
add edx,[edi+deflate_state.lookahead] add edx,[edi+deflate_state.lookahead]
sub edx,MIN_MATCH sub edx,MIN_MATCH
@ -2681,7 +2809,7 @@ align 4
inc dword[edi+deflate_state.strstart] inc dword[edi+deflate_state.strstart]
dec dword[edi+deflate_state.lookahead] dec dword[edi+deflate_state.lookahead]
mov eax,[edi+deflate_state.strm] mov eax,[edi+deflate_state.strm]
cmp word[eax+z_stream.avail_out],0 cmp dword[eax+z_stream.avail_out],0
jne .cycle0 ;if (..==0) return .. jne .cycle0 ;if (..==0) return ..
mov eax,need_more mov eax,need_more
jmp .end_f jmp .end_f

View File

@ -144,11 +144,6 @@ struct deflate_state ;internal_state
; smaller than this value. This mechanism is used only for compression ; smaller than this value. This mechanism is used only for compression
; levels >= 4. ; levels >= 4.
;# define max_insert_length max_lazy_match
; Insert new strings in the hash table only if the match length is not
; greater than this length. This saves time but degrades compression.
; max_insert_length is used only for compression levels <= 3.
level dw ? ;int ;compression level (1..9) level dw ? ;int ;compression level (1..9)
strategy dw ? ;int ;favor or force Huffman coding strategy dw ? ;int ;favor or force Huffman coding
@ -232,6 +227,11 @@ end if
; updated to the new high water mark. ; updated to the new high water mark.
ends ends
deflate_state.max_insert_length equ deflate_state.max_lazy_match
; Insert new strings in the hash table only if the match length is not
; greater than this length. This saves time but degrades compression.
; max_insert_length is used only for compression levels <= 3.
; Output a byte on the stream. ; Output a byte on the stream.
; IN assertion: there is enough room in pending_buf. ; IN assertion: there is enough room in pending_buf.

View File

@ -164,7 +164,7 @@ test_code:
mov ecx,[m0size] mov ecx,[m0size]
mov [eax+z_stream.avail_in],ecx ;à §¬¥à ᦨ¬ ¥¬ë¦ ¤ ­­ëå mov [eax+z_stream.avail_in],ecx ;à §¬¥à ᦨ¬ ¥¬ë¦ ¤ ­­ëå
mov [eax+z_stream.next_out],m1 ;ãáâ ­ ¢«¨¢ ¥¬ ¡ãä¥à ¤«ï ᦠâ¨ï mov [eax+z_stream.next_out],m1 ;ãáâ ­ ¢«¨¢ ¥¬ ¡ãä¥à ¤«ï ᦠâ¨ï
mov word[eax+z_stream.avail_out],1024 ;à §¬¥à ¡ãä¥à  ¤«ï ᦠâ¨ï (¬ ªá¨¬ã¬ 16 Š¡) mov dword[eax+z_stream.avail_out],1024 ;à §¬¥à ¡ãä¥à  ¤«ï ᦠâ¨ï (¬ ªá¨¬ã¬ 16 Š¡)
;¢ëç¨á«ï¥¬ crc ¤«ï ᦨ¬ ¥¬ë¦ ¤ ­­ëå ;¢ëç¨á«ï¥¬ crc ¤«ï ᦨ¬ ¥¬ë¦ ¤ ­­ëå
stdcall [calc_crc32], 0,m0,ecx stdcall [calc_crc32], 0,m0,ecx
@ -176,9 +176,9 @@ test_code:
;call print_z_struct ;call print_z_struct
;à §¬¥à ᦠâëå ¤ ­­ëå: 1024-word[my_strm.avail_out] ;à §¬¥à ᦠâëå ¤ ­­ëå: 1024-[my_strm.avail_out]
mov ecx,1024 mov ecx,1024
sub cx,word[my_strm.avail_out] sub ecx,[my_strm.avail_out]
mov [m1size],ecx mov [m1size],ecx
;assert(ret != Z_STREAM_ERROR) ;assert(ret != Z_STREAM_ERROR)

View File

@ -1555,10 +1555,10 @@ endl
; Check if the file is binary or text ; Check if the file is binary or text
mov ebx,[edi+deflate_state.strm] mov ebx,[edi+deflate_state.strm]
cmp word[ebx+z_stream.data_type],Z_UNKNOWN cmp dword[ebx+z_stream.data_type],Z_UNKNOWN
jne @f ;if (..==..) jne @f ;if (..==..)
stdcall detect_data_type, edi stdcall detect_data_type, edi
mov [ebx+z_stream.data_type],ax mov [ebx+z_stream.data_type],eax
@@: @@:
; Construct the literal and distance trees ; Construct the literal and distance trees

View File

@ -76,7 +76,7 @@ struct z_stream ;z_stream_s
total_in dd ? ;uLong ;total number of input bytes read so far total_in dd ? ;uLong ;total number of input bytes read so far
next_out dd ? ;Bytef * ;next output byte should be put there next_out dd ? ;Bytef * ;next output byte should be put there
avail_out dw ? ;uInt ;remaining free space at next_out avail_out dd ? ;uInt ;remaining free space at next_out
total_out dd ? ;uLong ;total number of bytes output so far total_out dd ? ;uLong ;total number of bytes output so far
msg dd ? ;z_const char * ;last error message, NULL if no error msg dd ? ;z_const char * ;last error message, NULL if no error
@ -86,7 +86,7 @@ struct z_stream ;z_stream_s
zfree dd ? ;free_func ;used to free the internal state zfree dd ? ;free_func ;used to free the internal state
opaque dd ? ;voidpf ;private data object passed to zalloc and zfree opaque dd ? ;voidpf ;private data object passed to zalloc and zfree
data_type dw ? ;int ;best guess about the data type: binary or text data_type dd ? ;int ;best guess about the data type: binary or text
adler dd ? ;uLong ;adler32 value of the uncompressed data adler dd ? ;uLong ;adler32 value of the uncompressed data
reserved dd ? ;uLong ;reserved for future use reserved dd ? ;uLong ;reserved for future use
ends ends
@ -227,14 +227,8 @@ if Z_SOLO eq 0
; z_off64_t pos; ; z_off64_t pos;
;}; ;};
if Z_PREFIX_SET eq 1
;# undef z_gzgetc
;# define z_gzgetc(g) \
; ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
else
;# define gzgetc(g) \ ;# define gzgetc(g) \
; ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) ; ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
end if
end if end if