kusano 7d535a
;/* inffas32.asm is a hand tuned assembler version of inffast.c -- fast decoding
kusano 7d535a
; *
kusano 7d535a
; * inffas32.asm is derivated from inffas86.c, with translation of assembly code
kusano 7d535a
; *
kusano 7d535a
; * Copyright (C) 1995-2003 Mark Adler
kusano 7d535a
; * For conditions of distribution and use, see copyright notice in zlib.h
kusano 7d535a
; *
kusano 7d535a
; * Copyright (C) 2003 Chris Anderson <christop@charm.net></christop@charm.net>
kusano 7d535a
; * Please use the copyright conditions above.
kusano 7d535a
; *
kusano 7d535a
; * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
kusano 7d535a
; * the gcc -S output of zlib-1.2.0/inffast.c.  Zlib-1.2.0 is in beta release at
kusano 7d535a
; * the moment.  I have successfully compiled and tested this code with gcc2.96,
kusano 7d535a
; * gcc3.2, icc5.0, msvc6.0.  It is very close to the speed of inffast.S
kusano 7d535a
; * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
kusano 7d535a
; * enabled.  I will attempt to merge the MMX code into this version.  Newer
kusano 7d535a
; * versions of this and inffast.S can be found at
kusano 7d535a
; * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
kusano 7d535a
; *
kusano 7d535a
; * 2005 : modification by Gilles Vollant
kusano 7d535a
; */
kusano 7d535a
; For Visual C++ 4.x and higher and ML 6.x and higher
kusano 7d535a
;   ml.exe is in directory \MASM611C of Win95 DDK
kusano 7d535a
;   ml.exe is also distributed in http://www.masm32.com/masmdl.htm
kusano 7d535a
;    and in VC++2003 toolkit at http://msdn.microsoft.com/visualc/vctoolkit2003/
kusano 7d535a
;
kusano 7d535a
;
kusano 7d535a
;   compile with command line option
kusano 7d535a
;   ml  /coff /Zi /c /Flinffas32.lst inffas32.asm
kusano 7d535a
kusano 7d535a
;   if you define NO_GZIP (see inflate.h), compile with
kusano 7d535a
;   ml  /coff /Zi /c /Flinffas32.lst /DNO_GUNZIP inffas32.asm
kusano 7d535a
kusano 7d535a
kusano 7d535a
; zlib122sup is 0 fort zlib 1.2.2.1 and lower
kusano 7d535a
; zlib122sup is 8 fort zlib 1.2.2.2 and more (with addition of dmax and head
kusano 7d535a
;        in inflate_state in inflate.h)
kusano 7d535a
zlib1222sup      equ    8
kusano 7d535a
kusano 7d535a
kusano 7d535a
IFDEF GUNZIP
kusano 7d535a
  INFLATE_MODE_TYPE    equ 11
kusano 7d535a
  INFLATE_MODE_BAD     equ 26
kusano 7d535a
ELSE
kusano 7d535a
  IFNDEF NO_GUNZIP
kusano 7d535a
    INFLATE_MODE_TYPE    equ 11
kusano 7d535a
    INFLATE_MODE_BAD     equ 26
kusano 7d535a
  ELSE
kusano 7d535a
    INFLATE_MODE_TYPE    equ 3
kusano 7d535a
    INFLATE_MODE_BAD     equ 17
kusano 7d535a
  ENDIF
kusano 7d535a
ENDIF
kusano 7d535a
kusano 7d535a
kusano 7d535a
; 75 "inffast.S"
kusano 7d535a
;FILE "inffast.S"
kusano 7d535a
kusano 7d535a
;;;GLOBAL _inflate_fast
kusano 7d535a
kusano 7d535a
;;;SECTION .text
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	.586p
kusano 7d535a
	.mmx
kusano 7d535a
kusano 7d535a
	name	inflate_fast_x86
kusano 7d535a
	.MODEL	FLAT
kusano 7d535a
kusano 7d535a
_DATA			segment
kusano 7d535a
inflate_fast_use_mmx:
kusano 7d535a
	dd	1
kusano 7d535a
kusano 7d535a
kusano 7d535a
_TEXT			segment
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
	db	'Fast decoding Code from Chris Anderson'
kusano 7d535a
	db	0
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
invalid_literal_length_code_msg:
kusano 7d535a
	db	'invalid literal/length code'
kusano 7d535a
	db	0
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
invalid_distance_code_msg:
kusano 7d535a
	db	'invalid distance code'
kusano 7d535a
	db	0
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
invalid_distance_too_far_msg:
kusano 7d535a
	db	'invalid distance too far back'
kusano 7d535a
	db	0
