wok view memtest64/stuff/unlzsa1.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 // Lzsa1Decode:
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 SI %si
9 #define DI %di
10 #else
11 // input esi=inStream, edi=outStream
12 // output outStream[], ds:esi, es:edi
13 .code32
14 #define AX %eax
15 #define BX %ebx
16 #define SI %esi
17 #define DI %edi
18 #endif
20 MATCH_RUN_LEN = 15
21 LITERALS_RUN_LEN = 7
22 MIN_MATCH_SIZE = 3
23 MIN_LITERALS_SIZE = 0
25 #define PACKED_ONLY // assume no copy block, optional
26 //#define PARANOIA // cover rare cases, optional
28 lzsa1main:
29 #ifdef PARANOIA
30 cld
31 #endif
32 #ifdef FLAT16OUT
33 #define RAW_FORMAT
34 #endif
35 #ifndef RAW_FORMAT
36 # if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
37 xorw %cx, %cx
38 call normalize
39 # endif
40 # ifndef NO_LZSA1_HEADER
41 lodsw
42 cmpw $0x9E7B, %ax // magic
43 jne lzsa1main
44 lodsb
45 cmpb $0, %al // lzsa1
46 jne lzsa1main
47 # endif
48 lzsa1block: // uncompress chunk
49 lodsw // block size
50 xchgw %ax, %cx
51 lodsb
52 # ifndef PACKED_ONLY
53 orb %al, %al
54 jns lzsa1compressed
55 # if !defined(FLAT32) && !defined(FLAT16OUT)
56 movw %cx, %dx
57 movb $0, %cl
58 movb $0, %dh
59 copytail:
60 call lzsa1movStr
61 xchg %dx, %cx
62 incw %cx
63 loop copytail
64 # else
65 movsb // copy block
66 copylp:
67 movsb // copy block
68 loop copylp // handle 64K case
69 # endif
70 jmp lzsa1block // end of block
71 lzsa1compressed:
72 jne lzsa1chunk // 64Kb block
73 # endif
74 jcxz lzsa1quit // bail if we hit EOD
75 pushw %cx
76 # if !defined(FLAT32) && !defined(FLAT16)
77 xorw %cx, %cx
78 call normalize
79 # define NeedNormalize
80 # endif
81 popw %dx
82 addw %si, %dx
83 #endif
84 lzsa1chunk: // uncompress chunk
85 lodsb // get token O|LLL|MMMM
86 movb %al, %bl // keep token in bl
87 shrb $4, %al // shift literals length into place
88 movw $LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
89 call lzsa1len // %ch = LITERALS_RUN_LEN
90 #if defined(NeedNormalize)
91 call lzsa1movLit // copy %cx literals from %ds:%si to %es:%di
92 #else
93 rep movsb // copy %cx literals from %ds:%si to %es:%di
94 #endif
95 #ifndef RAW_FORMAT
96 cmpw %dx, %si
97 jae lzsa1block // bail if we hit EOD
98 #endif
99 #ifdef FLAT32
100 orl $-1, %eax
101 #else
102 movb $-1, %ah
103 #endif
104 testb %bl, %bl // check match offset size in token (O bit)
105 jns lzsa1ShortOfs
106 lodsw
107 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
108 lzsa1ShortOfs:
109 lodsb
110 xchg AX, BX // %bx: match offset %ax: original token
111 movw $MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
112 call lzsa1len
113 #ifdef RAW_FORMAT
114 jcxz lzsa1quit // bail if we hit EOD
115 #endif
116 #if !defined(FLAT32) && !defined(FLAT16OUT)
117 pushw %ds
118 pushw %si
119 movw %di, %si
120 addw %bx, %si
121 movw %es, %ax
122 jc axok
123 subb $0x10, %ah
124 axok:
125 .macro norm reg
126 movw %si, \reg
127 subw %si, %dx
128 andw $0xF, %si
129 addw %si, %dx
130 shrw $4, \reg
131 addw \reg, %ax
132 movw %ax, %ds
133 movw %di, \reg
134 andw $0xF, %di
135 shrw $4, \reg
136 movw %es, %ax
137 addw \reg, %ax
138 movw %ax, %es
139 .endm
140 pushw %dx
141 # if defined(NeedNormalize) || defined(PARANOIA)
142 call lzsa1movStr // copy string
143 # else
144 norm %bp
145 rep movsb
146 # endif
147 popw %dx
148 popw %si
149 popw %ds
150 #else
151 xchg AX, SI // save %si
152 lea (BX,DI), SI
153 rep movsb %es:(SI), %es:(DI)
154 xchg AX, SI // restore %si
155 #endif
156 jmp lzsa1chunk
158 lzsa1len: // get length in %ecx
159 andb %ch, %al
160 cbw // clear %ah
161 cmpb %ch, %al
162 jne lzsa1minNumber // S=0-6, L=0-14
163 lodsb
164 addb %ch, %cl
165 lzsa1minNumber:
166 addb %cl, %al
167 jnc lzsa1gotNumber // 0-255
168 movb %al, %ah // S=256-1791, L=256-3839 or S=256-511, L=256-511
169 jne lzsa1midNumber
170 lodsw // 0-65535
171 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
172 lzsa1midNumber:
173 lodsb
174 lzsa1gotNumber:
175 xchgw %ax, %cx
176 lzsa1quit:
177 ret
179 #if defined(NeedNormalize) || defined(PARANOIA)
180 # if defined(PARANOIA)
181 lzsa1movlp:
182 decw %ch
183 rep movsb
184 incw %ch
185 # endif
186 normalize:
187 lzsa1movLit:
188 movw %ds, %ax
189 lzsa1movStr:
190 norm %bp
191 # if defined(PARANOIA)
192 cmpb $0xFF, %ch // catch FFFX case
193 je lzsa1movlp
194 # endif
195 rep movsb
196 ret
197 #endif