]> git.cworth.org Git - gzip/blob - amiga/match.a
Avoid creating an undersized buffer for the hufts table.
[gzip] / amiga / match.a
1 ; match.a -- optional optimized asm version of longest match in deflate.c
2 ; Copyright (C) 1992-1993 Jean-loup Gailly
3 ; This is free software; you can redistribute it and/or modify it under the
4 ; terms of the GNU General Public License, see the file COPYING.
5  
6 ; $Id: match.a,v 1.1 1993/03/11 16:05:57 jloup Exp $
7 ;
8 ; Adapted for the Amiga by Carsten Steger <stegerc@informatik.tu-muenchen.de>
9 ; using the code in match.S.
10 ; The major change in this code consists of removing all unaligned
11 ; word accesses, because they cause 68000-based Amigas to crash.
12 ; For maximum speed, UNALIGNED_OK can be defined in Makefile.sasc.
13 ; The program will then only run on 68020-based Amigas, though.
14 ;
15 ; This code will run with registerized parameters too, unless SAS
16 ; changes parameter passing conventions between new releases of SAS/C.
17
18
19 Cur_Match       reg     d0      ; Must be in d0!
20 Best_Len        reg     d1
21 Loop_Counter    reg     d2
22 Scan_Start      reg     d3
23 Scan_End        reg     d4
24 Limit           reg     d5
25 Chain_Length    reg     d6
26 Scan_Test       reg     d7
27 Scan            reg     a0
28 Match           reg     a1
29 Prev_Address    reg     a2
30 Scan_Ini        reg     a3
31 Match_Ini       reg     a4
32
33 MAX_MATCH       equ     258
34 MIN_MATCH       equ     3
35 WSIZE           equ     32768
36 MAX_DIST        equ     WSIZE-MAX_MATCH-MIN_MATCH-1
37
38
39         xref    _max_chain_length
40         xref    _prev_length
41         xref    _prev
42         xref    _window
43         xref    _strstart
44         xref    _good_match
45         xref    _match_start
46         xref    _nice_match
47
48
49         section match,code
50
51         xdef    _match_init
52         xdef    @match_init
53         xdef    _longest_match
54         xdef    @longest_match
55
56
57 _match_init:
58 @match_init:
59         rts
60
61
62 _longest_match:
63         move.l  4(sp),Cur_Match
64 @longest_match:
65         ifd     UNALIGNED_OK
66         movem.l d2-d6/a2-a4,-(sp)
67         else
68         movem.l d2-d7/a2-a4,-(sp)
69         endc
70         move.l  _max_chain_length,Chain_Length
71         move.l  _prev_length,Best_Len
72         lea     _prev,Prev_Address
73         lea     _window+MIN_MATCH,Match_Ini
74         move.l  _strstart,Limit
75         move.l  Match_Ini,Scan_Ini
76         add.l   Limit,Scan_Ini
77         subi.w  #MAX_DIST,Limit
78         bhi.b   limit_ok
79         moveq   #0,Limit
80 limit_ok:
81         cmp.l   _good_match,Best_Len
82         bcs.b   length_ok
83         lsr.l   #2,Chain_Length
84 length_ok:
85         subq.l  #1,Chain_Length
86
87         ifd     UNALIGNED_OK
88
89         move.w  -MIN_MATCH(Scan_Ini),Scan_Start
90         move.w  -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
91
92         else
93
94         move.b  -MIN_MATCH(Scan_Ini),Scan_Start
95         lsl.w   #8,Scan_Start
96         move.b  -MIN_MATCH+1(Scan_Ini),Scan_Start
97         move.b  -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
98         lsl.w   #8,Scan_End
99         move.b  -MIN_MATCH(Scan_Ini,Best_Len),Scan_End
100
101         endc
102
103         bra.b   do_scan
104
105 long_loop:
106
107         ifd     UNALIGNED_OK
108
109         move.w  -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
110
111         else
112
113         move.b  -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
114         lsl.w   #8,Scan_End
115         move.b  -MIN_MATCH(Scan_Ini,Best_Len),Scan_End
116
117         endc
118
119 short_loop:
120         lsl.w   #1,Cur_Match
121         move.w  0(Prev_Address,Cur_Match),Cur_Match
122         cmp.w   Limit,Cur_Match
123         dbls    Chain_Length,do_scan
124         bra.b   return
125
126 do_scan:
127         move.l  Match_Ini,Match
128         add.l   Cur_Match,Match
129
130         ifd     UNALIGNED_OK
131
132         cmp.w   -MIN_MATCH-1(Match,Best_Len),Scan_End
133         bne.b   short_loop
134         cmp.w   -MIN_MATCH(Match),Scan_Start
135         bne.b   short_loop
136
137         else
138
139         move.b  -MIN_MATCH-1(Match,Best_Len),Scan_Test
140         lsl.w   #8,Scan_Test
141         move.b  -MIN_MATCH(Match,Best_Len),Scan_Test
142         cmp.w   Scan_Test,Scan_End
143         bne.b   short_loop
144         move.b  -MIN_MATCH(Match),Scan_Test
145         lsl.w   #8,Scan_Test
146         move.b  -MIN_MATCH+1(Match),Scan_Test
147         cmp.w   Scan_Test,Scan_Start
148         bne.b   short_loop
149
150         endc
151
152         move.w  #(MAX_MATCH-MIN_MATCH),Loop_Counter
153         move.l  Scan_Ini,Scan
154 scan_loop:
155         cmpm.b  (Match)+,(Scan)+
156         dbne    Loop_Counter,scan_loop
157
158         sub.l   Scan_Ini,Scan
159         addq.l  #(MIN_MATCH-1),Scan
160         cmp.l   Best_Len,Scan
161         bls.b   short_loop
162         move.l  Scan,Best_Len
163         move.l  Cur_Match,_match_start
164         cmp.l   _nice_match,Best_Len
165         bcs.b   long_loop
166 return:
167         move.l  Best_Len,d0
168         ifd     UNALIGNED_OK
169         movem.l (sp)+,d2-d6/a2-a4
170         else
171         movem.l (sp)+,d2-d7/a2-a4
172         endc
173         rts
174
175         end