123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- /*
- */
- #define BEFORE_JMP .att_syntax
- #define AFTER_JMP .intel_syntax noprefix
- #ifndef NO_UNDERLINE
- # define match_init _match_init
- # define longest_match _longest_match
- #endif
- .intel_syntax noprefix
- .globl match_init, longest_match
- .text
- longest_match:
- #define LocalVarsSize 96
- /*
- */
- #define chainlenwmask (rsp + 8 - LocalVarsSize)
- #define nicematch (rsp + 16 - LocalVarsSize)
- #define save_rdi (rsp + 24 - LocalVarsSize)
- #define save_rsi (rsp + 32 - LocalVarsSize)
- #define save_rbx (rsp + 40 - LocalVarsSize)
- #define save_rbp (rsp + 48 - LocalVarsSize)
- #define save_r12 (rsp + 56 - LocalVarsSize)
- #define save_r13 (rsp + 64 - LocalVarsSize)
- #define save_r14 (rsp + 72 - LocalVarsSize)
- #define save_r15 (rsp + 80 - LocalVarsSize)
- /*
- */
- #define MAX_MATCH 258
- #define MIN_MATCH 3
- #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
- /*
- */
- /* you can check the structure offset by running
- #include <stdlib.h>
- #include <stdio.h>
- #include "deflate.h"
- void print_depl()
- {
- deflate_state ds
- deflate_state *s=&ds
- printf("size pointer=%u\n",(int)sizeof(void*))
- printf("#define dsWSize %u\n",(int)(((char*)&(s->w_size))-((char*)s)))
- printf("#define dsWMask %u\n",(int)(((char*)&(s->w_mask))-((char*)s)))
- printf("#define dsWindow %u\n",(int)(((char*)&(s->window))-((char*)s)))
- printf("#define dsPrev %u\n",(int)(((char*)&(s->prev))-((char*)s)))
- printf("#define dsMatchLen %u\n",(int)(((char*)&(s->match_length))-((char*)s)))
- printf("#define dsPrevMatch %u\n",(int)(((char*)&(s->prev_match))-((char*)s)))
- printf("#define dsStrStart %u\n",(int)(((char*)&(s->strstart))-((char*)s)))
- printf("#define dsMatchStart %u\n",(int)(((char*)&(s->match_start))-((char*)s)))
- printf("#define dsLookahead %u\n",(int)(((char*)&(s->lookahead))-((char*)s)))
- printf("#define dsPrevLen %u\n",(int)(((char*)&(s->prev_length))-((char*)s)))
- printf("#define dsMaxChainLen %u\n",(int)(((char*)&(s->max_chain_length))-((char*)s)))
- printf("#define dsGoodMatch %u\n",(int)(((char*)&(s->good_match))-((char*)s)))
- printf("#define dsNiceMatch %u\n",(int)(((char*)&(s->nice_match))-((char*)s)))
- }
- */
- #define dsWSize 68
- #define dsWMask 76
- #define dsWindow 80
- #define dsPrev 96
- #define dsMatchLen 144
- #define dsPrevMatch 148
- #define dsStrStart 156
- #define dsMatchStart 160
- #define dsLookahead 164
- #define dsPrevLen 168
- #define dsMaxChainLen 172
- #define dsGoodMatch 188
- #define dsNiceMatch 192
- #define window_size [ rcx + dsWSize]
- #define WMask [ rcx + dsWMask]
- #define window_ad [ rcx + dsWindow]
- #define prev_ad [ rcx + dsPrev]
- #define strstart [ rcx + dsStrStart]
- #define match_start [ rcx + dsMatchStart]
- #define Lookahead [ rcx + dsLookahead] //
- #define prev_length [ rcx + dsPrevLen]
- #define max_chain_length [ rcx + dsMaxChainLen]
- #define good_match [ rcx + dsGoodMatch]
- #define nice_match [ rcx + dsNiceMatch]
- /*
- */
- mov [save_rbx],rbx
- mov [save_rbp],rbp
- mov rcx,rdi
- mov r8d,esi
- mov [save_r12],r12
- mov [save_r13],r13
- mov [save_r14],r14
- mov [save_r15],r15
- //
- //
- //
- //
- //
- 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
- //
- //
- mov eax, nice_match
- mov [chainlenwmask], ebx
- mov r10d, Lookahead
- cmp r10d, eax
- cmovnl r10d, eax
- mov [nicematch],r10d
- //
- mov r10, window_ad
- mov ebp, strstart
- lea r13, [r10 + rbp]
- //
- //
- mov r9,r13
- neg r13
- and r13,3
- //
- //
- mov eax, window_size
- sub eax, MIN_LOOKAHEAD
- 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, 0x00010000
- BEFORE_JMP
- js LeaveNow
- AFTER_JMP
- LoopEntry1:
- cmp bx,word ptr [rsi + r8 - 1]
- BEFORE_JMP
- jz LookupLoopIsZero
- AFTER_JMP
- LookupLoop2:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- BEFORE_JMP
- jbe LeaveNow
- AFTER_JMP
- sub edx, 0x00010000
- BEFORE_JMP
- js LeaveNow
- AFTER_JMP
- LoopEntry2:
- cmp bx,word ptr [rsi + r8 - 1]
- BEFORE_JMP
- jz LookupLoopIsZero
- AFTER_JMP
- LookupLoop4:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- BEFORE_JMP
- jbe LeaveNow
- AFTER_JMP
- sub edx, 0x00010000
- BEFORE_JMP
- js LeaveNow
- AFTER_JMP
- LoopEntry4:
- cmp bx,word ptr [rsi + r8 - 1]
- BEFORE_JMP
- jnz LookupLoop1
- jmp LookupLoopIsZero
- AFTER_JMP
- /*
- */
- .balign 16
- LookupLoop:
- and r8d, edx
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- BEFORE_JMP
- jbe LeaveNow
- AFTER_JMP
- sub edx, 0x00010000
- BEFORE_JMP
- js LeaveNow
- AFTER_JMP
- LoopEntry:
- cmp bx,word ptr [rsi + r8 - 1]
- BEFORE_JMP
- jnz LookupLoop1
- AFTER_JMP
- LookupLoopIsZero:
- cmp r12w, word ptr [r10 + r8]
- BEFORE_JMP
- jnz LookupLoop1
- AFTER_JMP
- //
- mov [chainlenwmask], edx
- /*
- */
- lea rsi,[r8+r10]
- mov rdx, 0xfffffffffffffef8 //
- lea rsi, [rsi + r13 + 0x0108] //
- lea rdi, [r9 + r13 + 0x0108] //
- 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
- BEFORE_JMP
- jnz LoopCmps
- jmp LenMaximum
- AFTER_JMP
-
- LeaveLoopCmps16: add rdx,8
- LeaveLoopCmps8: add rdx,8
- LeaveLoopCmps:
- test eax, 0x0000FFFF
- jnz LenLower
- test eax,0xffffffff
- jnz LenLower32
- add rdx,4
- shr rax,32
- or ax,ax
- BEFORE_JMP
- jnz LenLower
- AFTER_JMP
- 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
- BEFORE_JMP
- jge LenMaximum
- AFTER_JMP
- /*
- */
- cmp eax, r11d
- jg LongerMatch
- lea rsi,[r10+r11]
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- BEFORE_JMP
- jmp LookupLoop
- AFTER_JMP
- /*
- */
- LongerMatch:
- mov r11d, eax
- mov match_start, r8d
- cmp eax, [nicematch]
- BEFORE_JMP
- jge LeaveNow
- AFTER_JMP
- lea rsi,[r10+rax]
- movzx ebx, word ptr [r9 + rax - 1]
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- BEFORE_JMP
- jmp LookupLoop
- AFTER_JMP
- //
- LenMaximum:
- mov r11d,MAX_MATCH
- mov match_start, r8d
- //
- //
- LeaveNow:
- mov eax, Lookahead
- cmp r11d, eax
- cmovng eax, r11d
- //
- // mov rsi,[save_rsi]
- // mov rdi,[save_rdi]
- mov rbx,[save_rbx]
- mov rbp,[save_rbp]
- mov r12,[save_r12]
- mov r13,[save_r13]
- mov r14,[save_r14]
- mov r15,[save_r15]
- 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
- match_init:
- ret 0
|