Debian Codegraph @

qdos/match.s

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 ; match.a -- optional optimized asm version of longest match in deflate.c
10 ; Written by Jean-loup Gailly
11 ;
12 ; Adapted for the Amiga by Carsten Steger <[email protected]>
13 ; using the code in match.S.
14 ; The major change in this code consists of removing all unaligned
15 ; word accesses, because they cause 68000-based Amigas to crash.
16 ; For maximum speed, UNALIGNED_OK can be defined in Makefile.sasc.
17 ; The program will then only run on 68020-based Amigas, though.
18 ;
19 ; This code will run with registerized parameters too, unless SAS
20 ; changes parameter passing conventions between new releases of SAS/C.
21
22
23 ;;Cur_Match equr d0 ; Must be in d0!
24 ;;Best_Len equr d1
25 ;;Loop_Counter equr d2
26 ;;Scan_Start equr d3
27 ;;Scan_End equr d4
28 ;;Limit equr d5
29 ;;Chain_Length equr d6
30 ;;Scan_Test equr d7
31 ;;Scan equr a0
32 ;;Match equr a1
33 ;;Prev_Address equr a2
34 ;;Scan_Ini equr a3
35 ;;Match_Ini equr a4
36
37 MAX_MATCH equ 258
38 MIN_MATCH equ 3
39 WSIZE equ 32768
40 MAX_DIST equ WSIZE-MAX_MATCH-MIN_MATCH-1
41
42
43 .globl _max_chain_length
44 .globl _prev_length
45 .globl _prev
46 .globl _window
47 .globl _strstart
48 .globl _good_match
49 .globl _match_start
50 .globl _nice_match
51
52 .text
53 .globl _match_init
54 .globl _longest_match
55
56 _match_init:
57 rts
58
59
60 _longest_match:
61 move.l 4(sp),d0
62 movem.l d2-d7/a2-a4,-(sp)
63 move.l _max_chain_length,d6
64 move.l _prev_length,d1
65 lea _prev,a2
66 lea _window+MIN_MATCH,a4
67 move.l _strstart,d5
68 move.l a4,a3
69 add.l d5,a3
70 subi.w #MAX_DIST,d5
71 bhi limit_ok
72 moveq #0,d5
73 limit_ok:
74 cmp.l _good_match,d1
75 bcs length_ok
76 lsr.l #2,d6
77 length_ok:
78 subq.l #1,d6
79
80 move.b -MIN_MATCH(a3),d3
81 lsl.w #8,d3
82 move.b -MIN_MATCH+1(a3),d3
83 move.b -MIN_MATCH-1(a3,d1),d4
84 lsl.w #8,d4
85 move.b -MIN_MATCH(a3,d1),d4
86
87 bra do_scan
88
89 long_loop:
90
91 move.b -MIN_MATCH-1(a3,d1),d4
92 lsl.w #8,d4
93 move.b -MIN_MATCH(a3,d1),d4
94
95 short_loop:
96 lsl.w #1,d0
97 move.w 0(a2,d0.l),d0
98 cmp.w d5,d0
99 dbls d6,do_scan
100 bra return
101
102 do_scan:
103 move.l a4,a1
104 add.l d0,a1
105
106 move.b -MIN_MATCH-1(a1,d1),d7
107 lsl.w #8,d7
108 move.b -MIN_MATCH(a1,d1),d7
109 cmp.w d7,d4
110 bne short_loop
111 move.b -MIN_MATCH(a1),d7
112 lsl.w #8,d7
113 move.b -MIN_MATCH+1(a1),d7
114 cmp.w d7,d3
115 bne short_loop
116
117 move.w #(MAX_MATCH-MIN_MATCH),d2
118 move.l a3,a0
119
120 scan_loop:
121 cmpm.b (a1)+,(a0)+
122 dbne d2,scan_loop
123
124 sub.l a3,a0
125 addq.l #(MIN_MATCH-1),a0
126 cmp.l d1,a0
127 bls short_loop
128 move.l a0,d1
129 move.l d0,_match_start
130 cmp.l _nice_match,d1
131 bcs long_loop
132 return:
133 move.l d1,d0
134 movem.l (sp)+,d2-d7/a2-a4
135 rts
136 end
137
138