kusano 7d535a
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
inflate_fast_mask:
kusano 7d535a
dd	0
kusano 7d535a
dd	1
kusano 7d535a
dd	3
kusano 7d535a
dd	7
kusano 7d535a
dd	15
kusano 7d535a
dd	31
kusano 7d535a
dd	63
kusano 7d535a
dd	127
kusano 7d535a
dd	255
kusano 7d535a
dd	511
kusano 7d535a
dd	1023
kusano 7d535a
dd	2047
kusano 7d535a
dd	4095
kusano 7d535a
dd	8191
kusano 7d535a
dd	16383
kusano 7d535a
dd	32767
kusano 7d535a
dd	65535
kusano 7d535a
dd	131071
kusano 7d535a
dd	262143
kusano 7d535a
dd	524287
kusano 7d535a
dd	1048575
kusano 7d535a
dd	2097151
kusano 7d535a
dd	4194303
kusano 7d535a
dd	8388607
kusano 7d535a
dd	16777215
kusano 7d535a
dd	33554431
kusano 7d535a
dd	67108863
kusano 7d535a
dd	134217727
kusano 7d535a
dd	268435455
kusano 7d535a
dd	536870911
kusano 7d535a
dd	1073741823
kusano 7d535a
dd	2147483647
kusano 7d535a
dd	4294967295
kusano 7d535a
kusano 7d535a
kusano 7d535a
mode_state	 equ	0	;/* state->mode	*/
kusano 7d535a
wsize_state	 equ	(32+zlib1222sup)	;/* state->wsize */
kusano 7d535a
write_state	 equ	(36+4+zlib1222sup)	;/* state->write */
kusano 7d535a
window_state	 equ	(40+4+zlib1222sup)	;/* state->window */
kusano 7d535a
hold_state	 equ	(44+4+zlib1222sup)	;/* state->hold	*/
kusano 7d535a
bits_state	 equ	(48+4+zlib1222sup)	;/* state->bits	*/
kusano 7d535a
lencode_state	 equ	(64+4+zlib1222sup)	;/* state->lencode */
kusano 7d535a
distcode_state	 equ	(68+4+zlib1222sup)	;/* state->distcode */
kusano 7d535a
lenbits_state	 equ	(72+4+zlib1222sup)	;/* state->lenbits */
kusano 7d535a
distbits_state	 equ	(76+4+zlib1222sup)	;/* state->distbits */
kusano 7d535a
kusano 7d535a
kusano 7d535a
;;SECTION .text
kusano 7d535a
; 205 "inffast.S"
kusano 7d535a
;GLOBAL	inflate_fast_use_mmx
kusano 7d535a
kusano 7d535a
;SECTION .data
kusano 7d535a
kusano 7d535a
kusano 7d535a
; GLOBAL inflate_fast_use_mmx:object
kusano 7d535a
;.size inflate_fast_use_mmx, 4
kusano 7d535a
; 226 "inffast.S"
kusano 7d535a
;SECTION .text
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
_inflate_fast proc near
kusano 7d535a
.FPO (16, 4, 0, 0, 1, 0)
kusano 7d535a
	push  edi
kusano 7d535a
	push  esi
kusano 7d535a
	push  ebp
kusano 7d535a
	push  ebx
kusano 7d535a
	pushfd
kusano 7d535a
	sub  esp,64
kusano 7d535a
	cld
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  esi, [esp+88]
kusano 7d535a
	mov  edi, [esi+28]
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  edx, [esi+4]
kusano 7d535a
	mov  eax, [esi+0]
kusano 7d535a
kusano 7d535a
	add  edx,eax
kusano 7d535a
	sub  edx,11
kusano 7d535a
kusano 7d535a
	mov  [esp+44],eax
kusano 7d535a
	mov  [esp+20],edx
kusano 7d535a
kusano 7d535a
	mov  ebp, [esp+92]
kusano 7d535a
	mov  ecx, [esi+16]
kusano 7d535a
	mov  ebx, [esi+12]
kusano 7d535a
kusano 7d535a
	sub  ebp,ecx
kusano 7d535a
	neg  ebp
kusano 7d535a
	add  ebp,ebx
kusano 7d535a
kusano 7d535a
	sub  ecx,257
kusano 7d535a
	add  ecx,ebx
kusano 7d535a
kusano 7d535a
	mov  [esp+60],ebx
kusano 7d535a
	mov  [esp+40],ebp
kusano 7d535a
	mov  [esp+16],ecx
kusano 7d535a
; 285 "inffast.S"
kusano 7d535a
	mov  eax, [edi+lencode_state]
kusano 7d535a
	mov  ecx, [edi+distcode_state]
kusano 7d535a
kusano 7d535a
	mov  [esp+8],eax
kusano 7d535a
	mov  [esp+12],ecx
kusano 7d535a
kusano 7d535a
	mov  eax,1
kusano 7d535a
	mov  ecx, [edi+lenbits_state]
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	dec  eax
kusano 7d535a
	mov  [esp+0],eax
kusano 7d535a
kusano 7d535a
	mov  eax,1
kusano 7d535a
	mov  ecx, [edi+distbits_state]
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	dec  eax
kusano 7d535a
	mov  [esp+4],eax
kusano 7d535a
kusano 7d535a
	mov  eax, [edi+wsize_state]
kusano 7d535a
	mov  ecx, [edi+write_state]
kusano 7d535a
	mov  edx, [edi+window_state]
kusano 7d535a
kusano 7d535a
	mov  [esp+52],eax
kusano 7d535a
	mov  [esp+48],ecx
kusano 7d535a
	mov  [esp+56],edx
