1381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; match686.asm -- Asm portion of the optimized longest_match for 32 bits x86
2381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; Copyright (C) 1995-1996 Jean-loup Gailly, Brian Raiter and Gilles Vollant.
3381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; File written by Gilles Vollant, by converting match686.S from Brian Raiter
4381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; for MASM. This is as assembly version of longest_match
5381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  from Jean-loup Gailly in deflate.c
6381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
7381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;         http://www.zlib.net
8381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;         http://www.winimage.com/zLibDll
9381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;         http://www.muppetlabs.com/~breadbox/software/assembly.html
10381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
11381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; For Visual C++ 4.x and higher and ML 6.x and higher
12381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   ml.exe is distributed in
13381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  http://www.microsoft.com/downloads/details.aspx?FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64
14381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
15381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; this file contain two implementation of longest_match
16381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
17381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  this longest_match was written by Brian raiter (1998), optimized for Pentium Pro
18381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   (and the faster known version of match_init on modern Core 2 Duo and AMD Phenom)
19381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
20381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  for using an assembly version of longest_match, you need define ASMV in project
21381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
22381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;    compile the asm file running
23381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;           ml /coff /Zi /c /Flmatch686.lst match686.asm
24381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;    and do not include match686.obj in your project
25381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
26381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; note: contrib of zLib 1.2.3 and earlier contained both a deprecated version for
27381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  Pentium (prior Pentium Pro) and this version for Pentium Pro and modern processor
28381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  with autoselect (with cpu detection code)
29381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  if you want support the old pentium optimization, you can still use these version
30381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
31381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; this file is not optimized for old pentium, but it compatible with all x86 32 bits
32381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; processor (starting 80386)
33381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
34381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;
35381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; see below : zlib1222add must be adjuster if you use a zlib version < 1.2.2.2
36381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
37381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;uInt longest_match(s, cur_match)
38381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;    deflate_state *s;
39381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;    IPos cur_match;                             /* current match */
40381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
41381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    NbStack         equ     76
42381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    cur_match       equ     dword ptr[esp+NbStack-0]
43381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    str_s           equ     dword ptr[esp+NbStack-4]
44381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; 5 dword on top (ret,ebp,esi,edi,ebx)
45381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    adrret          equ     dword ptr[esp+NbStack-8]
46381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    pushebp         equ     dword ptr[esp+NbStack-12]
47381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    pushedi         equ     dword ptr[esp+NbStack-16]
48381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    pushesi         equ     dword ptr[esp+NbStack-20]
49381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    pushebx         equ     dword ptr[esp+NbStack-24]
50381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
51381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    chain_length    equ     dword ptr [esp+NbStack-28]
52381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    limit           equ     dword ptr [esp+NbStack-32]
53381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    best_len        equ     dword ptr [esp+NbStack-36]
54381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    window          equ     dword ptr [esp+NbStack-40]
55381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    prev            equ     dword ptr [esp+NbStack-44]
56381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    scan_start      equ      word ptr [esp+NbStack-48]
57381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    wmask           equ     dword ptr [esp+NbStack-52]
58381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    match_start_ptr equ     dword ptr [esp+NbStack-56]
59381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    nice_match      equ     dword ptr [esp+NbStack-60]
60381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    scan            equ     dword ptr [esp+NbStack-64]
61381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
62381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    windowlen       equ     dword ptr [esp+NbStack-68]
63381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    match_start     equ     dword ptr [esp+NbStack-72]
64381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    strend          equ     dword ptr [esp+NbStack-76]
65381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    NbStackAdd      equ     (NbStack-24)
66381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
67381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    .386p
68381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
69381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    name    gvmatch
70381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    .MODEL  FLAT
71381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
72381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
73381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
74381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  all the +zlib1222add offsets are due to the addition of fields
75381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  in zlib in the deflate_state structure since the asm code was first written
76381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
77381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
78381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
79381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
80381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    zlib1222add         equ     8
81381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
82381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;  Note : these value are good with a 8 bytes boundary pack structure
83381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_chain_length    equ     74h+zlib1222add
84381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_window          equ     30h+zlib1222add
85381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_strstart        equ     64h+zlib1222add
86381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_prev_length     equ     70h+zlib1222add
87381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_nice_match      equ     88h+zlib1222add
88381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_w_size          equ     24h+zlib1222add
89381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_prev            equ     38h+zlib1222add
90381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_w_mask          equ     2ch+zlib1222add
91381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_good_match      equ     84h+zlib1222add
92381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_match_start     equ     68h+zlib1222add
93381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    dep_lookahead       equ     6ch+zlib1222add
94381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
95381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
96381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes_TEXT                   segment
97381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
98381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesIFDEF NOUNDERLINE
99381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes            public  longest_match
100381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes            public  match_init
101381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesELSE
102381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes            public  _longest_match
103381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes            public  _match_init
104381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesENDIF
105381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
106381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    MAX_MATCH           equ     258
107381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    MIN_MATCH           equ     3
108381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    MIN_LOOKAHEAD       equ     (MAX_MATCH+MIN_MATCH+1)
109381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
110381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
111381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
112381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesMAX_MATCH       equ     258
113381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesMIN_MATCH       equ     3
114381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesMIN_LOOKAHEAD   equ     (MAX_MATCH + MIN_MATCH + 1)
115381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesMAX_MATCH_8_     equ     ((MAX_MATCH + 7) AND 0FFF0h)
116381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
117381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
118381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; stack frame offsets
119381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
120381716e9396b55b1adb8235b020c37344f60ab07Elliott Hugheschainlenwmask   equ  esp + 0    ; high word: current chain len
121381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes                    ; low word: s->wmask
122381716e9396b55b1adb8235b020c37344f60ab07Elliott Hugheswindow      equ  esp + 4    ; local copy of s->window
123381716e9396b55b1adb8235b020c37344f60ab07Elliott Hugheswindowbestlen   equ  esp + 8    ; s->window + bestlen
124381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesscanstart   equ  esp + 16   ; first two bytes of string
125381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesscanend     equ  esp + 12   ; last two bytes of string
126381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesscanalign   equ  esp + 20   ; dword-misalignment of string
127381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesnicematch   equ  esp + 24   ; a good enough match size
128381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesbestlen     equ  esp + 28   ; size of best match so far
129381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesscan        equ  esp + 32   ; ptr to string wanting match
130381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
131381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLocalVarsSize   equ 36
132381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   saved ebx   byte esp + 36
133381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   saved edi   byte esp + 40
134381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   saved esi   byte esp + 44
135381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   saved ebp   byte esp + 48
136381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;   return address  byte esp + 52
137381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesdeflatestate    equ  esp + 56   ; the function arguments
138381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughescurmatch    equ  esp + 60
139381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
140381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Offsets for fields in the deflate_state structure. These numbers
141381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; are calculated from the definition of deflate_state, with the
142381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; assumption that the compiler will dword-align the fields. (Thus,
143381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; changing the definition of deflate_state could easily cause this
144381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; program to crash horribly, without so much as a warning at
145381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; compile time. Sigh.)
146381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
147381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsWSize     equ 36+zlib1222add
148381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsWMask     equ 44+zlib1222add
149381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsWindow    equ 48+zlib1222add
150381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsPrev      equ 56+zlib1222add
151381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsMatchLen  equ 88+zlib1222add
152381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsPrevMatch equ 92+zlib1222add
153381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsStrStart  equ 100+zlib1222add
154381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsMatchStart    equ 104+zlib1222add
155381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsLookahead equ 108+zlib1222add
156381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsPrevLen   equ 112+zlib1222add
157381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsMaxChainLen   equ 116+zlib1222add
158381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsGoodMatch equ 132+zlib1222add
159381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesdsNiceMatch equ 136+zlib1222add
160381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
161381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
162381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; match686.asm -- Pentium-Pro-optimized version of longest_match()
163381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Written for zlib 1.1.2
164381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
165381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html
166381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;
167381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;
168381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  This software is provided 'as-is', without any express or implied
169381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  warranty.  In no event will the authors be held liable for any damages
170381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  arising from the use of this software.
171381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;
172381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  Permission is granted to anyone to use this software for any purpose,
173381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  including commercial applications, and to alter it and redistribute it
174381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  freely, subject to the following restrictions:
175381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;
176381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  1. The origin of this software must not be misrepresented; you must not
177381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;     claim that you wrote the original software. If you use this software
178381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;     in a product, an acknowledgment in the product documentation would be
179381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;     appreciated but is not required.
180381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  2. Altered source versions must be plainly marked as such, and must not be
181381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;     misrepresented as being the original software
182381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;  3. This notice may not be removed or altered from any source distribution.
183381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;
184381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
185381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;GLOBAL _longest_match, _match_init
186381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
187381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
188381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;SECTION    .text
189381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
190381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch)
191381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
192381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;_longest_match:
193381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    IFDEF NOUNDERLINE
194381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    longest_match       proc near
195381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    ELSE
196381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    _longest_match      proc near
197381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    ENDIF
198ee9e11d0d4e3361533860bf04896abb86a291bfbElliott Hughes.FPO (9, 4, 0, 0, 1, 0)
199381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
200381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Save registers that the compiler may be using, and adjust esp to
201381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; make room for our stack frame.
202381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
203381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        push    ebp
204381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        push    edi
205381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        push    esi
206381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        push    ebx
207381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        sub esp, LocalVarsSize
208381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
209381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Retrieve the function arguments. ecx will hold cur_match
210381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; throughout the entire function. edx will hold the pointer to the
211381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; deflate_state structure during the function's setup (before
212381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; entering the main loop.
213381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
214381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, [deflatestate]
215381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ecx, [curmatch]
216381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
217381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; uInt wmask = s->w_mask;
218381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; unsigned chain_length = s->max_chain_length;
219381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; if (s->prev_length >= s->good_match) {
220381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;     chain_length >>= 2;
221381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; }
222381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
223381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [edx + dsPrevLen]
224381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, [edx + dsGoodMatch]
225381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp eax, ebx
226381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [edx + dsWMask]
227381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, [edx + dsMaxChainLen]
228381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jl  LastMatchGood
229381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        shr ebx, 2
230381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLastMatchGood:
231381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
232381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; chainlen is decremented once beforehand so that the function can
233381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; use the sign flag instead of the zero flag for the exit test.
234381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; It is then shifted into the high word, to make room for the wmask
235381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; value, which it will always accompany.
236381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
237381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        dec ebx
238381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        shl ebx, 16
239381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        or  ebx, eax
240381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [chainlenwmask], ebx
241381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
242381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
243381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
244381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [edx + dsNiceMatch]
245381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, [edx + dsLookahead]
246381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp ebx, eax
247381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jl  LookaheadLess
248381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, eax
249381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLookaheadLess:  mov [nicematch], ebx
250381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
251381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; register Bytef *scan = s->window + s->strstart;
252381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
253381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov esi, [edx + dsWindow]
254381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [window], esi
255381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebp, [edx + dsStrStart]
256381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        lea edi, [esi + ebp]
257381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [scan], edi
258381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
259381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Determine how many bytes the scan ptr is off from being
260381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; dword-aligned.
261381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
262381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, edi
263381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        neg eax
264381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        and eax, 3
265381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [scanalign], eax
266381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
267381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
268381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;     s->strstart - (IPos)MAX_DIST(s) : NIL;
269381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
270381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [edx + dsWSize]
271381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        sub eax, MIN_LOOKAHEAD
272381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        sub ebp, eax
273381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jg  LimitPositive
274381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        xor ebp, ebp
275381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLimitPositive:
276381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
277381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; int best_len = s->prev_length;
278381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
279381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [edx + dsPrevLen]
280381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [bestlen], eax
281381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
282381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Store the sum of s->window + best_len in esi locally, and in esi.
283381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
284381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        add esi, eax
285381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [windowbestlen], esi
286381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
287381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; register ush scan_start = *(ushf*)scan;
288381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; register ush scan_end   = *(ushf*)(scan+best_len-1);
289381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Posf *prev = s->prev;
290381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
291381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        movzx   ebx, word ptr [edi]
292381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [scanstart], ebx
293381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        movzx   ebx, word ptr [edi + eax - 1]
294381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [scanend], ebx
295381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edi, [edx + dsPrev]
296381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
297381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Jump into the main loop.
298381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
299381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, [chainlenwmask]
300381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jmp short LoopEntry
301381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
302381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesalign 4
303381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
304381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; do {
305381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;     match = s->window + cur_match;
306381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;     if (*(ushf*)(match+best_len-1) != scan_end ||
307381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;         *(ushf*)match != scan_start) continue;
308381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;     [...]
309381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; } while ((cur_match = prev[cur_match & wmask]) > limit
310381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;          && --chain_length != 0);
311381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;
312381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Here is the inner loop of the function. The function will spend the
313381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; majority of its time in this loop, and majority of that time will
314381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; be spent in the first ten instructions.
315381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;
316381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Within this loop:
317381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; ebx = scanend
318381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; ecx = curmatch
319381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
320381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; esi = windowbestlen - i.e., (window + bestlen)
321381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; edi = prev
322381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; ebp = limit
323381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
324381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLookupLoop:
325381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        and ecx, edx
326381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        movzx   ecx, word ptr [edi + ecx*2]
327381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp ecx, ebp
328381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jbe LeaveNow
329381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        sub edx, 00010000h
330381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        js  LeaveNow
331381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLoopEntry:  movzx   eax, word ptr [esi + ecx - 1]
332381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp eax, ebx
333381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jnz LookupLoop
334381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [window]
335381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        movzx   eax, word ptr [eax + ecx]
336381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp eax, [scanstart]
337381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jnz LookupLoop
338381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
339381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Store the current value of chainlen.
340381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
341381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [chainlenwmask], edx
342381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
343381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Point edi to the string under scrutiny, and esi to the string we
344381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; are hoping to match it up with. In actuality, esi and edi are
345381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is
346381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; initialized to -(MAX_MATCH_8 - scanalign).
347381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
348381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov esi, [window]
349381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edi, [scan]
350381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        add esi, ecx
351381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [scanalign]
352381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, 0fffffef8h; -(MAX_MATCH_8)
353381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        lea edi, [edi + eax + 0108h] ;MAX_MATCH_8]
354381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        lea esi, [esi + eax + 0108h] ;MAX_MATCH_8]
355381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
356381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Test the strings for equality, 8 bytes at a time. At the end,
357381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; adjust edx so that it is offset to the exact byte that mismatched.
358381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;
359381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; We already know at this point that the first three bytes of the
360381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; strings match each other, and they can be safely passed over before
361381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; starting the compare loop. So what this code does is skip over 0-3
362381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; bytes, as much as necessary in order to dword-align the edi
363381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; pointer. (esi will still be misaligned three times out of four.)
364381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;
365381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; It should be confessed that this loop usually does not represent
366381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; much of the total running time. Replacing it with a more
367381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; straightforward "rep cmpsb" would not drastically degrade
368381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; performance.
369381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
370381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLoopCmps:
371381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [esi + edx]
372381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        xor eax, [edi + edx]
373381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jnz LeaveLoopCmps
374381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [esi + edx + 4]
375381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        xor eax, [edi + edx + 4]
376381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jnz LeaveLoopCmps4
377381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        add edx, 8
378381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jnz LoopCmps
379381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jmp short LenMaximum
380381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLeaveLoopCmps4: add edx, 4
381381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLeaveLoopCmps:  test    eax, 0000FFFFh
382381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jnz LenLower
383381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        add edx,  2
384381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        shr eax, 16
385381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLenLower:   sub al, 1
386381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        adc edx, 0
387381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
388381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Calculate the length of the match. If it is longer than MAX_MATCH,
389381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; then automatically accept it as the best possible match and leave.
390381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
391381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        lea eax, [edi + edx]
392381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edi, [scan]
393381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        sub eax, edi
394381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp eax, MAX_MATCH
395381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jge LenMaximum
396381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
397381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; If the length of the match is not longer than the best match we
398381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; have so far, then forget it and return to the lookup loop.
399381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
400381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, [deflatestate]
401381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, [bestlen]
402381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp eax, ebx
403381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jg  LongerMatch
404381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov esi, [windowbestlen]
405381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edi, [edx + dsPrev]
406381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, [scanend]
407381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, [chainlenwmask]
408381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jmp LookupLoop
409381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
410381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;         s->match_start = cur_match;
411381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;         best_len = len;
412381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;         if (len >= nice_match) break;
413381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;;         scan_end = *(ushf*)(scan+best_len-1);
414381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
415381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLongerMatch:    mov ebx, [nicematch]
416381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [bestlen], eax
417381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [edx + dsMatchStart], ecx
418381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp eax, ebx
419381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jge LeaveNow
420381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov esi, [window]
421381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        add esi, eax
422381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [windowbestlen], esi
423381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        movzx   ebx, word ptr [edi + eax - 1]
424381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edi, [edx + dsPrev]
425381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [scanend], ebx
426381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, [chainlenwmask]
427381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jmp LookupLoop
428381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
429381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Accept the current string, with the maximum possible length.
430381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
431381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLenMaximum: mov edx, [deflatestate]
432381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov dword ptr [bestlen], MAX_MATCH
433381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov [edx + dsMatchStart], ecx
434381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
435381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
436381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; return s->lookahead;
437381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
438381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLeaveNow:
439381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov edx, [deflatestate]
440381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov ebx, [bestlen]
441381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, [edx + dsLookahead]
442381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        cmp ebx, eax
443381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        jg  LookaheadRet
444381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        mov eax, ebx
445381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLookaheadRet:
446381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
447381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes;;; Restore the stack and return from whence we came.
448381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
449381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        add esp, LocalVarsSize
450381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        pop ebx
451381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        pop esi
452381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        pop edi
453381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        pop ebp
454381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
455381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes        ret
456381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; please don't remove this string !
457381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes; Your can freely use match686 in any free or commercial app if you don't remove the string in the binary!
458381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    db     0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998",0dh,0ah
459381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
460381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
461381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    IFDEF NOUNDERLINE
462381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    longest_match       endp
463381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    ELSE
464381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    _longest_match      endp
465381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    ENDIF
466381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
467381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    IFDEF NOUNDERLINE
468381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    match_init      proc near
469381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes                    ret
470381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    match_init      endp
471381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    ELSE
472381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    _match_init     proc near
473381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes                    ret
474381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    _match_init     endp
475381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes    ENDIF
476381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
477381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
478381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes_TEXT   ends
479381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesend
480