rev |
line source |
pascal@13287
|
1 // #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
|
pascal@13287
|
2 //
|
pascal@13287
|
3 // #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
|
pascal@13287
|
4 // #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
|
pascal@13287
|
5 // #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
|
pascal@13287
|
6 //
|
pascal@13287
|
7 //#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
|
pascal@13287
|
8 // { UpdateBit0(p); mi <<= 1; A0; } else \
|
pascal@13287
|
9 // { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
|
pascal@13287
|
10 //
|
pascal@13287
|
11 // #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
|
pascal@13287
|
12 //
|
pascal@13287
|
13 // #define RangeDecoderBitTreeDecode(probs, numLevels, res) \
|
pascal@13287
|
14 // { int i = numLevels; res = 1; \
|
pascal@13287
|
15 // do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
|
pascal@13287
|
16 // res -= (1 << numLevels); }
|
pascal@13287
|
17 /*
|
pascal@13287
|
18 * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3
|
pascal@13287
|
19 */
|
pascal@13287
|
20
|
pascal@13287
|
21 #define PROP_PB 2
|
pascal@13287
|
22 #define PROP_LP 0
|
pascal@13287
|
23 #define PROP_LC 3
|
pascal@13287
|
24 #define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45))
|
pascal@13287
|
25
|
pascal@13287
|
26 // static const Byte *Buffer;
|
pascal@13287
|
27 // static UInt32 bound, Code, Range;
|
pascal@13287
|
28
|
pascal@13287
|
29 /*
|
pascal@13287
|
30 * Buffer register DS:SI
|
pascal@13287
|
31 * all var based ws=ss:bp
|
pascal@13287
|
32 */
|
pascal@13287
|
33
|
pascal@13287
|
34 rep0 = -4 // long
|
pascal@13287
|
35 rep1 = rep0-4 // long
|
pascal@13287
|
36 rep2 = rep0-8 // long
|
pascal@13287
|
37 rep3 = rep0-12 // long
|
pascal@13287
|
38 state = -17 // byte, 0..11
|
pascal@13287
|
39 posState = state-1 // byte, 0..15
|
pascal@13287
|
40 posState2 = posState-1 // byte, 0..15
|
pascal@13287
|
41 scratched = rep0-16 // byte = 1
|
pascal@13287
|
42 Code = -24 // long
|
pascal@13287
|
43 outStream = -28 // long
|
pascal@13287
|
44 nowPos = outStream // long
|
pascal@13287
|
45 Range = Code-8 // long
|
pascal@13287
|
46 #define LOCALS 32
|
pascal@13287
|
47
|
pascal@13287
|
48 // int LzmaDecode(CLzmaDecoderState *vs,
|
pascal@13287
|
49 // const unsigned char *inStream,
|
pascal@13287
|
50 // unsigned char *outStream)
|
pascal@13287
|
51 // {
|
pascal@13287
|
52 // CProb *p = vs->Probs;
|
pascal@13287
|
53 // SizeT nowPos = 0;
|
pascal@13287
|
54 // #define posStateMask = (1 << (vs->Properties.pb)) - 1;
|
pascal@13287
|
55 // #define literalPosMask = (1 << (vs->Properties.lp)) - 1;
|
pascal@13287
|
56 // int lc = vs->Properties.lc, state = 0, len = 0;
|
pascal@13287
|
57 // UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
pascal@13287
|
58 //
|
pascal@13287
|
59 // {
|
pascal@13287
|
60 // UInt32 i, numProbs = Literal /*1846*/
|
pascal@13287
|
61 // + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp));
|
pascal@13287
|
62 // for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1;
|
pascal@13287
|
63
|
pascal@13287
|
64 #define WS (1846+(768<<(PROP_LC+PROP_LP)))
|
pascal@13287
|
65 #if (WS+WS+LOCALS) >= 65000
|
pascal@13287
|
66 /* MAX WS = (1846+(768<<(8+4))) > 3MB! */
|
pascal@13287
|
67 #error invalid (lc,lp,pb) : out of memory
|
pascal@13287
|
68 #endif
|
pascal@13287
|
69
|
pascal@13287
|
70 ws1 = WS
|
pascal@13287
|
71 ws2 = ws1*2
|
pascal@13287
|
72 ws = ws2+LOCALS+15
|
pascal@13287
|
73
|
pascal@13287
|
74 #ifndef FLAT32
|
pascal@13287
|
75 #define AX %ax
|
pascal@13287
|
76 #define BX %bx
|
pascal@13287
|
77 #define CX %cx
|
pascal@13287
|
78 #define DX %dx
|
pascal@13287
|
79 #define SI %si
|
pascal@13287
|
80 #define DI %di
|
pascal@13287
|
81 #define BP %bp
|
pascal@13287
|
82 #define SP %sp
|
pascal@13287
|
83 #define CWD cwd
|
pascal@13287
|
84 #else
|
pascal@13287
|
85 #define AX %eax
|
pascal@13287
|
86 #define BX %ebx
|
pascal@13287
|
87 #define CX %ecx
|
pascal@13287
|
88 #define DX %edx
|
pascal@13287
|
89 #define SI %esi
|
pascal@13287
|
90 #define DI %edi
|
pascal@13287
|
91 #define BP %ebp
|
pascal@13287
|
92 #define SP %esp
|
pascal@13287
|
93 #define CWD cdq
|
pascal@13287
|
94 #endif
|
pascal@13287
|
95 /*
|
pascal@13287
|
96 * LzmaDecode:
|
pascal@13287
|
97 #ifndef FLAT32
|
pascal@13287
|
98 * input ds:si=inStream, es:di=outStream
|
pascal@13287
|
99 * output outStream[], ds:si, es:di
|
pascal@13287
|
100 .code 16
|
pascal@13287
|
101 #else
|
pascal@13287
|
102 * input esi=inStream, edi=outStream
|
pascal@13287
|
103 * output outStream[], esi, edi
|
pascal@13287
|
104 .code 32
|
pascal@13287
|
105 #endif
|
pascal@13287
|
106 */
|
pascal@13287
|
107
|
pascal@13287
|
108 mov $ws1, CX
|
pascal@13287
|
109 lzd1:
|
pascal@13287
|
110 pushw $2048/2
|
pascal@13287
|
111 loop lzd1
|
pascal@13287
|
112 mov SP, BP
|
pascal@13287
|
113 movb $((LOCALS+3)/4)*2, %cl
|
pascal@13287
|
114 initlocals:
|
pascal@13287
|
115 pushl $1
|
pascal@13287
|
116 loop initlocals
|
pascal@13287
|
117
|
pascal@13287
|
118 #ifndef FLAT32
|
pascal@13287
|
119 movb $4, %cl
|
pascal@13287
|
120 movw %es, %bx
|
pascal@13287
|
121 shrw %cl, %bx
|
pascal@13287
|
122 movw %es, %dx
|
pascal@13287
|
123 shlw %cl, %dx
|
pascal@13287
|
124 addw %dx, %di
|
pascal@13287
|
125 movw %di, outStream(%bp)
|
pascal@13287
|
126 adcb %bh, outStream+2(%bp)
|
pascal@13287
|
127 incw %cx
|
pascal@13287
|
128 #else
|
pascal@13287
|
129 movb $5, %cl
|
pascal@13287
|
130 movl %edi, outStream(%ebp)
|
pascal@13287
|
131 #endif
|
pascal@13287
|
132
|
pascal@13287
|
133 // Byte previousByte = 0;
|
pascal@13287
|
134 xor BX, BX
|
pascal@13287
|
135
|
pascal@13287
|
136 // #define RC_INIT(buffer)
|
pascal@13287
|
137 // Buffer = buffer; Code = 0; Range = 0xFFFFFFFF;
|
pascal@13287
|
138 // { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }}
|
pascal@13287
|
139 // }
|
pascal@13287
|
140 // RC_INIT(inStream);
|
pascal@13287
|
141
|
pascal@13287
|
142 add $13, SI // skip header
|
pascal@13287
|
143 setrep:
|
pascal@13287
|
144 call RC_LOAD_BYTE
|
pascal@13287
|
145 decb Range(BP)
|
pascal@13287
|
146 loop setrep
|
pascal@13287
|
147
|
pascal@13287
|
148 lzdmainlp:
|
pascal@13287
|
149 // while(1) {
|
pascal@13287
|
150 // CProb *prob;
|
pascal@13287
|
151 // int posState = (int)((nowPos) & posStateMask);
|
pascal@13287
|
152 //
|
pascal@13287
|
153 // prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState;
|
pascal@13287
|
154 // if (Bit0(prob)) { /* char */
|
pascal@13287
|
155
|
pascal@13287
|
156 xor DX, DX
|
pascal@13287
|
157 call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
|
pascal@13287
|
158 mov $state, DI
|
pascal@13287
|
159 jc lzdstring
|
pascal@13287
|
160
|
pascal@13287
|
161 // prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ *
|
pascal@13287
|
162 // ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc))));
|
pascal@13287
|
163
|
pascal@13287
|
164 #if PROP_LC != 0
|
pascal@13287
|
165 shrb $8-PROP_LC, %bl
|
pascal@13287
|
166 #endif
|
pascal@13287
|
167
|
pascal@13287
|
168 #if PROP_LP != 0
|
pascal@13287
|
169 movb posState2(BP), %dl
|
pascal@13287
|
170 shl $PROP_LC, DX
|
pascal@13287
|
171 movb $0, %bh
|
pascal@13287
|
172 add BX, DX
|
pascal@13287
|
173 #endif
|
pascal@13287
|
174
|
pascal@13287
|
175 movb $3, %ah
|
pascal@13287
|
176 mul BX // dx = 3*bh
|
pascal@13287
|
177 add $1846, AX
|
pascal@13287
|
178
|
pascal@13287
|
179 // int symbol = 1;
|
pascal@13287
|
180
|
pascal@13287
|
181 CWD
|
pascal@13287
|
182 inc DX // symbol = 1
|
pascal@13287
|
183 xchg AX, CX // save prob
|
pascal@13287
|
184
|
pascal@13287
|
185 // if (state >= kNumLitStates /*7*/) { /* previous was string */
|
pascal@13287
|
186 // if (state < 4) state = 0;
|
pascal@13287
|
187
|
pascal@13287
|
188 lzd6z:
|
pascal@13287
|
189 subb $3, (BP, DI)
|
pascal@13287
|
190
|
pascal@13287
|
191 // if (state < 4) state = 0;
|
pascal@13287
|
192
|
pascal@13287
|
193 jnc lzd6
|
pascal@13287
|
194 movb %dh, (BP, DI) // %dh = 0
|
pascal@13287
|
195
|
pascal@13287
|
196 lzd6:
|
pascal@13287
|
197 // else if (state < 10) state -= 3;
|
pascal@13287
|
198
|
pascal@13287
|
199 cmpb $10-3, (BP, DI)
|
pascal@13287
|
200
|
pascal@13287
|
201 // else state -= 6;
|
pascal@13287
|
202
|
pascal@13287
|
203 jnb lzd6z
|
pascal@13287
|
204 cmpb $7-3-1, (BP, DI)
|
pascal@13287
|
205 jbe lzd3
|
pascal@13287
|
206
|
pascal@13287
|
207 // int matchByte = outStream[nowPos - rep0];
|
pascal@13287
|
208
|
pascal@13287
|
209 call DicoRep02ESDI // %bl = outStream[nowPos - rep0];
|
pascal@13287
|
210
|
pascal@13287
|
211 // do {
|
pascal@13287
|
212 // int bit;
|
pascal@13287
|
213 // CProb *probLit;
|
pascal@13287
|
214 // matchByte <<= 1; bit = (matchByte & 0x100);
|
pascal@13287
|
215
|
pascal@13287
|
216 movb $1, %bh
|
pascal@13287
|
217 lzd4:
|
pascal@13287
|
218 shlb $1, %bl // matchByte <<= 1
|
pascal@13287
|
219 sbb DI, DI // save bit=C
|
pascal@13287
|
220
|
pascal@13287
|
221 // probLit = prob + 0x100 + bit + symbol;
|
pascal@13287
|
222
|
pascal@13287
|
223 mov CX, AX // restore prob
|
pascal@13287
|
224 adcb %bh, %ah // + bit + 0x100
|
pascal@13287
|
225
|
pascal@13287
|
226 // RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break)
|
pascal@13287
|
227
|
pascal@13287
|
228 call Bit1axdx // C,%ax = Bit1(prob+%ax)
|
pascal@13287
|
229 rclb $1, %dl // symbol <<= 1; symbol |= C
|
pascal@13287
|
230 jc lzd5 // if symbol >= 0x100
|
pascal@13287
|
231 cmp DI, AX
|
pascal@13287
|
232 jz lzd4 // if bit == Bit1(prob+%ax)
|
pascal@13287
|
233
|
pascal@13287
|
234 // } while (symbol < 0x100);
|
pascal@13287
|
235 // }
|
pascal@13287
|
236 lzd3:
|
pascal@13287
|
237 // while (symbol < 0x100) {
|
pascal@13287
|
238 // CProb *probLit = prob + symbol;
|
pascal@13287
|
239 // RC_GET_BIT(probLit, symbol)
|
pascal@13287
|
240 // }
|
pascal@13287
|
241
|
pascal@13287
|
242 xor BX, BX
|
pascal@13287
|
243 jmp lzd4
|
pascal@13287
|
244 lzd5:
|
pascal@13287
|
245
|
pascal@13287
|
246 // outStream[nowPos++] = previousByte = (Byte)symbol;
|
pascal@13287
|
247
|
pascal@13287
|
248 xchg AX, DX
|
pascal@13287
|
249 call outchar // %bl = outStream[nowPos++] = %al;
|
pascal@13287
|
250 jmp lzdmainlp
|
pascal@13287
|
251
|
pascal@13287
|
252 // }
|
pascal@13287
|
253
|
pascal@13287
|
254 lzdstring:
|
pascal@13287
|
255 mov $1, CX
|
pascal@13287
|
256
|
pascal@13287
|
257 // else { /* string */
|
pascal@13287
|
258 // prob = p + IsRep /*192*/ + state;
|
pascal@13287
|
259
|
pascal@13287
|
260 movb $192, %dl
|
pascal@13287
|
261 addb (BP, DI), %dl
|
pascal@13287
|
262 mov $rep0, DI
|
pascal@13287
|
263
|
pascal@13287
|
264 // if (Bit0(prob)) {
|
pascal@13287
|
265
|
pascal@13287
|
266 call Bit1dx // Bit1(prob)
|
pascal@13287
|
267 jc lzd8
|
pascal@13287
|
268
|
pascal@13287
|
269 // rep3 = rep2; rep2 = rep1; rep1 = rep0;
|
pascal@13287
|
270 // state = (state < kNumLitStates /*7*/) ? 0 : 3;
|
pascal@13287
|
271
|
pascal@13287
|
272 stc
|
pascal@13287
|
273
|
pascal@13287
|
274 // prob = p + LenCoder /*818*/;
|
pascal@13287
|
275
|
pascal@13287
|
276 mov $818, DX
|
pascal@13287
|
277
|
pascal@13287
|
278 // }
|
pascal@13287
|
279
|
pascal@13287
|
280 jmp lzd11a
|
pascal@13287
|
281
|
pascal@13287
|
282 // else {
|
pascal@13287
|
283 lzd8:
|
pascal@13287
|
284 // prob += kNumStates /*12*/;
|
pascal@13287
|
285 // if (Bit0(prob)) {
|
pascal@13287
|
286 call Bit1dx12 // prob += 12; Bit1(prob)
|
pascal@13287
|
287 jc lzd11
|
pascal@13287
|
288 // prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/)
|
pascal@13287
|
289 // + posState;
|
pascal@13287
|
290 movb $240, %dl // dh=0
|
pascal@13287
|
291
|
pascal@13287
|
292 // if (Bit0(prob)) {
|
pascal@13287
|
293
|
pascal@13287
|
294 call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
|
pascal@13287
|
295 jc lzd12
|
pascal@13287
|
296
|
pascal@13287
|
297 // // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR;
|
pascal@13287
|
298 // state = (state < kNumLitStates /*7*/) ? 9 : 11;
|
pascal@13287
|
299
|
pascal@13287
|
300 movb $9, %dl
|
pascal@13287
|
301
|
pascal@13287
|
302 // len++; goto string;
|
pascal@13287
|
303 jmp lzd13string // ax = 0
|
pascal@13287
|
304 // }
|
pascal@13287
|
305 // }
|
pascal@13287
|
306 // else {
|
pascal@13287
|
307 lzd11:
|
pascal@13287
|
308 // UInt32 distance = rep1;
|
pascal@13287
|
309 // prob += kNumStates /*12*/;
|
pascal@13287
|
310 // if (!Bit0(prob)) {
|
pascal@13287
|
311
|
pascal@13287
|
312 call Bit1dx12 // prob += 12; Bit1(prob)
|
pascal@13287
|
313 jnc lzd11z
|
pascal@13287
|
314
|
pascal@13287
|
315 // prob += kNumStates /*12*/;
|
pascal@13287
|
316 // if (Bit0(prob)) distance = rep2;
|
pascal@13287
|
317
|
pascal@13287
|
318 call Bit1dx12 // prob += 12; Bit1(prob)
|
pascal@13287
|
319 lzd11a:
|
pascal@13287
|
320 adcb %cl, %cl
|
pascal@13287
|
321
|
pascal@13287
|
322 // else { distance = rep3; rep3 = rep2; }
|
pascal@13287
|
323 // rep2 = rep1;
|
pascal@13287
|
324 // }
|
pascal@13287
|
325 // rep1 = rep0; rep0 = distance;
|
pascal@13287
|
326
|
pascal@13287
|
327 lzd11z:
|
pascal@13287
|
328 shl $2, CX // 8->32 bits
|
pascal@13287
|
329 sub CX, DI // &rep[cx]
|
pascal@13287
|
330 movl (BP, DI), %eax
|
pascal@13287
|
331 rotreplp:
|
pascal@13287
|
332 movb 4(BP, DI), %bl
|
pascal@13287
|
333 movb %bl, (BP, DI)
|
pascal@13287
|
334 inc DI
|
pascal@13287
|
335 loop rotreplp
|
pascal@13287
|
336 testb %dh, %dh
|
pascal@13287
|
337 jnz lzd10
|
pascal@13287
|
338 movl %eax, (BP, DI)
|
pascal@13287
|
339
|
pascal@13287
|
340 // }
|
pascal@13287
|
341 lzd12:
|
pascal@13287
|
342 // state = (state < kNumLitStates /*7*/) ? 8 : 11;
|
pascal@13287
|
343
|
pascal@13287
|
344 movb $0x08, %cl
|
pascal@13287
|
345
|
pascal@13287
|
346 // prob = p + RepLenCoder /*1332*/;
|
pascal@13287
|
347
|
pascal@13287
|
348 mov $1332, DX
|
pascal@13287
|
349
|
pascal@13287
|
350 // }
|
pascal@13287
|
351 lzd10:
|
pascal@13287
|
352 push CX // CX = 0
|
pascal@13287
|
353
|
pascal@13287
|
354 // { /* get len */
|
pascal@13287
|
355 // int numBits, offset;
|
pascal@13287
|
356 // CProb *probLen = prob + LenChoice /*0*/;
|
pascal@13287
|
357 // numBits = kLenNumLowBits /*3*/;
|
pascal@13287
|
358
|
pascal@13287
|
359 movb $8, %cl // numBits : 3,3,8
|
pascal@13287
|
360
|
pascal@13287
|
361 // if (Bit0(probLen)) {
|
pascal@13287
|
362
|
pascal@13287
|
363 call Bit1dx // Bit1(prob)
|
pascal@13287
|
364 xchg AX, BX
|
pascal@13287
|
365 inc DX
|
pascal@13287
|
366 jnc lzd15 // bx=0
|
pascal@13287
|
367
|
pascal@13287
|
368 // probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/);
|
pascal@13287
|
369 // offset = 0;
|
pascal@13287
|
370 // }
|
pascal@13287
|
371 // else {
|
pascal@13287
|
372 // probLen = prob + LenChoice2 /*1*/;
|
pascal@13287
|
373
|
pascal@13287
|
374 call Bit1dx // Bit1(prob)
|
pascal@13287
|
375 add AX, BX
|
pascal@13287
|
376
|
pascal@13287
|
377 #if PROP_PB != 0
|
pascal@13287
|
378 inc AX // ah=0
|
pascal@13287
|
379 #endif
|
pascal@13287
|
380 jc lzd16 // %ax=0, %bx=-2
|
pascal@13287
|
381 lzd15:
|
pascal@13287
|
382 #if PROP_PB != 0
|
pascal@13287
|
383 movb $8, %al
|
pascal@13287
|
384 mulb posState(BP)
|
pascal@13287
|
385 #endif
|
pascal@13287
|
386
|
pascal@13287
|
387 // if (Bit0(probLen)) {
|
pascal@13287
|
388 // probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/);
|
pascal@13287
|
389
|
pascal@13287
|
390 movb $3, %cl // numBits : 3,3,8
|
pascal@13287
|
391 lzd16:
|
pascal@13287
|
392 #if PROP_PB != 0
|
pascal@13287
|
393 add $2-128-1, AX // probLen : 2,130,258
|
pascal@13287
|
394 #else
|
pascal@13287
|
395 mov $2-128-1, AX // probLen : 2,130,258
|
pascal@13287
|
396 #endif
|
pascal@13287
|
397 add DX, AX
|
pascal@13287
|
398 mov $-8+1, DX // offset : 0,8,16
|
pascal@13287
|
399 lzdargslp:
|
pascal@13287
|
400 add $8, DX
|
pascal@13287
|
401 add $128, AX
|
pascal@13287
|
402 inc BX
|
pascal@13287
|
403 jle lzdargslp // leave with bx=1
|
pascal@13287
|
404
|
pascal@13287
|
405 // offset = kLenNumLowSymbols /*8*/;
|
pascal@13287
|
406 // //numBits = kLenNumMidBits /*3*/;
|
pascal@13287
|
407 // }
|
pascal@13287
|
408 // else {
|
pascal@13287
|
409 // probLen = prob + LenHigh /*258*/;
|
pascal@13287
|
410 // offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/;
|
pascal@13287
|
411 // numBits = kLenNumHighBits /*8*/;
|
pascal@13287
|
412 // }
|
pascal@13287
|
413 // }
|
pascal@13287
|
414 // RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset;
|
pascal@13287
|
415
|
pascal@13287
|
416 push DX
|
pascal@13287
|
417 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
|
pascal@13287
|
418 pop DX
|
pascal@13287
|
419 add DX, AX // offset
|
pascal@13287
|
420 pop DX // 0
|
pascal@13287
|
421 lzd13string:
|
pascal@13287
|
422 push AX
|
pascal@13287
|
423
|
pascal@13287
|
424 // state = (state < kNumLitStates /*7*/) ? dl : dl|3;
|
pascal@13287
|
425
|
pascal@13287
|
426 movb $7, %cl
|
pascal@13287
|
427 cmpb %cl, state(BP)
|
pascal@13287
|
428 jb new_state
|
pascal@13287
|
429 orb $3, %dl
|
pascal@13287
|
430 new_state:
|
pascal@13287
|
431 movb %dl, state(BP)
|
pascal@13287
|
432
|
pascal@13287
|
433 // } /* get len */
|
pascal@13287
|
434 // if (state < 4) {
|
pascal@13287
|
435
|
pascal@13287
|
436 cmpb $4-1, %dl
|
pascal@13287
|
437 ja lzd19
|
pascal@13287
|
438
|
pascal@13287
|
439 // int posSlot;
|
pascal@13287
|
440 // state += kNumLitStates /*7*/;
|
pascal@13287
|
441
|
pascal@13287
|
442 addb %cl, state(BP)
|
pascal@13287
|
443
|
pascal@13287
|
444 // prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ?
|
pascal@13287
|
445 // len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/);
|
pascal@13287
|
446
|
pascal@13287
|
447 cmp $4+1, AX
|
pascal@13287
|
448 jb lzd21
|
pascal@13287
|
449 mov $3+1, AX
|
pascal@13287
|
450
|
pascal@13287
|
451 lzd21:
|
pascal@13287
|
452
|
pascal@13287
|
453 dec CX // cx = 6
|
pascal@13287
|
454 shl %cl, AX
|
pascal@13287
|
455 add $432-64, AX
|
pascal@13287
|
456
|
pascal@13287
|
457 // RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot);
|
pascal@13287
|
458
|
pascal@13287
|
459 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
|
pascal@13287
|
460
|
pascal@13287
|
461 // if (posSlot >= kStartPosModelIndex /*4*/) {
|
pascal@13287
|
462 // int numDirectBits = ((posSlot >> 1) - 1);
|
pascal@13287
|
463
|
pascal@13287
|
464 #ifndef FLAT32
|
pascal@13287
|
465 movw %cx, 2(%bp, %di) // %cx = 0
|
pascal@13287
|
466 #endif
|
pascal@13287
|
467 mov AX, (BP, DI)
|
pascal@13287
|
468 mov AX, CX
|
pascal@13287
|
469 shrw $1, CX
|
pascal@13287
|
470 dec CX
|
pascal@13287
|
471 cmpb $4, %al
|
pascal@13287
|
472 jb lzd22
|
pascal@13287
|
473
|
pascal@13287
|
474 // rep0 = (2 | ((UInt32)posSlot & 1));
|
pascal@13287
|
475
|
pascal@13287
|
476 andb %bl, (BP, DI) // %bx=1
|
pascal@13287
|
477 orb $2, (BP, DI)
|
pascal@13287
|
478
|
pascal@13287
|
479 // if (posSlot < kEndPosModelIndex /*14*/) {
|
pascal@13287
|
480
|
pascal@13287
|
481 cmpb $14, %al
|
pascal@13287
|
482 jnb lzd23
|
pascal@13287
|
483
|
pascal@13287
|
484 // rep0 <<= numDirectBits;
|
pascal@13287
|
485
|
pascal@13287
|
486 neg AX
|
pascal@13287
|
487 shll %cl, (BP, DI)
|
pascal@13287
|
488 add (BP, DI), AX
|
pascal@13287
|
489
|
pascal@13287
|
490 // prob = p + SpecPos /*688*/ + rep0 - posSlot - 1;
|
pascal@13287
|
491
|
pascal@13287
|
492 add $687, AX
|
pascal@13287
|
493 jmp lzd24
|
pascal@13287
|
494
|
pascal@13287
|
495 // }
|
pascal@13287
|
496 // else {
|
pascal@13287
|
497 lzd23:
|
pascal@13287
|
498 // numDirectBits -= kNumAlignBits /*4*/;
|
pascal@13287
|
499 // do {
|
pascal@13287
|
500 // RC_NORMALIZE; Range >>= 1; rep0 <<= 1;
|
pascal@13287
|
501 // if (Code >= Range) { Code -= Range; rep0 |= 1; }
|
pascal@13287
|
502
|
pascal@13287
|
503 lzd23z:
|
pascal@13287
|
504 call RC_NORMALIZE
|
pascal@13287
|
505 shrl $1, Range(BP)
|
pascal@13287
|
506 movl Range(BP), %eax
|
pascal@13287
|
507 cmpl Code(BP), %eax
|
pascal@13287
|
508 ja lzd25
|
pascal@13287
|
509 subl %eax, Code(BP)
|
pascal@13287
|
510 stc
|
pascal@13287
|
511 lzd25:
|
pascal@13287
|
512 rcll $1, (BP, DI)
|
pascal@13287
|
513
|
pascal@13287
|
514 // } while (--numDirectBits != 0);
|
pascal@13287
|
515
|
pascal@13289
|
516 cmpb $4+1, %cl
|
pascal@13287
|
517 loopne lzd23z
|
pascal@13287
|
518
|
pascal@13287
|
519 // prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/;
|
pascal@13287
|
520 // rep0 <<= numDirectBits;
|
pascal@13287
|
521
|
pascal@13287
|
522 shll %cl, (BP, DI)
|
pascal@13287
|
523 mov $802, AX
|
pascal@13287
|
524 // }
|
pascal@13287
|
525
|
pascal@13287
|
526 lzd24:
|
pascal@13287
|
527 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
|
pascal@13287
|
528
|
pascal@13287
|
529 // {
|
pascal@13287
|
530 // int i = 1, mi = 1;
|
pascal@13287
|
531 // do {
|
pascal@13287
|
532 // CProb *prob3 = prob + mi;
|
pascal@13287
|
533 // RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
|
pascal@13287
|
534
|
pascal@13287
|
535 orb %dh, (BP, DI) // update rep0 with DirectBits
|
pascal@13287
|
536
|
pascal@13287
|
537 // i <<= 1;
|
pascal@13287
|
538 // } while(--numDirectBits != 0);
|
pascal@13287
|
539 // }
|
pascal@13287
|
540 // } else rep0 = posSlot;
|
pascal@13287
|
541 lzd22:
|
pascal@13287
|
542 // if (++rep0 == (UInt32)(0)) break; /* EOF */
|
pascal@13287
|
543
|
pascal@13287
|
544 incl (BP, DI)
|
pascal@13287
|
545
|
pascal@13287
|
546 lzd19:
|
pascal@13287
|
547 pop CX
|
pascal@13287
|
548 jz lzdone
|
pascal@13287
|
549
|
pascal@13287
|
550 // }
|
pascal@13287
|
551 // len += kMatchMinLen;/*2*/
|
pascal@13287
|
552
|
pascal@13287
|
553 inc CX
|
pascal@13287
|
554
|
pascal@13287
|
555 // string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR;
|
pascal@13287
|
556 // do {
|
pascal@13287
|
557 lzd13z:
|
pascal@13287
|
558 // previousByte = outStream[nowPos - rep0];
|
pascal@13287
|
559 // outStream[nowPos++] = previousByte;
|
pascal@13287
|
560
|
pascal@13287
|
561 call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0]
|
pascal@13287
|
562
|
pascal@13287
|
563 // } while(--len != 0);
|
pascal@13287
|
564
|
pascal@13287
|
565 loop lzd13z
|
pascal@13287
|
566
|
pascal@13287
|
567 // } /* char/string */
|
pascal@13287
|
568 // }
|
pascal@13287
|
569
|
pascal@13287
|
570 jmp lzdmainlp
|
pascal@13287
|
571
|
pascal@13287
|
572 lzdone:
|
pascal@13287
|
573 // //RC_NORMALIZE;
|
pascal@13287
|
574 // //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos;
|
pascal@13287
|
575 // return LZMA_RESULT_OK;
|
pascal@13287
|
576 call Dico2ESDI // set es & di (rep0 = 0)
|
pascal@13287
|
577 lea ws2(BP), SP // dealloc
|
pascal@13287
|
578 ret
|
pascal@13287
|
579 // }
|
pascal@13287
|
580
|
pascal@13287
|
581 // al = outStream[nowPos - rep0];
|
pascal@13287
|
582
|
pascal@13287
|
583 /*
|
pascal@13287
|
584 * output es:di, al
|
pascal@13287
|
585 * scratch bh, cl, flags
|
pascal@13287
|
586 */
|
pascal@13287
|
587
|
pascal@13287
|
588 DicoRep02ESDI:
|
pascal@13287
|
589 stc
|
pascal@13287
|
590
|
pascal@13287
|
591 // bl = outStream[nowPos];
|
pascal@13287
|
592
|
pascal@13287
|
593 /*
|
pascal@13287
|
594 * output es:di, bl
|
pascal@13287
|
595 * scratch bh, cl, flags
|
pascal@13287
|
596 */
|
pascal@13287
|
597
|
pascal@13287
|
598 Dico2ESDI:
|
pascal@13287
|
599 #ifndef FLAT32
|
pascal@13287
|
600 movl nowPos(%bp), %ebx
|
pascal@13287
|
601 jnc Dico2ESDIz
|
pascal@13287
|
602 subl rep0(%bp), %ebx
|
pascal@13287
|
603 Dico2ESDIz:
|
pascal@13287
|
604 movw %bx, %di
|
pascal@13287
|
605 xorw %bx, %bx
|
pascal@13287
|
606 shrl $4, %ebx
|
pascal@13287
|
607 movw %bx, %es
|
pascal@13287
|
608 movb %es:(%di), %bl
|
pascal@13287
|
609 #else
|
pascal@13287
|
610 movl nowPos(%bp), %edi
|
pascal@13287
|
611 jnc Dico2ESDIz
|
pascal@13287
|
612 subl rep0(%bp), %edi
|
pascal@13287
|
613 Dico2ESDIz:
|
pascal@13287
|
614 movb (%edi), %bl
|
pascal@13287
|
615 #endif
|
pascal@13287
|
616 ret
|
pascal@13287
|
617
|
pascal@13287
|
618 outcharDico:
|
pascal@13287
|
619
|
pascal@13287
|
620 // bl = outStream[nowPos++] = outStream[nowPos - rep0]
|
pascal@13287
|
621
|
pascal@13287
|
622 /*
|
pascal@13287
|
623 * output es:di, bl
|
pascal@13287
|
624 * update nowPos
|
pascal@13287
|
625 * scratch ax, dx, bh, cl, flags
|
pascal@13287
|
626 */
|
pascal@13287
|
627
|
pascal@13287
|
628 call DicoRep02ESDI // %bl = outStream[nowPos - rep0]
|
pascal@13287
|
629 xchg AX, BX
|
pascal@13287
|
630 outchar:
|
pascal@13287
|
631
|
pascal@13287
|
632 // bl = outStream[nowPos++] = previousByte = al;
|
pascal@13287
|
633
|
pascal@13287
|
634 /*
|
pascal@13287
|
635 * output bl
|
pascal@13287
|
636 * update nowPos
|
pascal@13287
|
637 * scratch ax, dx, bh, di, cl, flags
|
pascal@13287
|
638 */
|
pascal@13287
|
639
|
pascal@13287
|
640 clc
|
pascal@13287
|
641 call Dico2ESDI
|
pascal@13287
|
642 stosb
|
pascal@13287
|
643 xchg AX, BX // previous byte
|
pascal@13287
|
644
|
pascal@13287
|
645 // int posState = (int)((nowPos) & posStateMask);
|
pascal@13287
|
646
|
pascal@13287
|
647 #if PROP_PB != 0 && PROP_LP != 0
|
pascal@13287
|
648 addw $0x0101, posState2(BP)
|
pascal@13287
|
649 andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP)
|
pascal@13287
|
650 #else
|
pascal@13287
|
651 # if PROP_PB != 0
|
pascal@13287
|
652 incb posState(BP)
|
pascal@13287
|
653 andb $((1 << PROP_PB) -1), posState(BP)
|
pascal@13287
|
654 # endif
|
pascal@13287
|
655 # if PROP_LP != 0
|
pascal@13287
|
656 incb posState2(BP)
|
pascal@13287
|
657 andb $((1 << PROP_LP) -1), posState2(BP)
|
pascal@13287
|
658 # endif
|
pascal@13287
|
659 #endif
|
pascal@13287
|
660 incl nowPos(BP)
|
pascal@13287
|
661 ret
|
pascal@13287
|
662
|
pascal@13287
|
663 //
|
pascal@13287
|
664 // #define RC_NORMALIZE if (Range < kTopValue)
|
pascal@13287
|
665 // { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
|
pascal@13287
|
666
|
pascal@13287
|
667 /*
|
pascal@13287
|
668 * update Range, Code, ds:si
|
pascal@13287
|
669 * scratch flags
|
pascal@13287
|
670 */
|
pascal@13287
|
671
|
pascal@13287
|
672 RC_NORMALIZE:
|
pascal@13287
|
673 cmpb $0, Range+3(BP)
|
pascal@13287
|
674 jne RC_NORMALIZE_1
|
pascal@13287
|
675 RC_LOAD_BYTE:
|
pascal@13287
|
676 push AX
|
pascal@13287
|
677 shll $8, Range(BP)
|
pascal@13287
|
678 shll $8, Code(BP)
|
pascal@13287
|
679 #ifndef FLAT32
|
pascal@13287
|
680 testw %si, %si
|
pascal@13287
|
681 jns RC_READ_BYTE
|
pascal@13287
|
682 movw %ds, %ax
|
pascal@13287
|
683 incw %ax
|
pascal@13287
|
684 movw %ax, %ds
|
pascal@13287
|
685 addw $-16, %si
|
pascal@13287
|
686 RC_READ_BYTE:
|
pascal@13287
|
687 #endif
|
pascal@13287
|
688 lodsb
|
pascal@13287
|
689 movb %al, Code(BP)
|
pascal@13287
|
690 pop AX
|
pascal@13287
|
691 RC_NORMALIZE_1:
|
pascal@13287
|
692 ret
|
pascal@13287
|
693
|
pascal@13287
|
694 // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
|
pascal@13287
|
695
|
pascal@13287
|
696 Bit1state:
|
pascal@13287
|
697 movb $16, %al
|
pascal@13287
|
698 mulb state(BP)
|
pascal@13287
|
699 # if PROP_PB != 0
|
pascal@13287
|
700 addb posState(BP), %al
|
pascal@13287
|
701 # endif
|
pascal@13287
|
702 Bit1axdx:
|
pascal@13287
|
703 add DX, AX
|
pascal@13287
|
704 jmp Bit1
|
pascal@13287
|
705
|
pascal@13287
|
706 // prob += 12; Bit1(prob)
|
pascal@13287
|
707
|
pascal@13287
|
708 Bit1dx12:
|
pascal@13287
|
709 add $12, DX
|
pascal@13287
|
710 Bit1dx:
|
pascal@13287
|
711 mov DX, AX
|
pascal@13287
|
712
|
pascal@13287
|
713 // static int Bit1(CProb *p)
|
pascal@13287
|
714
|
pascal@13287
|
715 Bit1:
|
pascal@13287
|
716 /*
|
pascal@13287
|
717 * input ax=p
|
pascal@13287
|
718 * output C, ax
|
pascal@13287
|
719 * update bound, Range, Code, ds:si
|
pascal@13287
|
720 * scratch flags
|
pascal@13287
|
721 */
|
pascal@13287
|
722
|
pascal@13287
|
723 // {
|
pascal@13287
|
724 // RC_NORMALIZE;
|
pascal@13287
|
725
|
pascal@13287
|
726 call RC_NORMALIZE // kill %ax, update %si
|
pascal@13287
|
727
|
pascal@13289
|
728 pushal
|
pascal@13287
|
729
|
pascal@13287
|
730 xchg AX, DI
|
pascal@13287
|
731 add DI, DI // short *
|
pascal@13287
|
732
|
pascal@13287
|
733
|
pascal@13287
|
734 // bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p);
|
pascal@13287
|
735
|
pascal@13287
|
736 movl Range(BP), %eax
|
pascal@13287
|
737 shrl $11, %eax
|
pascal@13287
|
738 movzwl (BP, DI), %edx
|
pascal@13287
|
739 mull %edx
|
pascal@13287
|
740
|
pascal@13287
|
741 // if (Code < bound) {
|
pascal@13287
|
742
|
pascal@13287
|
743 cmpl Code(BP), %eax
|
pascal@13287
|
744 jbe Bit1_1
|
pascal@13287
|
745
|
pascal@13287
|
746 // Range = bound;
|
pascal@13287
|
747
|
pascal@13287
|
748 movl %eax, Range(BP)
|
pascal@13287
|
749
|
pascal@13287
|
750 // *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/;
|
pascal@13287
|
751
|
pascal@13287
|
752 movw $2048, %ax
|
pascal@13287
|
753
|
pascal@13287
|
754 // return 0;
|
pascal@13287
|
755
|
pascal@13287
|
756 jmp Bit1_2
|
pascal@13287
|
757
|
pascal@13287
|
758 // }
|
pascal@13287
|
759 // else {
|
pascal@13287
|
760
|
pascal@13287
|
761 Bit1_1:
|
pascal@13287
|
762
|
pascal@13287
|
763 // Range -= bound; Code -= bound;
|
pascal@13287
|
764
|
pascal@13287
|
765 subl %eax, Range(BP)
|
pascal@13287
|
766 subl %eax, Code(BP)
|
pascal@13287
|
767
|
pascal@13287
|
768 // *(p) -= (*(p)) >> kNumMoveBits /*5*/;
|
pascal@13287
|
769
|
pascal@13287
|
770 movw $31, %ax
|
pascal@13287
|
771
|
pascal@13287
|
772 // return 1;
|
pascal@13287
|
773
|
pascal@13287
|
774 stc
|
pascal@13287
|
775 Bit1_2:
|
pascal@13287
|
776 pushf
|
pascal@13287
|
777 subw (BP, DI), %ax
|
pascal@13287
|
778 sarw $5, %ax
|
pascal@13287
|
779 addw %ax, (BP, DI)
|
pascal@13287
|
780 popf
|
pascal@13289
|
781 popal
|
pascal@13287
|
782 sbb AX, AX
|
pascal@13287
|
783
|
pascal@13287
|
784 // }
|
pascal@13287
|
785 // }
|
pascal@13287
|
786
|
pascal@13287
|
787 ret
|
pascal@13287
|
788
|
pascal@13287
|
789 RangeDecoder:
|
pascal@13287
|
790
|
pascal@13287
|
791 /*
|
pascal@13287
|
792 * input ax=probs cx=numLevels (< 8) bx=1
|
pascal@13287
|
793 * output ax=res (backward), dh (forward)
|
pascal@13287
|
794 * update bound, Range, Code, ds:si
|
pascal@13287
|
795 * scratch flags, cx=0, dl
|
pascal@13287
|
796 */
|
pascal@13287
|
797
|
pascal@13287
|
798 push BX
|
pascal@13287
|
799
|
pascal@13287
|
800 // { int i = numLevels; res = 1;
|
pascal@13287
|
801 mov BX, DX // res = 1
|
pascal@13287
|
802
|
pascal@13287
|
803 // do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0);
|
pascal@13287
|
804
|
pascal@13287
|
805 RangeDecoder_1:
|
pascal@13287
|
806 push AX
|
pascal@13287
|
807 call Bit1axdx // C,%ax = Bit1(prob+%ax)
|
pascal@13287
|
808 rclb $1, %dl // res <<= 1; res |= C
|
pascal@13287
|
809 andb %bl, %al // current bit
|
pascal@13287
|
810 orb %al, %bh // store in bh
|
pascal@13287
|
811 shlb $1, %bl // update max
|
pascal@13287
|
812 pop AX
|
pascal@13287
|
813 loop RangeDecoder_1
|
pascal@13287
|
814
|
pascal@13287
|
815 // res -= (1 << numLevels); }
|
pascal@13287
|
816
|
pascal@13287
|
817 xchg AX, BX // move bh to dh
|
pascal@13287
|
818 xchg AX, DX // and dl to al
|
pascal@13287
|
819 sub %dl, %al // sub max
|
pascal@13287
|
820 pop BX
|
pascal@13287
|
821 ret
|