wok view memtest64/stuff/unlzsa2.S @ rev 25514

Add memtest64
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 16 14:18:05 2023 +0000 (15 months ago)
parents
children f2b4a9eb8bdd
line source
1 // Lzsa2Decode:
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 BP %bp
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 BP %ebp
18 #define SI %esi
19 #define DI %edi
20 #endif
22 MATCH_RUN_LEN = 7
23 LITERALS_RUN_LEN = 3
24 MIN_MATCH_SIZE = 2
25 MIN_LITERALS_SIZE = 0
27 #define PACKED_ONLY // assume no copy block, optional
28 //#define PARANOIA // cover rare cases, optional
30 lzsa2main:
31 #ifdef PARANOIA
32 cld
33 #endif
34 #ifdef FLAT16OUT
35 #define RAW_FORMAT
36 #endif
37 #ifndef RAW_FORMAT
38 # if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
39 xorw %cx, %cx
40 call normalize
41 # endif
42 # ifndef NO_LZSA2_HEADER
43 lodsw
44 cmpw $0x9E7B, %ax // magic
45 jne lzsa2main
46 lodsb
47 testb $0x20, %al // lzsa2
48 je lzsa2main
49 # endif
50 lzsa2block: // uncompress chunk
51 # if !defined(FLAT32) && !defined(FLAT16)
52 xorw %cx, %cx
53 call normalize
54 # endif
55 lodsw // block size
56 xchgw %ax, %cx
57 lodsb
58 # ifndef PACKED_ONLY
59 orb %al, %al
60 jns lzsa2compressed
61 # if !defined(FLAT32) && !defined(FLAT16OUT)
62 movw %cx, %dx
63 movb $0, %cl
64 movb $0, %dh
65 copytail:
66 call lzsa1movStr
67 xchg %dx, %cx
68 incw %cx
69 loop copytail
70 # else
71 movsb // copy block
72 copylp:
73 movsb // copy block
74 loop copylp // handle 64K case
75 # endif
76 jmp lzsa2block // end of block
77 lzsa2compressed:
78 jne lzsa2chunk // 64Kb block
79 # endif
80 jcxz lzsa2quit // bail if we hit EOD
81 # if !defined(FLAT16)
82 pushw %cx
83 xorw %cx, %cx
84 call normalize
85 # define NeedNormalize
86 popw %dx
87 addw %si, %dx
88 # else
89 movw %si, %dx
90 addw %cx, %dx
91 # endif
92 #else
93 # if !defined(FLAT16)
94 xorw %cx, %cx
95 call normalize
96 # define NeedNormalize
97 # endif
98 #endif
99 movb $0, %bh // no nibble stored
100 lzsa2chunk: // uncompress chunk
101 lodsb // get token XYZ|LL|MMM
102 movb %al, %bl // keep token in bl
103 movw $LITERALS_RUN_LEN+256*MIN_LITERALS_SIZE, %cx
104 shrb %cl, %al // shift literals length into place
105 call lzsa2len // %cl = LITERALS_RUN_LEN
106 #if defined(NeedNormalize)
107 pushw %bp
108 call lzsa2movLit // copy %cx literals from %ds:%si to %es:%di
109 popw %bp
110 #else
111 rep movsb // copy %cx literals from %ds:%si to %es:%di
112 #endif
113 #ifndef RAW_FORMAT
114 maxsi:
115 cmpw %dx, %si
116 jae lzsa2block // bail if we hit EOD
117 #endif
118 #ifdef FLAT32
119 orl $-1, %eax // set offset bits 31-8 to 1
120 #else
121 movb $-1, %ah // set offset bits 15-8 to 1
122 #endif
123 // XYZ
124 testb $0xC0, %bl // check match offset mode in token (X bit)
125 bt $5, %bx // move bit 5 to carry
126 js rep_match_or_large_offset
127 jne offset_9_bit
128 // 00Z 5-bit offset: read a nibble for offset bits 1-4 and use the inverted bit Z of the token as bit 0 of the offset.
129 // set bits 5-15 of the offset to 1.
130 call getByteFromNibbleAndC
131 jmp get_match_length
132 offset_9_bit:
133 // 01Z 9-bit offset: read a byte for offset bits 0-7 and use the inverted bit Z for bit 8 of the offset.
134 // set bits 9-15 of the offset to 1.
135 sbbb %cl, %ah // clear bit 8 if Z bit is clear
136 jmp get_match_length_0
138 getNibble:
139 xorb $0xF0, %bh // toggle nibble stored flags
140 movb %bh, %al
141 jns gotnibble
142 lodsb
143 movb $0xF0, %bh
144 orb %al, %bh
145 shrb $4, %al
146 gotnibble:
147 lzsa2quit:
148 ret
150 rep_match_or_large_offset:
151 jpe rep_match_or_16_bit
152 //10Z 13-bit offset: read a nibble for offset bits 9-12 and use the inverted bit Z for bit 8 of the offset,
153 // then read a byte for offset bits 0-7. set bits 13-15 of the offset to 1.
154 // substract 512 from the offset to get the final value.
155 call getByteFromNibbleAndC
156 subb $2, %al // substract 512
157 jmp get_match_length_1
158 rep_match_or_16_bit:
159 jc repeat_match // rep-match
160 //110 16-bit offset: read a byte for offset bits 8-15, then another byte for offset bits 0-7.
161 lodsb // Get 2-byte match offset
162 get_match_length_1:
163 xchgb %al, %ah
164 get_match_length_0:
165 lodsb // load match offset bits 0-7
166 get_match_length:
167 xchgw %ax, %bp // bp: offset
168 repeat_match:
169 //111 repeat offset: reuse the offset value of the previous match command.
171 movb %bl, %al // %al: original token
172 movw $MATCH_RUN_LEN+256*MIN_MATCH_SIZE, %cx
173 call lzsa2len
174 #ifdef RAW_FORMAT
175 jcxz lzsa2quit // bail if we hit EOD
176 #endif
177 #if !defined(FLAT32) && !defined(FLAT16OUT)
178 pushw %ds
179 pushw %si
180 movw %di, %si
181 addw %bp, %si
182 movw %es, %ax
183 jc axok
184 subb $0x10, %ah
185 axok:
186 .macro norm reg
187 movw %si, \reg
188 subw %si, %dx
189 andw $0xF, %si
190 addw %si, %dx
191 shrw $4, \reg
192 addw \reg, %ax
193 movw %ax, %ds
194 movw %di, \reg
195 andw $0xF, %di
196 shrw $4, \reg
197 movw %es, %ax
198 addw \reg, %ax
199 movw %ax, %es
200 .endm
201 pushw %bp
202 pushw %dx
203 # if defined(NeedNormalize) || defined(PARANOIA)
204 call lzsa2movStr // copy string
205 # else
206 norm %bp
207 rep movsb
208 # endif
209 popw %dx
210 popw %bp
211 popw %si
212 popw %ds
213 #else
214 xchg AX, SI // save %si
215 lea (BP,DI), SI
216 rep movsb %es:(SI), %es:(DI)
217 xchg AX, SI // restore %si
218 #endif
219 jmp lzsa2chunk
221 getByteFromNibbleAndC:
222 pushfw
223 call getNibble // get nibble for offset bits 0-3
224 popfw
225 rclb $1, %al
226 xorb $0xE1, %al // set offset bits 7-5 to 1
227 ret
229 lzsa2len: // get length in %cx
230 andb %cl, %al
231 cbw // clear %ah
232 cmpb %al, %cl
233 jne lzsa2minNumber // S=0-2, L=0-6
234 call getNibble
235 cmp $0xF, %al
236 jne lzsa2noExtraByte
237 addb %al, %ch
238 lodsb
239 lzsa2noExtraByte:
240 addb %cl, %ch
241 lzsa2minNumber:
242 addb %ch, %al
243 jnc lzsa2gotNumber // 0-255
244 #if 0
245 je lzsa2BigNumber
246 movb %al, %ah // S=256-767, L=256-1791
247 lodsb
248 .byte 0xB1 // mask lodsw with movb $0xAD, %cl
249 lzsa2BigNumber:
250 #endif
251 lodsw // 0-65535
252 lzsa2gotNumber:
253 xchgw %ax, %cx
254 ret
256 #if defined(NeedNormalize) || defined(PARANOIA)
257 # if defined(PARANOIA)
258 lzsa2movlp:
259 decw %ch
260 rep movsb
261 incw %ch
262 # endif
263 normalize:
264 lzsa2movLit:
265 movw %ds, %ax
266 lzsa2movStr:
267 norm %bp
268 # if defined(PARANOIA)
269 cmpb $0xFF, %ch // catch FFFX case
270 je lzsa2movlp
271 # endif
272 rep movsb
273 ret
274 #endif