kusano 7d535a
kusano 7d535a
	mov  ebp, [edi+hold_state]
kusano 7d535a
	mov  ebx, [edi+bits_state]
kusano 7d535a
; 321 "inffast.S"
kusano 7d535a
	mov  esi, [esp+44]
kusano 7d535a
	mov  ecx, [esp+20]
kusano 7d535a
	cmp  ecx,esi
kusano 7d535a
	ja   L_align_long
kusano 7d535a
kusano 7d535a
	add  ecx,11
kusano 7d535a
	sub  ecx,esi
kusano 7d535a
	mov  eax,12
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	lea  edi, [esp+28]
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  ecx,eax
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	rep stosb
kusano 7d535a
	lea  esi, [esp+28]
kusano 7d535a
	mov  [esp+20],esi
kusano 7d535a
	jmp  L_is_aligned
kusano 7d535a
kusano 7d535a
kusano 7d535a
L_align_long:
kusano 7d535a
	test  esi,3
kusano 7d535a
	jz   L_is_aligned
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	mov  al, [esi]
kusano 7d535a
	inc  esi
kusano 7d535a
	mov  ecx,ebx
kusano 7d535a
	add  ebx,8
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	or  ebp,eax
kusano 7d535a
	jmp L_align_long
kusano 7d535a
kusano 7d535a
L_is_aligned:
kusano 7d535a
	mov  edi, [esp+60]
kusano 7d535a
; 366 "inffast.S"
kusano 7d535a
L_check_mmx:
kusano 7d535a
	cmp  dword ptr [inflate_fast_use_mmx],2
kusano 7d535a
	je   L_init_mmx
kusano 7d535a
	ja   L_do_loop
kusano 7d535a
kusano 7d535a
	push  eax
kusano 7d535a
	push  ebx
kusano 7d535a
	push  ecx
kusano 7d535a
	push  edx
kusano 7d535a
	pushfd
kusano 7d535a
	mov  eax, [esp]
kusano 7d535a
	xor  dword ptr [esp],0200000h
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	popfd
kusano 7d535a
	pushfd
kusano 7d535a
	pop  edx
kusano 7d535a
	xor  edx,eax
kusano 7d535a
	jz   L_dont_use_mmx
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	cpuid
kusano 7d535a
	cmp  ebx,0756e6547h
kusano 7d535a
	jne  L_dont_use_mmx
kusano 7d535a
	cmp  ecx,06c65746eh
kusano 7d535a
	jne  L_dont_use_mmx
kusano 7d535a
	cmp  edx,049656e69h
kusano 7d535a
	jne  L_dont_use_mmx
kusano 7d535a
	mov  eax,1
kusano 7d535a
	cpuid
kusano 7d535a
	shr  eax,8
kusano 7d535a
	and  eax,15
kusano 7d535a
	cmp  eax,6
kusano 7d535a
	jne  L_dont_use_mmx
kusano 7d535a
	test  edx,0800000h
kusano 7d535a
	jnz  L_use_mmx
kusano 7d535a
	jmp  L_dont_use_mmx
kusano 7d535a
L_use_mmx:
kusano 7d535a
	mov  dword ptr [inflate_fast_use_mmx],2
kusano 7d535a
	jmp  L_check_mmx_pop
kusano 7d535a
L_dont_use_mmx:
kusano 7d535a
	mov  dword ptr [inflate_fast_use_mmx],3
kusano 7d535a
L_check_mmx_pop:
kusano 7d535a
	pop  edx
kusano 7d535a
	pop  ecx
kusano 7d535a
	pop  ebx
kusano 7d535a
	pop  eax
kusano 7d535a
	jmp  L_check_mmx
kusano 7d535a
; 426 "inffast.S"
kusano 7d535a
ALIGN 4
kusano 7d535a
L_do_loop:
kusano 7d535a
; 437 "inffast.S"
kusano 7d535a
	cmp  bl,15
kusano 7d535a
	ja   L_get_length_code
kusano 7d535a
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	lodsw
kusano 7d535a
	mov  cl,bl
kusano 7d535a
	add  bl,16
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	or  ebp,eax
kusano 7d535a
kusano 7d535a
L_get_length_code:
kusano 7d535a
	mov  edx, [esp+0]
kusano 7d535a
	mov  ecx, [esp+8]
kusano 7d535a
	and  edx,ebp
kusano 7d535a
	mov  eax, [ecx+edx*4]
kusano 7d535a
kusano 7d535a
L_dolen:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  cl,ah
kusano 7d535a
	sub  bl,ah
kusano 7d535a
	shr  ebp,cl
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	test  al,al
kusano 7d535a
	jnz   L_test_for_length_base
kusano 7d535a
kusano 7d535a
	shr  eax,16
kusano 7d535a
	stosb
kusano 7d535a
kusano 7d535a
L_while_test:
kusano 7d535a
kusano 7d535a
kusano 7d535a
	cmp  [esp+16],edi
kusano 7d535a
	jbe  L_break_loop
kusano 7d535a
kusano 7d535a
	cmp  [esp+20],esi
kusano 7d535a
	ja   L_do_loop
