123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- .code
- longest_match PROC
- LocalVarsSize equ 72
- chainlenwmask equ rsp + 8 - LocalVarsSize
-
- IFDEF INFOZIP
- ELSE
- nicematch equ (rsp + 16 - LocalVarsSize)
- ENDIF
- save_rdi equ rsp + 24 - LocalVarsSize
- save_rsi equ rsp + 32 - LocalVarsSize
- save_rbx equ rsp + 40 - LocalVarsSize
- save_rbp equ rsp + 48 - LocalVarsSize
- save_r12 equ rsp + 56 - LocalVarsSize
- save_r13 equ rsp + 64 - LocalVarsSize
- MAX_MATCH equ 258
- MIN_MATCH equ 3
- MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
- IFDEF INFOZIP
- _DATA SEGMENT
- COMM window_size:DWORD
- COMM window:BYTE:010040H
- COMM prev:WORD:08000H
- COMM strstart:DWORD
- COMM match_start:DWORD
- COMM prev_length:DWORD
- COMM max_chain_length:DWORD
- COMM good_match:DWORD
- COMM nice_match:DWORD
- prev_ad equ OFFSET prev
- window_ad equ OFFSET window
- nicematch equ nice_match
- _DATA ENDS
- WMask equ 07fffh
- ELSE
- IFNDEF zlib1222add
- zlib1222add equ 8
- ENDIF
- dsWSize equ 56+zlib1222add+(zlib1222add/2)
- dsWMask equ 64+zlib1222add+(zlib1222add/2)
- dsWindow equ 72+zlib1222add
- dsPrev equ 88+zlib1222add
- dsMatchLen equ 128+zlib1222add
- dsPrevMatch equ 132+zlib1222add
- dsStrStart equ 140+zlib1222add
- dsMatchStart equ 144+zlib1222add
- dsLookahead equ 148+zlib1222add
- dsPrevLen equ 152+zlib1222add
- dsMaxChainLen equ 156+zlib1222add
- dsGoodMatch equ 172+zlib1222add
- dsNiceMatch equ 176+zlib1222add
- window_size equ [ rcx + dsWSize]
- WMask equ [ rcx + dsWMask]
- window_ad equ [ rcx + dsWindow]
- prev_ad equ [ rcx + dsPrev]
- strstart equ [ rcx + dsStrStart]
- match_start equ [ rcx + dsMatchStart]
- Lookahead equ [ rcx + dsLookahead]
- prev_length equ [ rcx + dsPrevLen]
- max_chain_length equ [ rcx + dsMaxChainLen]
- good_match equ [ rcx + dsGoodMatch]
- nice_match equ [ rcx + dsNiceMatch]
- ENDIF
- mov [save_rdi],rdi
- mov [save_rsi],rsi
- mov [save_rbx],rbx
- mov [save_rbp],rbp
- IFDEF INFOZIP
- mov r8d,ecx
- ELSE
- mov r8d,edx
- ENDIF
- mov [save_r12],r12
- mov [save_r13],r13
- mov edi, prev_length
- mov esi, good_match
- mov eax, WMask
- mov ebx, max_chain_length
- cmp edi, esi
- jl LastMatchGood
- shr ebx, 2
- LastMatchGood:
- dec ebx
- shl ebx, 16
- or ebx, eax
- IFDEF INFOZIP
- mov [chainlenwmask], ebx
- ELSE
- mov eax, nice_match
- mov [chainlenwmask], ebx
- mov r10d, Lookahead
- cmp r10d, eax
- cmovnl r10d, eax
- mov [nicematch],r10d
- ENDIF
- mov r10, window_ad
- mov ebp, strstart
- lea r13, [r10 + rbp]
- mov r9,r13
- neg r13
- and r13,3
- IFDEF INFOZIP
- mov eax,07efah
- ELSE
- mov eax, window_size
- sub eax, MIN_LOOKAHEAD
- ENDIF
- xor edi,edi
- sub ebp, eax
- mov r11d, prev_length
- cmovng ebp,edi
- lea rsi,[r10+r11]
- movzx r12d,word ptr [r9]
- movzx ebx, word ptr [r9 + r11 - 1]
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- cmp bx,word ptr [rsi + r8 - 1]
- jz LookupLoopIsZero
- LookupLoop1:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
- LoopEntry1:
- cmp bx,word ptr [rsi + r8 - 1]
- jz LookupLoopIsZero
- LookupLoop2:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
- LoopEntry2:
- cmp bx,word ptr [rsi + r8 - 1]
- jz LookupLoopIsZero
- LookupLoop4:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
- LoopEntry4:
- cmp bx,word ptr [rsi + r8 - 1]
- jnz LookupLoop1
- jmp LookupLoopIsZero
- LookupLoop:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
- LoopEntry:
- cmp bx,word ptr [rsi + r8 - 1]
- jnz LookupLoop1
- LookupLoopIsZero:
- cmp r12w, word ptr [r10 + r8]
- jnz LookupLoop1
- mov [chainlenwmask], edx
- lea rsi,[r8+r10]
- mov rdx, 0fffffffffffffef8h
- lea rsi, [rsi + r13 + 0108h]
- lea rdi, [r9 + r13 + 0108h]
- prefetcht1 [rsi+rdx]
- prefetcht1 [rdi+rdx]
- LoopCmps:
- mov rax, [rsi + rdx]
- xor rax, [rdi + rdx]
- jnz LeaveLoopCmps
- mov rax, [rsi + rdx + 8]
- xor rax, [rdi + rdx + 8]
- jnz LeaveLoopCmps8
- mov rax, [rsi + rdx + 8+8]
- xor rax, [rdi + rdx + 8+8]
- jnz LeaveLoopCmps16
- add rdx,8+8+8
- jnz short LoopCmps
- jmp short LenMaximum
- LeaveLoopCmps16: add rdx,8
- LeaveLoopCmps8: add rdx,8
- LeaveLoopCmps:
- test eax, 0000FFFFh
- jnz LenLower
- test eax,0ffffffffh
- jnz LenLower32
- add rdx,4
- shr rax,32
- or ax,ax
- jnz LenLower
- LenLower32:
- shr eax,16
- add rdx,2
- LenLower: sub al, 1
- adc rdx, 0
- lea rax, [rdi + rdx]
- sub rax, r9
- cmp eax, MAX_MATCH
- jge LenMaximum
- cmp eax, r11d
- jg LongerMatch
- lea rsi,[r10+r11]
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- jmp LookupLoop
- LongerMatch:
- mov r11d, eax
- mov match_start, r8d
- cmp eax, [nicematch]
- jge LeaveNow
- lea rsi,[r10+rax]
- movzx ebx, word ptr [r9 + rax - 1]
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- jmp LookupLoop
- LenMaximum:
- mov r11d,MAX_MATCH
- mov match_start, r8d
- LeaveNow:
- IFDEF INFOZIP
- mov eax,r11d
- ELSE
- mov eax, Lookahead
- cmp r11d, eax
- cmovng eax, r11d
- ENDIF
- mov rsi,[save_rsi]
- mov rdi,[save_rdi]
- mov rbx,[save_rbx]
- mov rbp,[save_rbp]
- mov r12,[save_r12]
- mov r13,[save_r13]
- ret 0
- db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0
- longest_match ENDP
- match_init PROC
- ret 0
- match_init ENDP
- END
|