Debian Codegraph @

amiga/match_68.a

raw
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 ; This is a 68000 assembly language version of the Zip function
10 ; longest_match(). It is written for any 680x0 based computer, but at this
11 ; time the feature for runtime testing of CPU type is only supported for the
12 ; Amiga. Hopefully a similar test for the Macintosh is possible, and for any
13 ; other system that supports both 68000 and 68020+ CPUs. This is written by
14 ; Paul Kienitz, partially derived from a simpler version by Carsten Steger,
15 ; derived in turn from a 386 assembly function by Jean-loup Gailly and Kai Uwe
16 ; Rommel... but also based directly on the C original.
17 ;
18 ; The main difference of this from other longest_match() implementations is
19 ; that it includes both byte based and word based versions of the function,
20 ; and various symbols can be defined to select whether to use one routine or
21 ; the other, or to do a platform-specific test at runtime. The symbols that
22 ; can be used to select behavior are as follows:
23 ;
24 ; CPU020 if defined, use 68020 instructions always
25 ; CPUTEST if defined, check at runtime for CPU type. Another symbol
26 ; specifying the platform-specific test must be used with this.
27 ; If neither of these is defined, use 68000 instructions only.
28 ; AMIGA use Amiga-specific test for 68020, if CPUTEST defined. Also
29 ; tells it to let a0/a1/d1 be clobbered by functions.
30 ; ATSIGN define entry symbols in @foo form as well as _foo, with
31 ; @longest_match taking its parm in d0 instead of on the stack.
32 ; WSIZE if defined, determines the sliding window size for deflate;
33 ; the default is 32K. If you have reduced WSIZE for the C code,
34 ; make sure that this module is assembled with an equivalent
35 ; "-dWSIZE=<whatever>" (or "-e...") switch.
36 ;
37 ; NOTE: no provision is made for 16 bit ints. All external int variables are
38 ; treated as 32 bit values. This also assumes that longest_match's result is
39 ; returned in D0.
40
41 IFND CPU020
42 IFND CPUTEST
43 CPU000 equ 1
44 ENDC
45 ENDC
46
47 ; global variables:
48 xref _max_chain_length ; unsigned int
49 xref _prev_length ; unsigned int
50 xref _match_start ; unsigned int
51 xref _strstart ; unsigned int
52 xref _good_match ; signed int
53 xref _nice_match ; signed int
54 xref _window ; array of unsigned char
55 xref _prev ; array of unsigned short
56
57 ; our entry points:
58 xdef _match_init ; void match_init(void);
59 xdef _longest_match ; int longest_match(unsigned cur_match);
60 IFD ATSIGN
61 xdef @match_init ; for SAS assembler
62 xdef @longest_match ; ditto
63 ENDC
64
65 ; flag variable for remembering CPU type:
66 IFD CPUTEST
67 section cpuflag,data
68 is020: ds.w 1
69 ENDC
70
71
72 section match,code
73 _match_init:
74 IFD ATSIGN
75 @match_init:
76 ENDC
77
78 IFD CPUTEST ; now check for platform type
79 IFD AMIGA ; Amiga specific test for '020 CPU:
80
81 xref _SysBase
82
83 NOLIST
84 INCLUDE 'exec/execbase.i'
85 LIST
86
87 clr.w is020 ; default value is 68000
88 move.l _SysBase,a0
89 btst #AFB_68020,AttnFlags+1(a0)
90 beq.s cheap
91 move.w #1,is020
92
93 cheap:
94 ELSE ; !AMIGA
95
96 !! Write an '020-detector for your system here!
97
98 ENDC ; AMIGA
99 ENDC ; CPUTEST
100 rts ; match_init consists only of rts if CPUTEST unset
101
102
103 IFD AMIGA
104 SAVEREGS reg d3-d7/a2/a3/a5 ; don't protect d0/d1/a0/a1
105 ELSE
106 SAVEREGS reg d1/d3-d7/a0-a3/a5 ; protect all but d0 return val
107 ENDC
108
109 Cur_Match equr d0 ; Must be in d0!
110 Best_Len equr d1
111 Scan_Start equr d3
112 Scan_End equr d4
113 Limit equr d5
114 Chain_Length equr d6
115 Scan_Test equr d7
116 Scan equr a0
117 Match equr a1
118 Prev_Address equr a2
119 Scan_Ini equr a3
120 Match_Ini equr a5
121
122
123 MAX_MATCH equ 258
124 MIN_MATCH equ 3
125 IFND WSIZE
126 WSIZE equ 32768
127 ENDC
128 MAX_DIST equ WSIZE-MAX_MATCH-MIN_MATCH-1
129
130 _longest_match:
131 move.l 4(sp),Cur_Match ; stack arg to register
132 IFD ATSIGN
133 @longest_match:
134 ENDC
135 movem.l SAVEREGS,-(sp)
136
137 ; setup steps common to byte and word versions:
138 move.l _max_chain_length,Chain_Length
139 move.l _prev_length,Best_Len
140 lea _prev,Prev_Address
141 lea _window,Match_Ini
142 move.l _strstart,Limit
143 move.l Match_Ini,Scan_Ini
144 addq #MIN_MATCH,Match_Ini
145 add.l Limit,Scan_Ini
146 subi.w #MAX_DIST,Limit
147 bhi.s limit_ok
148 moveq #0,Limit
149 limit_ok:
150 cmp.l _good_match,Best_Len
151 bcs.s length_ok
152 lsr.l #2,Chain_Length
153 length_ok:
154 subq.l #1,Chain_Length
155
156 IFD CPUTEST
157 tst.w is020 ; can we use '020 stuff today?
158 bne WORD_match
159 ENDC
160
161 IFND CPU020
162
163 ; for 68000 or 68010, use byte operations:
164 moveq #0,Scan_Start ; clear 2nd and 4th bytes, use 1st & 3rd
165 moveq #0,Scan_End
166 moveq #0,Scan_Test
167 move.b (Scan_Ini),Scan_Start
168 swap Scan_Start
169 move.b 1(Scan_Ini),Scan_Start
170 move.b -1(Scan_Ini,Best_Len),Scan_End
171 swap Scan_End
172 move.b 0(Scan_Ini,Best_Len),Scan_End
173 bra.s bdo_scan
174
175 blong_loop:
176 move.b -1(Scan_Ini,Best_Len),Scan_End
177 swap Scan_End
178 move.b 0(Scan_Ini,Best_Len),Scan_End
179
180 bshort_loop:
181 add.w Cur_Match,Cur_Match
182 move.w 0(Prev_Address,Cur_Match.l),Cur_Match
183 cmp.l Limit,Cur_Match
184 dbls Chain_Length,bdo_scan
185 bra return
186
187 bdo_scan:
188 move.l Match_Ini,Match
189 add.l Cur_Match,Match
190 move.b -MIN_MATCH-1(Match,Best_Len),Scan_Test
191 swap Scan_Test
192 move.b -MIN_MATCH(Match,Best_Len),Scan_Test
193 cmp.l Scan_Test,Scan_End
194 bne.s bshort_loop
195 move.b -MIN_MATCH(Match),Scan_Test
196 swap Scan_Test
197 move.b -MIN_MATCH+1(Match),Scan_Test
198 cmp.l Scan_Test,Scan_Start
199 bne.s bshort_loop
200 move.w #(MAX_MATCH-MIN_MATCH),Scan_Test
201 lea MIN_MATCH(Scan_Ini),Scan
202
203 bscan_loop:
204 cmpm.b (Match)+,(Scan)+
205 dbne Scan_Test,bscan_loop
206 subq #1,Scan
207
208 sub.l Scan_Ini,Scan
209 cmp.l Best_Len,Scan
210 bls.s bshort_loop
211 move.l Scan,Best_Len
212 move.l Cur_Match,_match_start
213 cmp.l _nice_match,Best_Len
214 bcs.s blong_loop
215 IFD CPUTEST
216 bra return
217 ENDC
218
219 ENDC ; !CPU020
220
221 IFND CPU000
222
223 ; for 68020 or higher, use word operations even on odd addresses:
224 WORD_match:
225 move.w (Scan_Ini),Scan_Start
226 move.w -1(Scan_Ini,Best_Len),Scan_End
227 bra.s wdo_scan
228
229 wlong_loop:
230 move.w -1(Scan_Ini,Best_Len),Scan_End
231
232 wshort_loop:
233 add.w Cur_Match,Cur_Match
234 move.w (Prev_Address,Cur_Match.l),Cur_Match
235 cmp.l Limit,Cur_Match
236 dbls Chain_Length,wdo_scan
237 bra.s return
238
239 wdo_scan:
240 move.l Match_Ini,Match
241 add.l Cur_Match,Match
242 cmp.w -MIN_MATCH-1(Match,Best_Len),Scan_End
243 bne.s wshort_loop
244 cmp.w -MIN_MATCH(Match),Scan_Start
245 bne.s wshort_loop
246 moveq #((MAX_MATCH-MIN_MATCH)/2),Scan_Test ; value = 127
247 lea MIN_MATCH(Scan_Ini),Scan
248
249 wscan_loop:
250 cmpm.w (Match)+,(Scan)+
251 dbne Scan_Test,wscan_loop
252 subq #2,Scan
253 move.b -MIN_MATCH+1(Match),Scan_Test
254 cmp.b (Scan),Scan_Test
255 bne steven
256 addq #1,Scan
257 steven:
258 sub.l Scan_Ini,Scan
259 cmp.l Best_Len,Scan
260 bls.s wshort_loop
261 move.l Scan,Best_Len
262 move.l Cur_Match,_match_start
263 cmp.l _nice_match,Best_Len
264 bcs.s wlong_loop
265
266 ENDC ; !CPU000
267
268 return:
269 move.l Best_Len,d0 ; function return value
270 movem.l (sp)+,SAVEREGS
271 rts
272
273 end