kusano 7d535a
	jmp  L_break_loop
kusano 7d535a
kusano 7d535a
L_test_for_length_base:
kusano 7d535a
; 502 "inffast.S"
kusano 7d535a
	mov  edx,eax
kusano 7d535a
	shr  edx,16
kusano 7d535a
	mov  cl,al
kusano 7d535a
kusano 7d535a
	test  al,16
kusano 7d535a
	jz   L_test_for_second_level_length
kusano 7d535a
	and  cl,15
kusano 7d535a
	jz   L_save_len
kusano 7d535a
	cmp  bl,cl
kusano 7d535a
	jae  L_add_bits_to_len
kusano 7d535a
kusano 7d535a
	mov  ch,cl
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	lodsw
kusano 7d535a
	mov  cl,bl
kusano 7d535a
	add  bl,16
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	or  ebp,eax
kusano 7d535a
	mov  cl,ch
kusano 7d535a
kusano 7d535a
L_add_bits_to_len:
kusano 7d535a
	mov  eax,1
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	dec  eax
kusano 7d535a
	sub  bl,cl
kusano 7d535a
	and  eax,ebp
kusano 7d535a
	shr  ebp,cl
kusano 7d535a
	add  edx,eax
kusano 7d535a
kusano 7d535a
L_save_len:
kusano 7d535a
	mov  [esp+24],edx
kusano 7d535a
kusano 7d535a
kusano 7d535a
L_decode_distance:
kusano 7d535a
; 549 "inffast.S"
kusano 7d535a
	cmp  bl,15
kusano 7d535a
	ja   L_get_distance_code
kusano 7d535a
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	lodsw
kusano 7d535a
	mov  cl,bl
kusano 7d535a
	add  bl,16
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	or  ebp,eax
kusano 7d535a
kusano 7d535a
L_get_distance_code:
kusano 7d535a
	mov  edx, [esp+4]
kusano 7d535a
	mov  ecx, [esp+12]
kusano 7d535a
	and  edx,ebp
kusano 7d535a
	mov  eax, [ecx+edx*4]
kusano 7d535a
kusano 7d535a
kusano 7d535a
L_dodist:
kusano 7d535a
	mov  edx,eax
kusano 7d535a
	shr  edx,16
kusano 7d535a
	mov  cl,ah
kusano 7d535a
	sub  bl,ah
kusano 7d535a
	shr  ebp,cl
kusano 7d535a
; 584 "inffast.S"
kusano 7d535a
	mov  cl,al
kusano 7d535a
kusano 7d535a
	test  al,16
kusano 7d535a
	jz  L_test_for_second_level_dist
kusano 7d535a
	and  cl,15
kusano 7d535a
	jz  L_check_dist_one
kusano 7d535a
	cmp  bl,cl
kusano 7d535a
	jae  L_add_bits_to_dist
kusano 7d535a
kusano 7d535a
	mov  ch,cl
kusano 7d535a
	xor  eax,eax
kusano 7d535a
	lodsw
kusano 7d535a
	mov  cl,bl
kusano 7d535a
	add  bl,16
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	or  ebp,eax
kusano 7d535a
	mov  cl,ch
kusano 7d535a
kusano 7d535a
L_add_bits_to_dist:
kusano 7d535a
	mov  eax,1
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	dec  eax
kusano 7d535a
	sub  bl,cl
kusano 7d535a
	and  eax,ebp
kusano 7d535a
	shr  ebp,cl
kusano 7d535a
	add  edx,eax
kusano 7d535a
	jmp  L_check_window
kusano 7d535a
kusano 7d535a
L_check_window:
kusano 7d535a
; 625 "inffast.S"
kusano 7d535a
	mov  [esp+44],esi
kusano 7d535a
	mov  eax,edi
kusano 7d535a
	sub  eax, [esp+40]
kusano 7d535a
kusano 7d535a
	cmp  eax,edx
kusano 7d535a
	jb   L_clip_window
kusano 7d535a
kusano 7d535a
	mov  ecx, [esp+24]
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,edx
kusano 7d535a
kusano 7d535a
	sub  ecx,3
kusano 7d535a
	mov  al, [esi]
kusano 7d535a
	mov  [edi],al
kusano 7d535a
	mov  al, [esi+1]
kusano 7d535a
	mov  dl, [esi+2]
kusano 7d535a
	add  esi,3
kusano 7d535a
	mov  [edi+1],al
kusano 7d535a
	mov  [edi+2],dl
kusano 7d535a
	add  edi,3
kusano 7d535a
	rep movsb
kusano 7d535a
kusano 7d535a
	mov  esi, [esp+44]
kusano 7d535a
	jmp  L_while_test
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_check_dist_one:
kusano 7d535a
	cmp  edx,1
kusano 7d535a
	jne  L_check_window
kusano 7d535a
	cmp  [esp+40],edi
kusano 7d535a
	je  L_check_window
kusano 7d535a
kusano 7d535a
	dec  edi
kusano 7d535a
	mov  ecx, [esp+24]
kusano 7d535a
	mov  al, [edi]
kusano 7d535a
	sub  ecx,3
