small fixes & optimize

git-svn-id: svn://kolibrios.org@6851 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2017-02-01 17:23:05 +00:00
parent abcb2b1bfa
commit 88bb295c51
5 changed files with 114 additions and 88 deletions

View File

@ -136,13 +136,13 @@ endl
movzx eax,byte[ebx] movzx eax,byte[ebx]
add [adler],eax add [adler],eax
cmp dword[adler],BASE cmp dword[adler],BASE
jl @f ;if (..>=..) jb @f ;if (..>=..)
sub dword[adler],BASE sub dword[adler],BASE
@@: @@:
mov eax,[adler] mov eax,[adler]
add [sum2],eax add [sum2],eax
cmp dword[sum2],BASE cmp dword[sum2],BASE
jl @f ;if (..>=..) jb @f ;if (..>=..)
sub dword[sum2],BASE sub dword[sum2],BASE
@@: @@:
jmp .combine jmp .combine

View File

@ -1354,13 +1354,13 @@ align 4
mov ecx,[edi+deflate_state.pending] mov ecx,[edi+deflate_state.pending]
add ecx,2 add ecx,2
cmp ecx,[edi+deflate_state.pending_buf_size] cmp ecx,[edi+deflate_state.pending_buf_size]
jle @f ;if (..>..) jbe @f ;if (..>..)
stdcall flush_pending, ebx stdcall flush_pending, ebx
@@: @@:
mov ecx,[edi+deflate_state.pending] mov ecx,[edi+deflate_state.pending]
add ecx,2 add ecx,2
cmp ecx,[edi+deflate_state.pending_buf_size] cmp ecx,[edi+deflate_state.pending_buf_size]
jg .end8 ;if (..<=..) ja .end8 ;if (..<=..)
mov ecx,[ebx+z_stream.adler] mov ecx,[ebx+z_stream.adler]
put_byte edi, cl put_byte edi, cl
put_byte edi, ch put_byte edi, ch
@ -2157,10 +2157,12 @@ pushad
; If the window is almost full and there is insufficient lookahead, ; If the window is almost full and there is insufficient lookahead,
; move the upper half to the lower one to make room in the upper half. ; move the upper half to the lower one to make room in the upper half.
MAX_DIST edi ;;MAX_DIST edi
add eax,ecx ;;add eax,ecx
mov eax,[edi+deflate_state.w_size]
lea eax,[ecx+eax-MIN_LOOKAHEAD]
cmp [edi+deflate_state.strstart],eax cmp [edi+deflate_state.strstart],eax
jl .end0 ;if (..>=..) jb .end0 ;if (..>=..)
push ecx push ecx
mov eax,[edi+deflate_state.window] mov eax,[edi+deflate_state.window]
add eax,ecx add eax,ecx
@ -2285,14 +2287,14 @@ end if
mov eax,[edi+deflate_state.lookahead] mov eax,[edi+deflate_state.lookahead]
add eax,[edi+deflate_state.insert] add eax,[edi+deflate_state.insert]
cmp eax,MIN_MATCH cmp eax,MIN_MATCH
jl .end1 ;if (..<..) break jb .end1 ;if (..<..) break
jmp .cycle3 jmp .cycle3
.end1: .end1:
; If the whole input has less than MIN_MATCH bytes, ins_h is garbage, ; If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
; but this is not important since only literal bytes will be emitted. ; but this is not important since only literal bytes will be emitted.
cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD
jge .cycle0end jae .cycle0end
cmp dword[edx+z_stream.avail_in],0 cmp dword[edx+z_stream.avail_in],0
jne .cycle0 jne .cycle0
align 4 align 4
@ -2307,20 +2309,20 @@ align 4
mov eax,[edi+deflate_state.window_size] mov eax,[edi+deflate_state.window_size]
cmp [edi+deflate_state.high_water],eax cmp [edi+deflate_state.high_water],eax
jge .end2 ;if (..<..) jae .end2 ;if (..<..)
mov esi,[edi+deflate_state.lookahead] mov esi,[edi+deflate_state.lookahead]
add esi,[edi+deflate_state.strstart] add esi,[edi+deflate_state.strstart]
;esi = curr ;esi = curr
cmp [edi+deflate_state.high_water],esi cmp [edi+deflate_state.high_water],esi
jge .end3 ;if (..<..) jae .end3 ;if (..<..)
; Previous high water mark below current data -- zero WIN_INIT ; Previous high water mark below current data -- zero WIN_INIT
; bytes or up to end of window, whichever is less. ; bytes or up to end of window, whichever is less.
mov eax,[edi+deflate_state.window_size] mov eax,[edi+deflate_state.window_size]
sub eax,esi sub eax,esi
cmp eax,WIN_INIT cmp eax,WIN_INIT
jle @f ;if (..>..) jbe @f ;if (..>..)
mov eax,WIN_INIT mov eax,WIN_INIT
@@: @@:
mov edx,[edi+deflate_state.window] mov edx,[edi+deflate_state.window]
@ -2333,7 +2335,7 @@ align 4
mov eax,esi mov eax,esi
add eax,WIN_INIT add eax,WIN_INIT
cmp [edi+deflate_state.high_water],eax cmp [edi+deflate_state.high_water],eax
jge .end2 jae .end2
; High water mark at or above current data, but below current data ; High water mark at or above current data, but below current data
; plus WIN_INIT -- zero out to current data plus WIN_INIT, or up ; plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
; to end of window, whichever is less. ; to end of window, whichever is less.
@ -2343,7 +2345,7 @@ align 4
mov edx,[edi+deflate_state.window_size] mov edx,[edi+deflate_state.window_size]
sub edx,[edi+deflate_state.high_water] sub edx,[edi+deflate_state.high_water]
cmp eax,edx ;if (..>..) cmp eax,edx ;if (..>..)
jle @f jbe @f
mov eax,edx mov eax,edx
@@: @@:
mov edx,[edi+deflate_state.window] mov edx,[edi+deflate_state.window]
@ -2682,10 +2684,10 @@ endl
; string following the next match. ; string following the next match.
cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD
jge .end0 ;if (..<..) jae .end0 ;if (..<..)
stdcall fill_window, edi stdcall fill_window, edi
cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD
jge @f ;if (..<.. && ..==..) jae @f ;if (..<.. && ..==..)
cmp dword[flush],Z_NO_FLUSH cmp dword[flush],Z_NO_FLUSH
jne @f jne @f
mov eax,need_more mov eax,need_more
@ -2702,7 +2704,7 @@ align 4
mov ecx,NIL mov ecx,NIL
cmp dword[edi+deflate_state.lookahead],MIN_MATCH cmp dword[edi+deflate_state.lookahead],MIN_MATCH
jl @f ;if (..>=..) jb @f ;if (..>=..)
INSERT_STRING edi, [edi+deflate_state.strstart], ecx INSERT_STRING edi, [edi+deflate_state.strstart], ecx
@@: @@:
@ -2718,12 +2720,12 @@ align 4
je .end1 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 .end1 jae .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
cmp ebx,eax cmp ebx,eax
jg .end1 ;if (..!=0 && ..<.. && ..<=..) ja .end1 ;if (..!=0 && ..<.. && ..<=..)
; To simplify the code, we prevent matches with the string ; To simplify the code, we prevent matches with the string
; of window index 0 (in particular we have to avoid a match ; of window index 0 (in particular we have to avoid a match
; of the string with itself at the start of the input file). ; of the string with itself at the start of the input file).
@ -2733,7 +2735,7 @@ align 4
; longest_match() sets match_start ; longest_match() sets match_start
cmp dword[edi+deflate_state.match_length],5 cmp dword[edi+deflate_state.match_length],5
jg .end1 ja .end1
cmp word[edi+deflate_state.strategy],Z_FILTERED cmp word[edi+deflate_state.strategy],Z_FILTERED
if TOO_FAR <= 32767 if TOO_FAR <= 32767
je @f je @f
@ -2742,7 +2744,7 @@ if TOO_FAR <= 32767
mov eax,[edi+deflate_state.strstart] mov eax,[edi+deflate_state.strstart]
sub eax,[edi+deflate_state.match_start] sub eax,[edi+deflate_state.match_start]
cmp eax,TOO_FAR cmp eax,TOO_FAR
jle .end1 ;if (..<=.. && (..==.. || (..==.. && ..>..))) jbe .end1 ;if (..<=.. && (..==.. || (..==.. && ..>..)))
@@: @@:
else else
jne .end1 ;if (..<=.. && ..==..) jne .end1 ;if (..<=.. && ..==..)
@ -2758,9 +2760,9 @@ end if
mov eax,[edi+deflate_state.prev_length] mov eax,[edi+deflate_state.prev_length]
cmp eax,MIN_MATCH cmp eax,MIN_MATCH
jl .end2 jb .end2
cmp [edi+deflate_state.match_length],eax cmp [edi+deflate_state.match_length],eax
jg .end2 ;if (..>=.. && ..<=..) ja .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
@ -2790,7 +2792,7 @@ end if
.cycle1: ;do .cycle1: ;do
inc dword[edi+deflate_state.strstart] inc dword[edi+deflate_state.strstart]
cmp [edi+deflate_state.strstart],edx cmp [edi+deflate_state.strstart],edx
jg @f ;if (..<=..) ja @f ;if (..<=..)
INSERT_STRING edi, [edi+deflate_state.strstart], ecx INSERT_STRING edi, [edi+deflate_state.strstart], ecx
@@: @@:
dec dword[edi+deflate_state.prev_length] dec dword[edi+deflate_state.prev_length]
@ -2856,7 +2858,7 @@ align 4
@@: @@:
mov eax,[edi+deflate_state.strstart] mov eax,[edi+deflate_state.strstart]
cmp eax,MIN_MATCH-1 cmp eax,MIN_MATCH-1
jl @f jb @f
mov eax,MIN_MATCH-1 mov eax,MIN_MATCH-1
@@: @@:
mov [edi+deflate_state.insert],eax mov [edi+deflate_state.insert],eax

