annotate src/zlib-1.2.8/contrib/masmx64/gvmat64.asm @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 5b4145a0d408
children
rev   line source
cannam@128 1 ;uInt longest_match_x64(
cannam@128 2 ; deflate_state *s,
cannam@128 3 ; IPos cur_match); /* current match */
cannam@128 4
cannam@128 5 ; gvmat64.asm -- Asm portion of the optimized longest_match for 32 bits x86_64
cannam@128 6 ; (AMD64 on Athlon 64, Opteron, Phenom
cannam@128 7 ; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7)
cannam@128 8 ; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant.
cannam@128 9 ;
cannam@128 10 ; File written by Gilles Vollant, by converting to assembly the longest_match
cannam@128 11 ; from Jean-loup Gailly in deflate.c of zLib and infoZip zip.
cannam@128 12 ;
cannam@128 13 ; and by taking inspiration on asm686 with masm, optimised assembly code
cannam@128 14 ; from Brian Raiter, written 1998
cannam@128 15 ;
cannam@128 16 ; This software is provided 'as-is', without any express or implied
cannam@128 17 ; warranty. In no event will the authors be held liable for any damages
cannam@128 18 ; arising from the use of this software.
cannam@128 19 ;
cannam@128 20 ; Permission is granted to anyone to use this software for any purpose,
cannam@128 21 ; including commercial applications, and to alter it and redistribute it
cannam@128 22 ; freely, subject to the following restrictions:
cannam@128 23 ;
cannam@128 24 ; 1. The origin of this software must not be misrepresented; you must not
cannam@128 25 ; claim that you wrote the original software. If you use this software
cannam@128 26 ; in a product, an acknowledgment in the product documentation would be
cannam@128 27 ; appreciated but is not required.
cannam@128 28 ; 2. Altered source versions must be plainly marked as such, and must not be
cannam@128 29 ; misrepresented as being the original software
cannam@128 30 ; 3. This notice may not be removed or altered from any source distribution.
cannam@128 31 ;
cannam@128 32 ;
cannam@128 33 ;
cannam@128 34 ; http://www.zlib.net
cannam@128 35 ; http://www.winimage.com/zLibDll
cannam@128 36 ; http://www.muppetlabs.com/~breadbox/software/assembly.html
cannam@128 37 ;
cannam@128 38 ; to compile this file for infozip Zip, I use option:
cannam@128 39 ; ml64.exe /Flgvmat64 /c /Zi /DINFOZIP gvmat64.asm
cannam@128 40 ;
cannam@128 41 ; to compile this file for zLib, I use option:
cannam@128 42 ; ml64.exe /Flgvmat64 /c /Zi gvmat64.asm
cannam@128 43 ; Be carrefull to adapt zlib1222add below to your version of zLib
cannam@128 44 ; (if you use a version of zLib before 1.0.4 or after 1.2.2.2, change
cannam@128 45 ; value of zlib1222add later)
cannam@128 46 ;
cannam@128 47 ; This file compile with Microsoft Macro Assembler (x64) for AMD64
cannam@128 48 ;
cannam@128 49 ; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK
cannam@128 50 ;
cannam@128 51 ; (you can get Windows WDK with ml64 for AMD64 from
cannam@128 52 ; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price)
cannam@128 53 ;
cannam@128 54
cannam@128 55
cannam@128 56 ;uInt longest_match(s, cur_match)
cannam@128 57 ; deflate_state *s;
cannam@128 58 ; IPos cur_match; /* current match */
cannam@128 59 .code
cannam@128 60 longest_match PROC
cannam@128 61
cannam@128 62
cannam@128 63 ;LocalVarsSize equ 88
cannam@128 64 LocalVarsSize equ 72
cannam@128 65
cannam@128 66 ; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12
cannam@128 67 ; free register : r14,r15
cannam@128 68 ; register can be saved : rsp
cannam@128 69
cannam@128 70 chainlenwmask equ rsp + 8 - LocalVarsSize ; high word: current chain len
cannam@128 71 ; low word: s->wmask
cannam@128 72 ;window equ rsp + xx - LocalVarsSize ; local copy of s->window ; stored in r10
cannam@128 73 ;windowbestlen equ rsp + xx - LocalVarsSize ; s->window + bestlen , use r10+r11
cannam@128 74 ;scanstart equ rsp + xx - LocalVarsSize ; first two bytes of string ; stored in r12w
cannam@128 75 ;scanend equ rsp + xx - LocalVarsSize ; last two bytes of string use ebx
cannam@128 76 ;scanalign equ rsp + xx - LocalVarsSize ; dword-misalignment of string r13
cannam@128 77 ;bestlen equ rsp + xx - LocalVarsSize ; size of best match so far -> r11d
cannam@128 78 ;scan equ rsp + xx - LocalVarsSize ; ptr to string wanting match -> r9
cannam@128 79 IFDEF INFOZIP
cannam@128 80 ELSE
cannam@128 81 nicematch equ (rsp + 16 - LocalVarsSize) ; a good enough match size
cannam@128 82 ENDIF
cannam@128 83
cannam@128 84 save_rdi equ rsp + 24 - LocalVarsSize
cannam@128 85 save_rsi equ rsp + 32 - LocalVarsSize
cannam@128 86 save_rbx equ rsp + 40 - LocalVarsSize
cannam@128 87 save_rbp equ rsp + 48 - LocalVarsSize
cannam@128 88 save_r12 equ rsp + 56 - LocalVarsSize
cannam@128 89 save_r13 equ rsp + 64 - LocalVarsSize
cannam@128 90 ;save_r14 equ rsp + 72 - LocalVarsSize
cannam@128 91 ;save_r15 equ rsp + 80 - LocalVarsSize
cannam@128 92
cannam@128 93
cannam@128 94 ; summary of register usage
cannam@128 95 ; scanend ebx
cannam@128 96 ; scanendw bx
cannam@128 97 ; chainlenwmask edx
cannam@128 98 ; curmatch rsi
cannam@128 99 ; curmatchd esi
cannam@128 100 ; windowbestlen r8
cannam@128 101 ; scanalign r9
cannam@128 102 ; scanalignd r9d
cannam@128 103 ; window r10
cannam@128 104 ; bestlen r11
cannam@128 105 ; bestlend r11d
cannam@128 106 ; scanstart r12d
cannam@128 107 ; scanstartw r12w
cannam@128 108 ; scan r13
cannam@128 109 ; nicematch r14d
cannam@128 110 ; limit r15
cannam@128 111 ; limitd r15d
cannam@128 112 ; prev rcx
cannam@128 113
cannam@128 114 ; all the +4 offsets are due to the addition of pending_buf_size (in zlib
cannam@128 115 ; in the deflate_state structure since the asm code was first written
cannam@128 116 ; (if you compile with zlib 1.0.4 or older, remove the +4).
cannam@128 117 ; Note : these value are good with a 8 bytes boundary pack structure
cannam@128 118
cannam@128 119
cannam@128 120 MAX_MATCH equ 258
cannam@128 121 MIN_MATCH equ 3
cannam@128 122 MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
cannam@128 123
cannam@128 124
cannam@128 125 ;;; Offsets for fields in the deflate_state structure. These numbers
cannam@128 126 ;;; are calculated from the definition of deflate_state, with the
cannam@128 127 ;;; assumption that the compiler will dword-align the fields. (Thus,
cannam@128 128 ;;; changing the definition of deflate_state could easily cause this
cannam@128 129 ;;; program to crash horribly, without so much as a warning at
cannam@128 130 ;;; compile time. Sigh.)
cannam@128 131
cannam@128 132 ; all the +zlib1222add offsets are due to the addition of fields
cannam@128 133 ; in zlib in the deflate_state structure since the asm code was first written
cannam@128 134 ; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
cannam@128 135 ; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
cannam@128 136 ; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
cannam@128 137
cannam@128 138
cannam@128 139 IFDEF INFOZIP
cannam@128 140
cannam@128 141 _DATA SEGMENT
cannam@128 142 COMM window_size:DWORD
cannam@128 143 ; WMask ; 7fff
cannam@128 144 COMM window:BYTE:010040H
cannam@128 145 COMM prev:WORD:08000H
cannam@128 146 ; MatchLen : unused
cannam@128 147 ; PrevMatch : unused
cannam@128 148 COMM strstart:DWORD
cannam@128 149 COMM match_start:DWORD
cannam@128 150 ; Lookahead : ignore
cannam@128 151 COMM prev_length:DWORD ; PrevLen
cannam@128 152 COMM max_chain_length:DWORD
cannam@128 153 COMM good_match:DWORD
cannam@128 154 COMM nice_match:DWORD
cannam@128 155 prev_ad equ OFFSET prev
cannam@128 156 window_ad equ OFFSET window
cannam@128 157 nicematch equ nice_match
cannam@128 158 _DATA ENDS
cannam@128 159 WMask equ 07fffh
cannam@128 160
cannam@128 161 ELSE
cannam@128 162
cannam@128 163 IFNDEF zlib1222add
cannam@128 164 zlib1222add equ 8
cannam@128 165 ENDIF
cannam@128 166 dsWSize equ 56+zlib1222add+(zlib1222add/2)
cannam@128 167 dsWMask equ 64+zlib1222add+(zlib1222add/2)
cannam@128 168 dsWindow equ 72+zlib1222add
cannam@128 169 dsPrev equ 88+zlib1222add
cannam@128 170 dsMatchLen equ 128+zlib1222add
cannam@128 171 dsPrevMatch equ 132+zlib1222add
cannam@128 172 dsStrStart equ 140+zlib1222add
cannam@128 173 dsMatchStart equ 144+zlib1222add
cannam@128 174 dsLookahead equ 148+zlib1222add
cannam@128 175 dsPrevLen equ 152+zlib1222add
cannam@128 176 dsMaxChainLen equ 156+zlib1222add
cannam@128 177 dsGoodMatch equ 172+zlib1222add
cannam@128 178 dsNiceMatch equ 176+zlib1222add
cannam@128 179
cannam@128 180 window_size equ [ rcx + dsWSize]
cannam@128 181 WMask equ [ rcx + dsWMask]
cannam@128 182 window_ad equ [ rcx + dsWindow]
cannam@128 183 prev_ad equ [ rcx + dsPrev]
cannam@128 184 strstart equ [ rcx + dsStrStart]
cannam@128 185 match_start equ [ rcx + dsMatchStart]
cannam@128 186 Lookahead equ [ rcx + dsLookahead] ; 0ffffffffh on infozip
cannam@128 187 prev_length equ [ rcx + dsPrevLen]
cannam@128 188 max_chain_length equ [ rcx + dsMaxChainLen]
cannam@128 189 good_match equ [ rcx + dsGoodMatch]
cannam@128 190 nice_match equ [ rcx + dsNiceMatch]
cannam@128 191 ENDIF
cannam@128 192
cannam@128 193 ; parameter 1 in r8(deflate state s), param 2 in rdx (cur match)
cannam@128 194
cannam@128 195 ; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and
cannam@128 196 ; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp
cannam@128 197 ;
cannam@128 198 ; All registers must be preserved across the call, except for
cannam@128 199 ; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch.
cannam@128 200
cannam@128 201
cannam@128 202
cannam@128 203 ;;; Save registers that the compiler may be using, and adjust esp to
cannam@128 204 ;;; make room for our stack frame.
cannam@128 205
cannam@128 206
cannam@128 207 ;;; Retrieve the function arguments. r8d will hold cur_match
cannam@128 208 ;;; throughout the entire function. edx will hold the pointer to the
cannam@128 209 ;;; deflate_state structure during the function's setup (before
cannam@128 210 ;;; entering the main loop.
cannam@128 211
cannam@128 212 ; parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match)
cannam@128 213
cannam@128 214 ; this clear high 32 bits of r8, which can be garbage in both r8 and rdx
cannam@128 215
cannam@128 216 mov [save_rdi],rdi
cannam@128 217 mov [save_rsi],rsi
cannam@128 218 mov [save_rbx],rbx
cannam@128 219 mov [save_rbp],rbp
cannam@128 220 IFDEF INFOZIP
cannam@128 221 mov r8d,ecx
cannam@128 222 ELSE
cannam@128 223 mov r8d,edx
cannam@128 224 ENDIF
cannam@128 225 mov [save_r12],r12
cannam@128 226 mov [save_r13],r13
cannam@128 227 ; mov [save_r14],r14
cannam@128 228 ; mov [save_r15],r15
cannam@128 229
cannam@128 230
cannam@128 231 ;;; uInt wmask = s->w_mask;
cannam@128 232 ;;; unsigned chain_length = s->max_chain_length;
cannam@128 233 ;;; if (s->prev_length >= s->good_match) {
cannam@128 234 ;;; chain_length >>= 2;
cannam@128 235 ;;; }
cannam@128 236
cannam@128 237 mov edi, prev_length
cannam@128 238 mov esi, good_match
cannam@128 239 mov eax, WMask
cannam@128 240 mov ebx, max_chain_length
cannam@128 241 cmp edi, esi
cannam@128 242 jl LastMatchGood
cannam@128 243 shr ebx, 2
cannam@128 244 LastMatchGood:
cannam@128 245
cannam@128 246 ;;; chainlen is decremented once beforehand so that the function can
cannam@128 247 ;;; use the sign flag instead of the zero flag for the exit test.
cannam@128 248 ;;; It is then shifted into the high word, to make room for the wmask
cannam@128 249 ;;; value, which it will always accompany.
cannam@128 250
cannam@128 251 dec ebx
cannam@128 252 shl ebx, 16
cannam@128 253 or ebx, eax
cannam@128 254
cannam@128 255 ;;; on zlib only
cannam@128 256 ;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
cannam@128 257
cannam@128 258 IFDEF INFOZIP
cannam@128 259 mov [chainlenwmask], ebx
cannam@128 260 ; on infozip nice_match = [nice_match]
cannam@128 261 ELSE
cannam@128 262 mov eax, nice_match
cannam@128 263 mov [chainlenwmask], ebx
cannam@128 264 mov r10d, Lookahead
cannam@128 265 cmp r10d, eax
cannam@128 266 cmovnl r10d, eax
cannam@128 267 mov [nicematch],r10d
cannam@128 268 ENDIF
cannam@128 269
cannam@128 270 ;;; register Bytef *scan = s->window + s->strstart;
cannam@128 271 mov r10, window_ad
cannam@128 272 mov ebp, strstart
cannam@128 273 lea r13, [r10 + rbp]
cannam@128 274
cannam@128 275 ;;; Determine how many bytes the scan ptr is off from being
cannam@128 276 ;;; dword-aligned.
cannam@128 277
cannam@128 278 mov r9,r13
cannam@128 279 neg r13
cannam@128 280 and r13,3
cannam@128 281
cannam@128 282 ;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
cannam@128 283 ;;; s->strstart - (IPos)MAX_DIST(s) : NIL;
cannam@128 284 IFDEF INFOZIP
cannam@128 285 mov eax,07efah ; MAX_DIST = (WSIZE-MIN_LOOKAHEAD) (0x8000-(3+8+1))
cannam@128 286 ELSE
cannam@128 287 mov eax, window_size
cannam@128 288 sub eax, MIN_LOOKAHEAD
cannam@128 289 ENDIF
cannam@128 290 xor edi,edi
cannam@128 291 sub ebp, eax
cannam@128 292
cannam@128 293 mov r11d, prev_length
cannam@128 294
cannam@128 295 cmovng ebp,edi
cannam@128 296
cannam@128 297 ;;; int best_len = s->prev_length;
cannam@128 298
cannam@128 299
cannam@128 300 ;;; Store the sum of s->window + best_len in esi locally, and in esi.
cannam@128 301
cannam@128 302 lea rsi,[r10+r11]
cannam@128 303
cannam@128 304 ;;; register ush scan_start = *(ushf*)scan;
cannam@128 305 ;;; register ush scan_end = *(ushf*)(scan+best_len-1);
cannam@128 306 ;;; Posf *prev = s->prev;
cannam@128 307
cannam@128 308 movzx r12d,word ptr [r9]
cannam@128 309 movzx ebx, word ptr [r9 + r11 - 1]
cannam@128 310
cannam@128 311 mov rdi, prev_ad
cannam@128 312
cannam@128 313 ;;; Jump into the main loop.
cannam@128 314
cannam@128 315 mov edx, [chainlenwmask]
cannam@128 316
cannam@128 317 cmp bx,word ptr [rsi + r8 - 1]
cannam@128 318 jz LookupLoopIsZero
cannam@128 319
cannam@128 320 LookupLoop1:
cannam@128 321 and r8d, edx
cannam@128 322
cannam@128 323 movzx r8d, word ptr [rdi + r8*2]
cannam@128 324 cmp r8d, ebp
cannam@128 325 jbe LeaveNow
cannam@128 326 sub edx, 00010000h
cannam@128 327 js LeaveNow
cannam@128 328
cannam@128 329 LoopEntry1:
cannam@128 330 cmp bx,word ptr [rsi + r8 - 1]
cannam@128 331 jz LookupLoopIsZero
cannam@128 332
cannam@128 333 LookupLoop2:
cannam@128 334 and r8d, edx
cannam@128 335
cannam@128 336 movzx r8d, word ptr [rdi + r8*2]
cannam@128 337 cmp r8d, ebp
cannam@128 338 jbe LeaveNow
cannam@128 339 sub edx, 00010000h
cannam@128 340 js LeaveNow
cannam@128 341
cannam@128 342 LoopEntry2:
cannam@128 343 cmp bx,word ptr [rsi + r8 - 1]
cannam@128 344 jz LookupLoopIsZero
cannam@128 345
cannam@128 346 LookupLoop4:
cannam@128 347 and r8d, edx
cannam@128 348
cannam@128 349 movzx r8d, word ptr [rdi + r8*2]
cannam@128 350 cmp r8d, ebp
cannam@128 351 jbe LeaveNow
cannam@128 352 sub edx, 00010000h
cannam@128 353 js LeaveNow
cannam@128 354
cannam@128 355 LoopEntry4:
cannam@128 356
cannam@128 357 cmp bx,word ptr [rsi + r8 - 1]
cannam@128 358 jnz LookupLoop1
cannam@128 359 jmp LookupLoopIsZero
cannam@128 360
cannam@128 361
cannam@128 362 ;;; do {
cannam@128 363 ;;; match = s->window + cur_match;
cannam@128 364 ;;; if (*(ushf*)(match+best_len-1) != scan_end ||
cannam@128 365 ;;; *(ushf*)match != scan_start) continue;
cannam@128 366 ;;; [...]
cannam@128 367 ;;; } while ((cur_match = prev[cur_match & wmask]) > limit
cannam@128 368 ;;; && --chain_length != 0);
cannam@128 369 ;;;
cannam@128 370 ;;; Here is the inner loop of the function. The function will spend the
cannam@128 371 ;;; majority of its time in this loop, and majority of that time will
cannam@128 372 ;;; be spent in the first ten instructions.
cannam@128 373 ;;;
cannam@128 374 ;;; Within this loop:
cannam@128 375 ;;; ebx = scanend
cannam@128 376 ;;; r8d = curmatch
cannam@128 377 ;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
cannam@128 378 ;;; esi = windowbestlen - i.e., (window + bestlen)
cannam@128 379 ;;; edi = prev
cannam@128 380 ;;; ebp = limit
cannam@128 381
cannam@128 382 LookupLoop:
cannam@128 383 and r8d, edx
cannam@128 384
cannam@128 385 movzx r8d, word ptr [rdi + r8*2]
cannam@128 386 cmp r8d, ebp
cannam@128 387 jbe LeaveNow
cannam@128 388 sub edx, 00010000h
cannam@128 389 js LeaveNow
cannam@128 390
cannam@128 391 LoopEntry:
cannam@128 392
cannam@128 393 cmp bx,word ptr [rsi + r8 - 1]
cannam@128 394 jnz LookupLoop1
cannam@128 395 LookupLoopIsZero:
cannam@128 396 cmp r12w, word ptr [r10 + r8]
cannam@128 397 jnz LookupLoop1
cannam@128 398
cannam@128 399
cannam@128 400 ;;; Store the current value of chainlen.
cannam@128 401 mov [chainlenwmask], edx
cannam@128 402
cannam@128 403 ;;; Point edi to the string under scrutiny, and esi to the string we
cannam@128 404 ;;; are hoping to match it up with. In actuality, esi and edi are
cannam@128 405 ;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is
cannam@128 406 ;;; initialized to -(MAX_MATCH_8 - scanalign).
cannam@128 407
cannam@128 408 lea rsi,[r8+r10]
cannam@128 409 mov rdx, 0fffffffffffffef8h; -(MAX_MATCH_8)
cannam@128 410 lea rsi, [rsi + r13 + 0108h] ;MAX_MATCH_8]
cannam@128 411 lea rdi, [r9 + r13 + 0108h] ;MAX_MATCH_8]
cannam@128 412
cannam@128 413 prefetcht1 [rsi+rdx]
cannam@128 414 prefetcht1 [rdi+rdx]
cannam@128 415
cannam@128 416
cannam@128 417 ;;; Test the strings for equality, 8 bytes at a time. At the end,
cannam@128 418 ;;; adjust rdx so that it is offset to the exact byte that mismatched.
cannam@128 419 ;;;
cannam@128 420 ;;; We already know at this point that the first three bytes of the
cannam@128 421 ;;; strings match each other, and they can be safely passed over before
cannam@128 422 ;;; starting the compare loop. So what this code does is skip over 0-3
cannam@128 423 ;;; bytes, as much as necessary in order to dword-align the edi
cannam@128 424 ;;; pointer. (rsi will still be misaligned three times out of four.)
cannam@128 425 ;;;
cannam@128 426 ;;; It should be confessed that this loop usually does not represent
cannam@128 427 ;;; much of the total running time. Replacing it with a more
cannam@128 428 ;;; straightforward "rep cmpsb" would not drastically degrade
cannam@128 429 ;;; performance.
cannam@128 430
cannam@128 431
cannam@128 432 LoopCmps:
cannam@128 433 mov rax, [rsi + rdx]
cannam@128 434 xor rax, [rdi + rdx]
cannam@128 435 jnz LeaveLoopCmps
cannam@128 436
cannam@128 437 mov rax, [rsi + rdx + 8]
cannam@128 438 xor rax, [rdi + rdx + 8]
cannam@128 439 jnz LeaveLoopCmps8
cannam@128 440
cannam@128 441
cannam@128 442 mov rax, [rsi + rdx + 8+8]
cannam@128 443 xor rax, [rdi + rdx + 8+8]
cannam@128 444 jnz LeaveLoopCmps16
cannam@128 445
cannam@128 446 add rdx,8+8+8
cannam@128 447
cannam@128 448 jnz short LoopCmps
cannam@128 449 jmp short LenMaximum
cannam@128 450 LeaveLoopCmps16: add rdx,8
cannam@128 451 LeaveLoopCmps8: add rdx,8
cannam@128 452 LeaveLoopCmps:
cannam@128 453
cannam@128 454 test eax, 0000FFFFh
cannam@128 455 jnz LenLower
cannam@128 456
cannam@128 457 test eax,0ffffffffh
cannam@128 458
cannam@128 459 jnz LenLower32
cannam@128 460
cannam@128 461 add rdx,4
cannam@128 462 shr rax,32
cannam@128 463 or ax,ax
cannam@128 464 jnz LenLower
cannam@128 465
cannam@128 466 LenLower32:
cannam@128 467 shr eax,16
cannam@128 468 add rdx,2
cannam@128 469 LenLower: sub al, 1
cannam@128 470 adc rdx, 0
cannam@128 471 ;;; Calculate the length of the match. If it is longer than MAX_MATCH,
cannam@128 472 ;;; then automatically accept it as the best possible match and leave.
cannam@128 473
cannam@128 474 lea rax, [rdi + rdx]
cannam@128 475 sub rax, r9
cannam@128 476 cmp eax, MAX_MATCH
cannam@128 477 jge LenMaximum
cannam@128 478
cannam@128 479 ;;; If the length of the match is not longer than the best match we
cannam@128 480 ;;; have so far, then forget it and return to the lookup loop.
cannam@128 481 ;///////////////////////////////////
cannam@128 482
cannam@128 483 cmp eax, r11d
cannam@128 484 jg LongerMatch
cannam@128 485
cannam@128 486 lea rsi,[r10+r11]
cannam@128 487
cannam@128 488 mov rdi, prev_ad
cannam@128 489 mov edx, [chainlenwmask]
cannam@128 490 jmp LookupLoop
cannam@128 491
cannam@128 492 ;;; s->match_start = cur_match;
cannam@128 493 ;;; best_len = len;
cannam@128 494 ;;; if (len >= nice_match) break;
cannam@128 495 ;;; scan_end = *(ushf*)(scan+best_len-1);
cannam@128 496
cannam@128 497 LongerMatch:
cannam@128 498 mov r11d, eax
cannam@128 499 mov match_start, r8d
cannam@128 500 cmp eax, [nicematch]
cannam@128 501 jge LeaveNow
cannam@128 502
cannam@128 503 lea rsi,[r10+rax]
cannam@128 504
cannam@128 505 movzx ebx, word ptr [r9 + rax - 1]
cannam@128 506 mov rdi, prev_ad
cannam@128 507 mov edx, [chainlenwmask]
cannam@128 508 jmp LookupLoop
cannam@128 509
cannam@128 510 ;;; Accept the current string, with the maximum possible length.
cannam@128 511
cannam@128 512 LenMaximum:
cannam@128 513 mov r11d,MAX_MATCH
cannam@128 514 mov match_start, r8d
cannam@128 515
cannam@128 516 ;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
cannam@128 517 ;;; return s->lookahead;
cannam@128 518
cannam@128 519 LeaveNow:
cannam@128 520 IFDEF INFOZIP
cannam@128 521 mov eax,r11d
cannam@128 522 ELSE
cannam@128 523 mov eax, Lookahead
cannam@128 524 cmp r11d, eax
cannam@128 525 cmovng eax, r11d
cannam@128 526 ENDIF
cannam@128 527
cannam@128 528 ;;; Restore the stack and return from whence we came.
cannam@128 529
cannam@128 530
cannam@128 531 mov rsi,[save_rsi]
cannam@128 532 mov rdi,[save_rdi]
cannam@128 533 mov rbx,[save_rbx]
cannam@128 534 mov rbp,[save_rbp]
cannam@128 535 mov r12,[save_r12]
cannam@128 536 mov r13,[save_r13]
cannam@128 537 ; mov r14,[save_r14]
cannam@128 538 ; mov r15,[save_r15]
cannam@128 539
cannam@128 540
cannam@128 541 ret 0
cannam@128 542 ; please don't remove this string !
cannam@128 543 ; Your can freely use gvmat64 in any free or commercial app
cannam@128 544 ; but it is far better don't remove the string in the binary!
cannam@128 545 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
cannam@128 546 longest_match ENDP
cannam@128 547
cannam@128 548 match_init PROC
cannam@128 549 ret 0
cannam@128 550 match_init ENDP
cannam@128 551
cannam@128 552
cannam@128 553 END