kusano 7d535a
kusano 7d535a
	mov  [edi+1],al
kusano 7d535a
	mov  [edi+2],al
kusano 7d535a
	mov  [edi+3],al
kusano 7d535a
	add  edi,4
kusano 7d535a
	rep stosb
kusano 7d535a
kusano 7d535a
	jmp  L_while_test
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_test_for_second_level_length:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	test  al,64
kusano 7d535a
	jnz   L_test_for_end_of_block
kusano 7d535a
kusano 7d535a
	mov  eax,1
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	dec  eax
kusano 7d535a
	and  eax,ebp
kusano 7d535a
	add  eax,edx
kusano 7d535a
	mov  edx, [esp+8]
kusano 7d535a
	mov  eax, [edx+eax*4]
kusano 7d535a
	jmp  L_dolen
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_test_for_second_level_dist:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	test  al,64
kusano 7d535a
	jnz   L_invalid_distance_code
kusano 7d535a
kusano 7d535a
	mov  eax,1
kusano 7d535a
	shl  eax,cl
kusano 7d535a
	dec  eax
kusano 7d535a
	and  eax,ebp
kusano 7d535a
	add  eax,edx
kusano 7d535a
	mov  edx, [esp+12]
kusano 7d535a
	mov  eax, [edx+eax*4]
kusano 7d535a
	jmp  L_dodist
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_clip_window:
kusano 7d535a
; 721 "inffast.S"
kusano 7d535a
	mov  ecx,eax
kusano 7d535a
	mov  eax, [esp+52]
kusano 7d535a
	neg  ecx
kusano 7d535a
	mov  esi, [esp+56]
kusano 7d535a
kusano 7d535a
	cmp  eax,edx
kusano 7d535a
	jb   L_invalid_distance_too_far
kusano 7d535a
kusano 7d535a
	add  ecx,edx
kusano 7d535a
	cmp  dword ptr [esp+48],0
kusano 7d535a
	jne  L_wrap_around_window
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	add  esi,eax
kusano 7d535a
; 749 "inffast.S"
kusano 7d535a
	mov  eax, [esp+24]
kusano 7d535a
	cmp  eax,ecx
kusano 7d535a
	jbe  L_do_copy1
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,edx
kusano 7d535a
	jmp  L_do_copy1
kusano 7d535a
kusano 7d535a
	cmp  eax,ecx
kusano 7d535a
	jbe  L_do_copy1
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,edx
kusano 7d535a
	jmp  L_do_copy1
kusano 7d535a
kusano 7d535a
L_wrap_around_window:
kusano 7d535a
; 793 "inffast.S"
kusano 7d535a
	mov  eax, [esp+48]
kusano 7d535a
	cmp  ecx,eax
kusano 7d535a
	jbe  L_contiguous_in_window
kusano 7d535a
kusano 7d535a
	add  esi, [esp+52]
kusano 7d535a
	add  esi,eax
kusano 7d535a
	sub  esi,ecx
kusano 7d535a
	sub  ecx,eax
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  eax, [esp+24]
kusano 7d535a
	cmp  eax,ecx
kusano 7d535a
	jbe  L_do_copy1
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi, [esp+56]
kusano 7d535a
	mov  ecx, [esp+48]
kusano 7d535a
	cmp  eax,ecx
kusano 7d535a
	jbe  L_do_copy1
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,edx
kusano 7d535a
	jmp  L_do_copy1
kusano 7d535a
kusano 7d535a
L_contiguous_in_window:
kusano 7d535a
; 836 "inffast.S"
kusano 7d535a
	add  esi,eax
kusano 7d535a
	sub  esi,ecx
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  eax, [esp+24]
kusano 7d535a
	cmp  eax,ecx
kusano 7d535a
	jbe  L_do_copy1
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,edx
kusano 7d535a
kusano 7d535a
L_do_copy1:
kusano 7d535a
; 862 "inffast.S"
kusano 7d535a
	mov  ecx,eax
kusano 7d535a
	rep movsb
kusano 7d535a
kusano 7d535a
	mov  esi, [esp+44]
kusano 7d535a
	jmp  L_while_test
kusano 7d535a
; 878 "inffast.S"
kusano 7d535a
ALIGN 4
kusano 7d535a
L_init_mmx:
kusano 7d535a
	emms
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	movd mm0,ebp
kusano 7d535a
	mov  ebp,ebx
kusano 7d535a
; 896 "inffast.S"
kusano 7d535a
	movd mm4,dword ptr [esp+0]
kusano 7d535a
	movq mm3,mm4
kusano 7d535a
	movd mm5,dword ptr [esp+4]
kusano 7d535a
	movq mm2,mm5
kusano 7d535a
	pxor mm1,mm1
kusano 7d535a
	mov  ebx, [esp+8]
kusano 7d535a
	jmp  L_do_loop_mmx
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_do_loop_mmx:
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
kusano 7d535a
	cmp  ebp,32
kusano 7d535a
	ja  L_get_length_code_mmx
kusano 7d535a
kusano 7d535a
	movd mm6,ebp
kusano 7d535a
	movd mm7,dword ptr [esi]
