| 1 |
;=========================================================================== |
| 2 |
; Copyright (c) 1990-1999 Info-ZIP. All rights reserved. |
| 3 |
; |
| 4 |
; See the accompanying file LICENSE, version 1999-Oct-05 or later |
| 5 |
; (the contents of which are also included in zip.h) for terms of use. |
| 6 |
; If, for some reason, both of these files are missing, the Info-ZIP license |
| 7 |
; also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html |
| 8 |
;=========================================================================== |
| 9 |
; match32.asm by Jean-loup Gailly. |
| 10 |
|
| 11 |
; match32.asm, optimized version of longest_match() in deflate.c |
| 12 |
; To be used only with 32 bit flat model. To simplify the code, the option |
| 13 |
; -DDYN_ALLOC is not supported. |
| 14 |
; This file is only optional. If you don't have an assembler, use the |
| 15 |
; C version (add -DNO_ASM to CFLAGS in makefile and remove match.o |
| 16 |
; from OBJI). If you have reduced WSIZE in zip.h, then make sure this is |
| 17 |
; assembled with an equivalent -DWSIZE=<whatever>. |
| 18 |
; |
| 19 |
; Win32 (Windows NT) version - 1994/04/13 by Steve Salisbury |
| 20 |
; * works with Microsoft MASM 6.1X and Microsoft Visual C++ / 32-bit edition |
| 21 |
; |
| 22 |
; The code in this file has been copied verbatim from match32.{asm|S}; |
| 23 |
; only the assembler syntax and metacommands have been adapted to |
| 24 |
; the habits of the free LCC-Win32 C compiler package. |
| 25 |
; IMPORTANT NOTE to the Info-ZIP editors: |
| 26 |
; The TAB characters in this source file are required by the parser of |
| 27 |
; the LCC-Win32 assembler program and MUST NOT be removed!! |
| 28 |
; |
| 29 |
;============================================================================== |
| 30 |
; |
| 31 |
; Do NOT assemble this source if external crc32 routine from zlib gets used. |
| 32 |
; |
| 33 |
|
| 34 |
|
| 35 |
;/* This version is for 386 Unix or OS/2 in 32 bit mode. |
| 36 |
; * Warning: it uses the AT&T syntax: mov source,dest |
| 37 |
; * This file is only optional. If you want to force the C version, |
| 38 |
; * add -DNO_ASM to CFLAGS in Makefile and set OBJA to an empty string. |
| 39 |
; * If you have reduced WSIZE in (g)zip.h, then make sure this is |
| 40 |
; * assembled with an equivalent -DWSIZE=<whatever>. |
| 41 |
; * This version assumes static allocation of the arrays (-DDYN_ALLOC not used). |
| 42 |
; */ |
| 43 |
|
| 44 |
.text |
| 45 |
.file "match.S" |
| 46 |
|
| 47 |
|
| 48 |
.text |
| 49 |
.type _match_init,function |
| 50 |
|
| 51 |
_match_init: |
| 52 |
ret |
| 53 |
_$98: |
| 54 |
.size _match_init,_$98-_match_init |
| 55 |
.globl _match_init |
| 56 |
|
| 57 |
;/*----------------------------------------------------------------------- |
| 58 |
; * Set match_start to the longest match starting at the given string and |
| 59 |
; * return its length. Matches shorter or equal to prev_length are discarded, |
| 60 |
; * in which case the result is equal to prev_length and match_start is |
| 61 |
; * garbage. |
| 62 |
; * IN assertions: cur_match is the head of the hash chain for the current |
| 63 |
; * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 |
| 64 |
; */ |
| 65 |
|
| 66 |
.align 4 |
| 67 |
.type _longest_match,function |
| 68 |
|
| 69 |
_longest_match: ;/* int longest_match(cur_match) */ |
| 70 |
|
| 71 |
; cur_match equ 20(%esp) |
| 72 |
; /* return address */ /* esp+16 */ |
| 73 |
push %ebp |
| 74 |
push %edi |
| 75 |
;/* esp+8 */ |
| 76 |
push %esi |
| 77 |
;/* esp+4 */ |
| 78 |
push %ebx |
| 79 |
;/* esp */ |
| 80 |
|
| 81 |
;/* |
| 82 |
; * match equ esi |
| 83 |
; * scan equ edi |
| 84 |
; * chain_length equ ebp |
| 85 |
; * best_len equ ebx |
| 86 |
; * limit equ edx |
| 87 |
; */ |
| 88 |
mov 20(%esp),%esi |
| 89 |
mov _strstart,%edx |
| 90 |
mov _max_chain_length,%ebp |
| 91 |
mov %edx,%edi |
| 92 |
sub $(32768-262),%edx |
| 93 |
cld |
| 94 |
jae limit_ok |
| 95 |
sub %edx,%edx |
| 96 |
limit_ok: |
| 97 |
add $2+_window,%edi |
| 98 |
mov _prev_length,%ebx |
| 99 |
movw -2(%edi),%cx |
| 100 |
movw -3(%ebx,%edi),%ax |
| 101 |
cmp _good_match,%ebx |
| 102 |
jb do_scan |
| 103 |
shr $2,%ebp |
| 104 |
jmp do_scan |
| 105 |
|
| 106 |
.align 4 |
| 107 |
long_loop: |
| 108 |
;/* at this point, edi == scan+2, esi == cur_match */ |
| 109 |
movw -3(%ebx,%edi),%ax |
| 110 |
movw -2(%edi),%cx |
| 111 |
short_loop: |
| 112 |
;/* |
| 113 |
; * at this point, di == scan+2, si == cur_match, |
| 114 |
; * ax = scan[best_len-1..best_len] and cx = scan[0..1] |
| 115 |
; */ |
| 116 |
and $(32768-1), %esi |
| 117 |
dec %ebp |
| 118 |
movw _prev(,%esi,2),%si |
| 119 |
jz the_end |
| 120 |
cmp %edx,%esi |
| 121 |
jbe the_end |
| 122 |
do_scan: |
| 123 |
cmpw _window-1(%ebx,%esi),%ax |
| 124 |
jne short_loop |
| 125 |
cmpw _window(%esi),%cx |
| 126 |
jne short_loop |
| 127 |
|
| 128 |
add $2+_window,%esi |
| 129 |
mov $((258>>1)-1),%ecx |
| 130 |
mov %edi,%eax |
| 131 |
repe; cmpsw |
| 132 |
;/* loop until mismatch */ |
| 133 |
je maxmatch |
| 134 |
;/* match of length MAX_MATCH? */ |
| 135 |
mismatch: |
| 136 |
movb -2(%edi),%cl |
| 137 |
xchg %edi,%eax |
| 138 |
subb -2(%esi),%cl |
| 139 |
sub %edi,%eax |
| 140 |
sub $2+_window,%esi |
| 141 |
sub %eax,%esi |
| 142 |
subb $1,%cl |
| 143 |
adc $0,%eax |
| 144 |
cmp %ebx,%eax |
| 145 |
jle long_loop |
| 146 |
mov %esi,_match_start |
| 147 |
mov %eax,%ebx |
| 148 |
cmp _nice_match,%eax |
| 149 |
; /* len >= nice_match ? */ |
| 150 |
jl long_loop |
| 151 |
the_end: |
| 152 |
mov %ebx,%eax |
| 153 |
pop %ebx |
| 154 |
pop %esi |
| 155 |
pop %edi |
| 156 |
pop %ebp |
| 157 |
ret |
| 158 |
.align 4 |
| 159 |
maxmatch: |
| 160 |
cmpsb |
| 161 |
jmp mismatch |
| 162 |
_$99: |
| 163 |
|
| 164 |
.size _longest_match,_$99-_longest_match |
| 165 |
.globl _longest_match |
| 166 |
|
| 167 |
.extern _nice_match |
| 168 |
.extern _good_match |
| 169 |
.extern _max_chain_length |
| 170 |
.extern _match_start |
| 171 |
.extern _strstart |
| 172 |
.extern _prev_length |
| 173 |
.extern _prev |
| 174 |
.extern _window |