wok view memtest/stuff/unlz4.S @ rev 25708

Add shrinkler
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jul 25 12:01:54 2024 +0000 (11 months ago)
parents a794ec0a6495
children 1b965c2713aa
line source
1 // Lz4Decode:
2 #ifndef FLAT32
3 // input ds:si=inStream, es:di=outStream
4 // output outStream[], ds:si, es:di
5 .code16
6 #define AX %ax
7 #define BX %bx
8 #define CX %cx
9 #define SI %si
10 #define DI %di
11 #else
12 // input esi=inStream, edi=outStream
13 // output outStream[], ds:esi, es:edi
14 .code32
15 #define AX %eax
16 #define BX %ebx
17 #define CX %ecx
18 #define SI %esi
19 #define DI %edi
20 #endif
22 #if defined(FLAT16OUT) || defined(ONLY8086)
23 #define cAX %ax
24 #define cCX %cx
25 #define cDX %dx
26 #else
27 #define cAX %eax
28 #define cCX %ecx
29 #define cDX %edx
30 #endif
32 #define ARCHIVE_MAGICNUMBER 0x184C2102
34 //#define PARANOIA // cover rare cases, optional
36 .macro norm1 reg, seg, ptr
37 movw \seg, %ax
38 movw \ptr, \reg
39 #ifdef ONLY8086
40 shrw %cl, \reg
41 #else
42 shrw $4, \reg
43 #endif
44 #ifdef BACKWARD
45 subw $0xFFF, %ax
46 orw $0xFFF0, \ptr
47 #else
48 andw $0xF, \ptr
49 #endif
50 addw \reg, %ax
51 movw %ax, \seg
52 .endm
54 .macro norm reg
55 #ifdef ONLY8086
56 pushw %cx
57 movb $4, %cl
58 #endif
59 #ifndef FLAT16
60 norm1 \reg, %ds, %si
61 #endif
62 norm1 \reg, %es, %di
63 #ifdef ONLY8086
64 popw %cx
65 #endif
66 .endm
68 lz4main:
69 #ifdef PARANOIA
70 cld
71 # if !defined(FLAT32) && !defined(FLAT16OUT)
72 xorl %cx, %cx
73 call lz4mov
74 # endif
75 #endif
76 #if defined(FLAT16OUT) || defined(ONLY8086)
77 lodsw // get chunkSize
78 # ifndef NO_LZ4_HEADER
79 cmpw $ARCHIVE_MAGICNUMBER&0xFFFF, %ax
80 # endif
81 xchg %ax, %dx
82 lodsw
83 # ifndef NO_LZ4_HEADER
84 jne chkeof
85 cmpw $ARCHIVE_MAGICNUMBER>>16, %ax
86 je lz4main
87 chkeof:
88 # endif
89 # ifdef PARANOIA
90 orw %ax, %dx // end of file ?
91 je lz4quit
92 # endif
93 # ifndef FLAT16OUT
94 xchgw %ax, %bp
95 subw $1, %dx
96 sbbw $0, %bp
97 # endif
98 #else
99 lodsl // get chunkSize
100 # ifndef NO_LZ4_HEADER
101 cmpl $ARCHIVE_MAGICNUMBER, %eax
102 je lz4main
103 # endif
104 # ifdef PARANOIA
105 orl %eax, %eax // end of file ?
106 je lz4quit
107 # endif
108 xchgl %eax, %edx
109 #endif
110 lz4chunk: // uncompress chunk
111 lodsb // get token
112 pushw %ax
113 #ifdef ONLY8086
114 movb $4, %cl
115 shrb %cl, %al
116 #else
117 shrb $4, %al
118 #endif
119 call lz4len // get literal length
120 #if !defined(FLAT16OUT) && defined(ONLY8086)
121 subw %cx, %dx // count literal
122 sbbw $0, %bp
123 #else
124 sub cCX, cDX // count literal
125 #endif
126 #if !defined(FLAT32) && !defined(FLAT16OUT) && (!defined(FLAT16) || !defined(PARANOIA))
127 #define NeedLz4mov
128 call lz4mov // copy literals
129 #else
130 rep movsb
131 #endif
132 popw %bx
133 #if !defined(FLAT16OUT) && defined(ONLY8086)
134 subw $1+2, %dx // count token & string address
135 sbbw $0, %bp
136 jb lz4quit
137 lz4cont:
138 #else
139 sub $1+2, cDX // count token & string address
140 jbe lz4quit
141 #endif
142 lodsw // get string address
143 xchg AX, BX
144 call lz4len // get string length
145 add $4, CX
146 #if !defined(FLAT32) && !defined(FLAT16OUT)
147 pushw %ds
148 pushw %si
149 movw %di, %si
150 movw %es, %ax
151 # ifdef BACKWARD
152 addw %bx, %si
153 jnc axok
154 addb $0x10, %ah
155 # else
156 subw %bx, %si
157 jnc axok
158 subb $0x10, %ah
159 # endif
160 axok:
161 # if !defined (NeedLz4mov)
162 norm %bx
163 rep movsb
164 # else
165 call lz4movStr // copy string
166 # endif
167 popw %si
168 popw %ds
169 #else
170 # ifdef FASTFILL
171 cmp $FASTFILL,BX
172 jbe lz4fast
173 # endif
174 lz4notfast:
175 xchg AX, SI
176 # ifdef BACKWARD
177 lea (DI,BX), SI
178 # else
179 mov DI, SI
180 sub BX, SI
181 # endif
182 # ifdef ONLY8086
183 lz4movsb:
184 movsb %es:(SI), %es:(DI) // NMOS 8088/8086 workaround.
185 loop lz4movsb
186 # else
187 rep movsb %es:(SI), %es:(DI)
188 # endif
189 xchg AX, SI
190 # ifdef FASTFILL
191 lz4fast:
192 # if FASTFILL == 1
193 movb %es:-1(DI), %al
194 rep stosb
195 # endif
196 # if FASTFILL >= 2
197 movw %es:-2(DI), %ax
198 je lz4fastword
199 movb %al, %ah
200 lz4fastword:
201 shr $1, CX
202 rep stosw
203 jnc lz4chunk
204 stosb
205 # endif
206 # endif
207 jmp lz4chunk
208 #endif
210 #if defined(NeedLz4mov)
211 # if defined(PARANOIA)
212 lz4movlp:
213 xchgw %ax, %cx
214 movw $0x7800, %cx
215 rep movsw
216 xchgw %ax, %cx
217 sub $0xF0, %ch
218 # endif
219 lz4mov:
220 movw %ds, %ax
221 lz4movStr:
222 norm %bx
223 # if defined(PARANOIA)
224 cmp $0xFF, %ch // catch FFFX case
225 jz lz4movlp
226 # endif
227 rep movsb
228 ret
229 #endif
231 lz4len: // get length in %ecx
232 and $0xF, cAX
233 mov cAX, cCX
234 cmpb $0xF, %al
235 jne lz4quit
236 lz4len2:
237 lodsb
238 #if !defined(FLAT16OUT) && defined(ONLY8086)
239 subw $1, %dx // remaining chunk size
240 sbbw $0, %bp
241 #else
242 dec cDX // remaining chunk size
243 #endif
244 add AX, CX
245 cmpb $0xFF, %al
246 je lz4len2
247 lz4quit:
248 ret