kusano 7d535a
	add  esi,4
kusano 7d535a
	psllq mm7,mm6
kusano 7d535a
	add  ebp,32
kusano 7d535a
	por mm0,mm7
kusano 7d535a
kusano 7d535a
L_get_length_code_mmx:
kusano 7d535a
	pand mm4,mm0
kusano 7d535a
	movd eax,mm4
kusano 7d535a
	movq mm4,mm3
kusano 7d535a
	mov  eax, [ebx+eax*4]
kusano 7d535a
kusano 7d535a
L_dolen_mmx:
kusano 7d535a
	movzx  ecx,ah
kusano 7d535a
	movd mm1,ecx
kusano 7d535a
	sub  ebp,ecx
kusano 7d535a
kusano 7d535a
	test  al,al
kusano 7d535a
	jnz L_test_for_length_base_mmx
kusano 7d535a
kusano 7d535a
	shr  eax,16
kusano 7d535a
	stosb
kusano 7d535a
kusano 7d535a
L_while_test_mmx:
kusano 7d535a
kusano 7d535a
kusano 7d535a
	cmp  [esp+16],edi
kusano 7d535a
	jbe L_break_loop
kusano 7d535a
kusano 7d535a
	cmp  [esp+20],esi
kusano 7d535a
	ja L_do_loop_mmx
kusano 7d535a
	jmp L_break_loop
kusano 7d535a
kusano 7d535a
L_test_for_length_base_mmx:
kusano 7d535a
kusano 7d535a
	mov  edx,eax
kusano 7d535a
	shr  edx,16
kusano 7d535a
kusano 7d535a
	test  al,16
kusano 7d535a
	jz  L_test_for_second_level_length_mmx
kusano 7d535a
	and  eax,15
kusano 7d535a
	jz L_decode_distance_mmx
kusano 7d535a
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
	movd mm1,eax
kusano 7d535a
	movd ecx,mm0
kusano 7d535a
	sub  ebp,eax
kusano 7d535a
	and  ecx, [inflate_fast_mask+eax*4]
kusano 7d535a
	add  edx,ecx
kusano 7d535a
kusano 7d535a
L_decode_distance_mmx:
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
kusano 7d535a
	cmp  ebp,32
kusano 7d535a
	ja L_get_dist_code_mmx
kusano 7d535a
kusano 7d535a
	movd mm6,ebp
kusano 7d535a
	movd mm7,dword ptr [esi]
kusano 7d535a
	add  esi,4
kusano 7d535a
	psllq mm7,mm6
kusano 7d535a
	add  ebp,32
kusano 7d535a
	por mm0,mm7
kusano 7d535a
kusano 7d535a
L_get_dist_code_mmx:
kusano 7d535a
	mov  ebx, [esp+12]
kusano 7d535a
	pand mm5,mm0
kusano 7d535a
	movd eax,mm5
kusano 7d535a
	movq mm5,mm2
kusano 7d535a
	mov  eax, [ebx+eax*4]
kusano 7d535a
kusano 7d535a
L_dodist_mmx:
kusano 7d535a
kusano 7d535a
	movzx  ecx,ah
kusano 7d535a
	mov  ebx,eax
kusano 7d535a
	shr  ebx,16
kusano 7d535a
	sub  ebp,ecx
kusano 7d535a
	movd mm1,ecx
kusano 7d535a
kusano 7d535a
	test  al,16
kusano 7d535a
	jz L_test_for_second_level_dist_mmx
kusano 7d535a
	and  eax,15
kusano 7d535a
	jz L_check_dist_one_mmx
kusano 7d535a
kusano 7d535a
L_add_bits_to_dist_mmx:
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
	movd mm1,eax
kusano 7d535a
	movd ecx,mm0
kusano 7d535a
	sub  ebp,eax
kusano 7d535a
	and  ecx, [inflate_fast_mask+eax*4]
kusano 7d535a
	add  ebx,ecx
kusano 7d535a
kusano 7d535a
L_check_window_mmx:
kusano 7d535a
	mov  [esp+44],esi
kusano 7d535a
	mov  eax,edi
kusano 7d535a
	sub  eax, [esp+40]
kusano 7d535a
kusano 7d535a
	cmp  eax,ebx
kusano 7d535a
	jb L_clip_window_mmx
kusano 7d535a
kusano 7d535a
	mov  ecx,edx
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
kusano 7d535a
	sub  ecx,3
kusano 7d535a
	mov  al, [esi]
kusano 7d535a
	mov  [edi],al
kusano 7d535a
	mov  al, [esi+1]
kusano 7d535a
	mov  dl, [esi+2]
kusano 7d535a
	add  esi,3
kusano 7d535a
	mov  [edi+1],al
kusano 7d535a
	mov  [edi+2],dl
kusano 7d535a
	add  edi,3
kusano 7d535a
	rep movsb
kusano 7d535a
kusano 7d535a
	mov  esi, [esp+44]
kusano 7d535a
	mov  ebx, [esp+8]
kusano 7d535a
	jmp  L_while_test_mmx
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_check_dist_one_mmx:
kusano 7d535a
	cmp  ebx,1