View File

@ -277,7 +277,7 @@ macro d_code dist
local .end0 local .end0
mov eax,dist mov eax,dist
cmp eax,256 cmp eax,256
jl .end0 ja .end0
shr eax,7 shr eax,7
add eax,256 add eax,256
.end0: .end0:
@ -289,7 +289,6 @@ local .end0
macro _tr_tally_lit s, c, flush macro _tr_tally_lit s, c, flush
{ {
local .end0
if DEBUG eq 0 if DEBUG eq 0
; Inline versions of _tr_tally for speed: ; Inline versions of _tr_tally for speed:
if c eq eax if c eq eax
@ -306,15 +305,12 @@ end if
mov byte[ecx],al mov byte[ecx],al
inc dword[s+deflate_state.last_lit] inc dword[s+deflate_state.last_lit]
and eax,0xff and eax,0xff
imul eax,sizeof.ct_data inc word[s+sizeof.ct_data*eax+deflate_state.dyn_ltree+Freq]
inc word[s+eax+deflate_state.dyn_ltree+Freq]
xor eax,eax xor eax,eax
mov ecx,[s+deflate_state.lit_bufsize] mov ecx,[s+deflate_state.lit_bufsize]
dec ecx dec ecx
cmp [s+deflate_state.last_lit],ecx cmp [s+deflate_state.last_lit],ecx
jne .end0 sete al ;flush = (..==..)
inc eax ;flush = (..==..)
.end0:
mov flush, eax mov flush, eax
pop ecx pop ecx
else else
@ -324,25 +320,54 @@ end if
} }
macro _tr_tally_dist s, distance, length, flush macro _tr_tally_dist s, distance, length, flush
{ {
if 0 ;;;DEBUG eq 0 if DEBUG eq 0
push ecx push ecx
; uch len = (length)
;s.d_buf[s.last_lit] = dist
mov ecx,[s+deflate_state.last_lit]
shl ecx,1
add ecx,[s+deflate_state.d_buf]
if distance eq eax
mov [ecx],ax
else
mov word[ecx],distance
end if
;s.l_buf[s.last_lit++] = len
mov ecx,[s+deflate_state.last_lit]
add ecx,[s+deflate_state.l_buf]
if length eq eax
mov [ecx],al
else if length eq ebx
mov [ecx],bl
else
... ;mov byte[ecx],length
end if
inc dword[s+deflate_state.last_lit]
;dist--
if distance eq eax if distance eq eax
else else
mov eax,distance mov eax,distance
end if end if
mov ecx,[s+deflate_state.last_lit]
shl ecx,1
add ecx,[s+deflate_state.d_buf]
mov word[ecx],ax
mov ecx,[s+deflate_state.last_lit]
add ecx,[s+deflate_state.l_buf]
mov byte[ecx],length
inc dword[s+deflate_state.last_lit]
dec eax dec eax
; s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++;
; s->dyn_dtree[d_code(dist)].Freq++; ;s.dyn_ltree[_length_code[len]+LITERALS+1].Freq++
; flush = (s->last_lit == s->lit_bufsize-1); movzx ecx,byte[ecx]
movzx ecx,byte[ecx+_length_code]
inc word[s+sizeof.ct_data*ecx+deflate_state.dyn_ltree+sizeof.ct_data*(LITERALS+1)+Freq]
;s.dyn_dtree[d_code(dist)].Freq++
d_code eax
inc word[s+sizeof.ct_data*eax+deflate_state.dyn_dtree+Freq]
;flush = (s.last_lit == s.lit_bufsize-1)
mov ecx,[s+deflate_state.lit_bufsize]
dec ecx
xor eax,eax
cmp [s+deflate_state.last_lit],ecx
sete al
mov flush,eax
pop ecx pop ecx
else else
stdcall _tr_tally, s, distance, length stdcall _tr_tally, s, distance, length

View File

@ -201,7 +201,7 @@ proc send_bits uses eax ecx edi, s:dword, value:dword, length:dword
mov eax,[value] mov eax,[value]
mov ecx,Buf_size mov ecx,Buf_size
sub ecx,[edi+deflate_state.bi_valid] sub ecx,[edi+deflate_state.bi_valid]
shr eax,cl sar eax,cl
mov [edi+deflate_state.bi_buf],ax mov [edi+deflate_state.bi_buf],ax
mov eax,[length] mov eax,[length]
sub eax,Buf_size sub eax,Buf_size
@ -1408,12 +1408,8 @@ proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, b
cmp ecx,[blcodes] cmp ecx,[blcodes]
jge .cycle0end ;for (..;..<..;..) jge .cycle0end ;for (..;..<..;..)
; Tracev((stderr, "\nbl code %2d ", bl_order[ecx])); ; Tracev((stderr, "\nbl code %2d ", bl_order[ecx]));
mov eax,ecx movzx eax,byte[ecx+bl_order]
add eax,bl_order movzx eax,word[edi+sizeof.ct_data*eax+deflate_state.bl_tree+Len]
movzx eax,byte[eax]
imul eax,sizeof.ct_data
add eax,edi
movzx eax,word[eax+deflate_state.bl_tree+Len]
stdcall send_bits, edi, eax, 3 stdcall send_bits, edi, eax, 3
inc ecx inc ecx
jmp .cycle0 jmp .cycle0
@ -1556,7 +1552,7 @@ endl
; s->last_lit)); ; s->last_lit));
cmp eax,[opt_lenb] cmp eax,[opt_lenb]
jg .end1 ;if (..<=..) ja .end1 ;if (..<=..)
mov [opt_lenb],eax mov [opt_lenb],eax
jmp .end1 jmp .end1
.end0: ;else .end0: ;else
@ -1577,7 +1573,7 @@ else
mov eax,[stored_len] mov eax,[stored_len]
add eax,4 add eax,4
cmp eax,[opt_lenb] cmp eax,[opt_lenb]
jg .end2 ja .end2
cmp dword[buf],0 cmp dword[buf],0
je .end2 ;if (..<=.. && ..!=0) je .end2 ;if (..<=.. && ..!=0)
;4: two words for the lengths ;4: two words for the lengths
@ -1666,7 +1662,6 @@ endp
align 4 align 4
proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword
mov edi,[s] mov edi,[s]
zlib_debug '_tr_tally'
mov eax,[edi+deflate_state.last_lit] mov eax,[edi+deflate_state.last_lit]
shl eax,1 shl eax,1
add eax,[edi+deflate_state.d_buf] add eax,[edi+deflate_state.d_buf]
@ -1681,9 +1676,7 @@ proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword
jne @f ;if (..==0) jne @f ;if (..==0)
; lc is the unmatched char ; lc is the unmatched char
mov eax,[lc] mov eax,[lc]
imul eax,sizeof.ct_data inc word[edi+sizeof.ct_data*eax+deflate_state.dyn_ltree+Freq]
add eax,edi
inc word[eax+deflate_state.dyn_ltree+Freq]
jmp .end0 jmp .end0
align 4 align 4
@@: ;else @@: ;else
@ -1703,12 +1696,9 @@ align 4
.end2: .end2:
mov eax,[lc] mov eax,[lc]
movzx eax,byte[eax+_length_code] movzx eax,byte[eax+_length_code]
add eax,LITERALS+1 inc word[edi+sizeof.ct_data*eax+deflate_state.dyn_ltree+sizeof.ct_data*(LITERALS+1)+Freq]
imul eax,sizeof.ct_data
inc word[edi+eax+deflate_state.dyn_ltree+Freq]
d_code [dist] d_code [dist]
imul eax,sizeof.ct_data inc word[edi+sizeof.ct_data*eax+deflate_state.dyn_dtree+Freq]
inc word[edi+eax+deflate_state.dyn_dtree+Freq]
.end0: .end0:
if TRUNCATE_BLOCK eq 1 if TRUNCATE_BLOCK eq 1
@ -1733,14 +1723,12 @@ if TRUNCATE_BLOCK eq 1
; if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; ; if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
.end1: .end1:
end if end if
mov ebx,[edi+deflate_state.last_lit] mov ebx,[edi+deflate_state.lit_bufsize]
mov edi,[edi+deflate_state.lit_bufsize] dec ebx
dec edi
xor eax,eax xor eax,eax
cmp ebx,edi cmp [edi+deflate_state.last_lit],ebx
jne @f sete al ;return (..==..)
inc eax ;return (..==..)
@@:
; We avoid equality with lit_bufsize because of wraparound at 64K ; We avoid equality with lit_bufsize because of wraparound at 64K
; on 16 bit machines and because stored blocks are restricted to ; on 16 bit machines and because stored blocks are restricted to
; 64K-1 bytes. ; 64K-1 bytes.
@ -1828,7 +1816,7 @@ endl
@@: @@:
mov eax,[edi+deflate_state.last_lit] mov eax,[edi+deflate_state.last_lit]
cmp [lx],eax cmp [lx],eax
jl .cycle0 ;while (..<..) jb .cycle0 ;while (..<..)
align 4 align 4
.end0: .end0:
@ -1849,8 +1837,7 @@ endp
; (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). ; (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
; IN assertion: the fields Freq of dyn_ltree are set. ; IN assertion: the fields Freq of dyn_ltree are set.
;int (s) ;int (deflate_state* s)
; deflate_state* s
align 4 align 4
proc detect_data_type uses ebx ecx edi, s:dword proc detect_data_type uses ebx ecx edi, s:dword
; black_mask is the bit mask of black-listed bytes ; black_mask is the bit mask of black-listed bytes
@ -1860,7 +1847,6 @@ locals
black_mask dd 0xf3ffc07f black_mask dd 0xf3ffc07f
endl endl
mov edi,[s] mov edi,[s]
zlib_debug 'detect_data_type'
; Check for non-textual ("black-listed") bytes. ; Check for non-textual ("black-listed") bytes.
xor ecx,ecx xor ecx,ecx
@ -1948,8 +1934,7 @@ endp
; =========================================================================== ; ===========================================================================
; Flush the bit buffer, keeping at most 7 bits in it. ; Flush the bit buffer, keeping at most 7 bits in it.
;void (s) ;void (deflate_state* s)
; deflate_state* s
align 4 align 4
proc bi_flush uses eax ecx edi, s:dword proc bi_flush uses eax ecx edi, s:dword
mov edi,[s] mov edi,[s]
@ -2030,6 +2015,8 @@ if DEBUG eq 1
add [edi+deflate_state.bits_sent],ecx add [edi+deflate_state.bits_sent],ecx
end if end if
mov ecx,[len] mov ecx,[len]
; test ecx,ecx
; jz .end_f
mov esi,[buf] mov esi,[buf]
jmp .end0 jmp .end0
align 4 align 4
@ -2039,5 +2026,6 @@ align 4
put_byte edi, bl put_byte edi, bl
.end0: .end0:
loop @b loop @b
; .end_f:
ret ret
endp endp

View File

@ -107,8 +107,7 @@ end if
ret ret
endp endp
;void (m) ;void (char *m)
; char *m
align 4 align 4
proc z_error, m:dword proc z_error, m:dword
; fprintf(stderr, "%s\n", m); ; fprintf(stderr, "%s\n", m);
@ -119,8 +118,7 @@ endp
; exported to allow conversion of error code to string for compress() and ; exported to allow conversion of error code to string for compress() and
; uncompress() ; uncompress()
;const char * (err) ;const char * (int err)
; int err
align 4 align 4
proc zError uses ecx, err:dword proc zError uses ecx, err:dword
ERR_MSG [err] ERR_MSG [err]
@ -173,15 +171,28 @@ proc zmemcmp, s1:dword, s2:dword, len:dword
ret ret
endp endp
;void (dest, len) ;void (Bytef* dest, uInt len)
; Bytef* dest
; uInt len
align 4 align 4
proc zmemzero, dest:dword, len:dword proc zmemzero uses eax ecx edi, dest:dword, len:dword
; if (len == 0) return; mov ecx,[len]
; do { test ecx,ecx
; *dest++ = 0; /* ??? to be unrolled */ jz .end0
; } while (--len != 0); xor eax,eax
mov edi,[dest]
bt ecx,0 ;кратно 2 ?
jnc @f
rep stosb
jmp .end0
@@:
bt ecx,1 ;кратно 4 ?
jnc @f
shr ecx,1
rep stosw
jmp .end0
@@:
shr ecx,2
rep stosd
.end0:
ret ret
endp endp
;end if ;end if