kusano 7d535a
	jne  L_check_window_mmx
kusano 7d535a
	cmp  [esp+40],edi
kusano 7d535a
	je   L_check_window_mmx
kusano 7d535a
kusano 7d535a
	dec  edi
kusano 7d535a
	mov  ecx,edx
kusano 7d535a
	mov  al, [edi]
kusano 7d535a
	sub  ecx,3
kusano 7d535a
kusano 7d535a
	mov  [edi+1],al
kusano 7d535a
	mov  [edi+2],al
kusano 7d535a
	mov  [edi+3],al
kusano 7d535a
	add  edi,4
kusano 7d535a
	rep stosb
kusano 7d535a
kusano 7d535a
	mov  ebx, [esp+8]
kusano 7d535a
	jmp  L_while_test_mmx
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_test_for_second_level_length_mmx:
kusano 7d535a
	test  al,64
kusano 7d535a
	jnz L_test_for_end_of_block
kusano 7d535a
kusano 7d535a
	and  eax,15
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
	movd ecx,mm0
kusano 7d535a
	and  ecx, [inflate_fast_mask+eax*4]
kusano 7d535a
	add  ecx,edx
kusano 7d535a
	mov  eax, [ebx+ecx*4]
kusano 7d535a
	jmp L_dolen_mmx
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_test_for_second_level_dist_mmx:
kusano 7d535a
	test  al,64
kusano 7d535a
	jnz L_invalid_distance_code
kusano 7d535a
kusano 7d535a
	and  eax,15
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
	movd ecx,mm0
kusano 7d535a
	and  ecx, [inflate_fast_mask+eax*4]
kusano 7d535a
	mov  eax, [esp+12]
kusano 7d535a
	add  ecx,ebx
kusano 7d535a
	mov  eax, [eax+ecx*4]
kusano 7d535a
	jmp  L_dodist_mmx
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_clip_window_mmx:
kusano 7d535a
kusano 7d535a
	mov  ecx,eax
kusano 7d535a
	mov  eax, [esp+52]
kusano 7d535a
	neg  ecx
kusano 7d535a
	mov  esi, [esp+56]
kusano 7d535a
kusano 7d535a
	cmp  eax,ebx
kusano 7d535a
	jb  L_invalid_distance_too_far
kusano 7d535a
kusano 7d535a
	add  ecx,ebx
kusano 7d535a
	cmp  dword ptr [esp+48],0
kusano 7d535a
	jne  L_wrap_around_window_mmx
kusano 7d535a
kusano 7d535a
	sub  eax,ecx
kusano 7d535a
	add  esi,eax
kusano 7d535a
kusano 7d535a
	cmp  edx,ecx
kusano 7d535a
	jbe  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
	sub  edx,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
	jmp  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
	cmp  edx,ecx
kusano 7d535a
	jbe  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
	sub  edx,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
	jmp  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
L_wrap_around_window_mmx:
kusano 7d535a
kusano 7d535a
	mov  eax, [esp+48]
kusano 7d535a
	cmp  ecx,eax
kusano 7d535a
	jbe  L_contiguous_in_window_mmx
kusano 7d535a
kusano 7d535a
	add  esi, [esp+52]
kusano 7d535a
	add  esi,eax
kusano 7d535a
	sub  esi,ecx
kusano 7d535a
	sub  ecx,eax
kusano 7d535a
kusano 7d535a
kusano 7d535a
	cmp  edx,ecx
kusano 7d535a
	jbe  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
	sub  edx,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi, [esp+56]
kusano 7d535a
	mov  ecx, [esp+48]
kusano 7d535a
	cmp  edx,ecx
kusano 7d535a
	jbe  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
	sub  edx,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
	jmp  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
L_contiguous_in_window_mmx:
kusano 7d535a
kusano 7d535a
	add  esi,eax
kusano 7d535a
	sub  esi,ecx
kusano 7d535a
kusano 7d535a
kusano 7d535a
	cmp  edx,ecx
kusano 7d535a
	jbe  L_do_copy1_mmx
kusano 7d535a
kusano 7d535a
	sub  edx,ecx
kusano 7d535a
	rep movsb
kusano 7d535a
	mov  esi,edi
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
kusano 7d535a
L_do_copy1_mmx:
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  ecx,edx
kusano 7d535a
	rep movsb
kusano 7d535a
kusano 7d535a
	mov  esi, [esp+44]
kusano 7d535a
	mov  ebx, [esp+8]
kusano 7d535a
	jmp  L_while_test_mmx
kusano 7d535a
; 1174 "inffast.S"
kusano 7d535a
L_invalid_distance_code:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  ecx, invalid_distance_code_msg
kusano 7d535a
	mov  edx,INFLATE_MODE_BAD
kusano 7d535a
	jmp  L_update_stream_state
kusano 7d535a
kusano 7d535a
L_test_for_end_of_block:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	test  al,32
kusano 7d535a
	jz  L_invalid_literal_length_code
kusano 7d535a
kusano 7d535a
	mov  ecx,0
kusano 7d535a
	mov  edx,INFLATE_MODE_TYPE
kusano 7d535a
	jmp  L_update_stream_state
kusano 7d535a
kusano 7d535a
L_invalid_literal_length_code:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  ecx, invalid_literal_length_code_msg
kusano 7d535a
	mov  edx,INFLATE_MODE_BAD
kusano 7d535a
	jmp  L_update_stream_state
kusano 7d535a
kusano 7d535a
L_invalid_distance_too_far:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  esi, [esp+44]
kusano 7d535a
	mov  ecx, invalid_distance_too_far_msg
kusano 7d535a
	mov  edx,INFLATE_MODE_BAD
kusano 7d535a
	jmp  L_update_stream_state
kusano 7d535a
kusano 7d535a
L_update_stream_state:
kusano 7d535a
kusano 7d535a
	mov  eax, [esp+88]
kusano 7d535a
	test  ecx,ecx
kusano 7d535a
	jz  L_skip_msg
kusano 7d535a
	mov  [eax+24],ecx
kusano 7d535a
L_skip_msg:
kusano 7d535a
	mov  eax, [eax+28]
kusano 7d535a
	mov  [eax+mode_state],edx
kusano 7d535a
	jmp  L_break_loop
kusano 7d535a
kusano 7d535a
ALIGN 4
kusano 7d535a
L_break_loop:
kusano 7d535a
; 1243 "inffast.S"
kusano 7d535a
	cmp  dword ptr [inflate_fast_use_mmx],2
kusano 7d535a
	jne  L_update_next_in
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  ebx,ebp
kusano 7d535a
kusano 7d535a
L_update_next_in:
kusano 7d535a
; 1266 "inffast.S"
kusano 7d535a
	mov  eax, [esp+88]
kusano 7d535a
	mov  ecx,ebx
kusano 7d535a
	mov  edx, [eax+28]
kusano 7d535a
	shr  ecx,3
kusano 7d535a
	sub  esi,ecx
kusano 7d535a
	shl  ecx,3
kusano 7d535a
	sub  ebx,ecx
kusano 7d535a
	mov  [eax+12],edi
kusano 7d535a
	mov  [edx+bits_state],ebx
kusano 7d535a
	mov  ecx,ebx
kusano 7d535a
kusano 7d535a
	lea  ebx, [esp+28]
kusano 7d535a
	cmp  [esp+20],ebx
kusano 7d535a
	jne  L_buf_not_used
kusano 7d535a
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
	mov  ebx, [eax+0]
kusano 7d535a
	mov  [esp+20],ebx
kusano 7d535a
	add  esi,ebx
kusano 7d535a
	mov  ebx, [eax+4]
kusano 7d535a
	sub  ebx,11
kusano 7d535a
	add  [esp+20],ebx
kusano 7d535a
kusano 7d535a
L_buf_not_used:
kusano 7d535a
	mov  [eax+0],esi
kusano 7d535a
kusano 7d535a
	mov  ebx,1
kusano 7d535a
	shl  ebx,cl
kusano 7d535a
	dec  ebx
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	cmp  dword ptr [inflate_fast_use_mmx],2
kusano 7d535a
	jne  L_update_hold
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	psrlq mm0,mm1
kusano 7d535a
	movd ebp,mm0
kusano 7d535a
kusano 7d535a
	emms
kusano 7d535a
kusano 7d535a
L_update_hold:
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	and  ebp,ebx
kusano 7d535a
	mov  [edx+hold_state],ebp
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
	mov  ebx, [esp+20]
kusano 7d535a
	cmp  ebx,esi
kusano 7d535a
	jbe  L_last_is_smaller
kusano 7d535a
kusano 7d535a
	sub  ebx,esi
kusano 7d535a
	add  ebx,11
kusano 7d535a
	mov  [eax+4],ebx
kusano 7d535a
	jmp  L_fixup_out
kusano 7d535a
L_last_is_smaller:
kusano 7d535a
	sub  esi,ebx
kusano 7d535a
	neg  esi
kusano 7d535a
	add  esi,11
kusano 7d535a
	mov  [eax+4],esi
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
L_fixup_out:
kusano 7d535a
kusano 7d535a
	mov  ebx, [esp+16]
kusano 7d535a
	cmp  ebx,edi
kusano 7d535a
	jbe  L_end_is_smaller
kusano 7d535a
kusano 7d535a
	sub  ebx,edi
kusano 7d535a
	add  ebx,257
kusano 7d535a
	mov  [eax+16],ebx
kusano 7d535a
	jmp  L_done
kusano 7d535a
L_end_is_smaller:
kusano 7d535a
	sub  edi,ebx
kusano 7d535a
	neg  edi
kusano 7d535a
	add  edi,257
kusano 7d535a
	mov  [eax+16],edi
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
L_done:
kusano 7d535a
	add  esp,64
kusano 7d535a
	popfd
kusano 7d535a
	pop  ebx
kusano 7d535a
	pop  ebp
kusano 7d535a
	pop  esi
kusano 7d535a
	pop  edi
kusano 7d535a
	ret
kusano 7d535a
_inflate_fast endp
kusano 7d535a
kusano 7d535a
_TEXT	ends
kusano 7d535a
end