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@20184
|
109 #ifdef ONLY8086
|
pascal@20184
|
110 movw $2048/2, %ax
|
pascal@20184
|
111 lzd1:
|
pascal@20184
|
112 pushw %ax
|
pascal@20184
|
113 #else
|
pascal@13287
|
114 lzd1:
|
pascal@13287
|
115 pushw $2048/2
|
pascal@20184
|
116 #endif
|
pascal@13287
|
117 loop lzd1
|
pascal@13287
|
118 mov SP, BP
|
pascal@13287
|
119 movb $((LOCALS+3)/4)*2, %cl
|
pascal@20184
|
120 #ifdef ONLY8086
|
pascal@20184
|
121 movw $1, %ax
|
pascal@20184
|
122 cwd
|
pascal@20184
|
123 initlocals:
|
pascal@20184
|
124 pushw %dx
|
pascal@20184
|
125 pushw %ax
|
pascal@20184
|
126 #else
|
pascal@13287
|
127 initlocals:
|
pascal@13287
|
128 pushl $1
|
pascal@20184
|
129 #endif
|
pascal@13287
|
130 loop initlocals
|
pascal@13287
|
131
|
pascal@19391
|
132 #if !defined(FLAT32) && !defined(FLAT16OUT)
|
pascal@13287
|
133 movb $4, %cl
|
pascal@13287
|
134 movw %es, %bx
|
pascal@13287
|
135 shrw %cl, %bx
|
pascal@13287
|
136 movw %es, %dx
|
pascal@13287
|
137 shlw %cl, %dx
|
pascal@13287
|
138 addw %dx, %di
|
pascal@13287
|
139 movw %di, outStream(%bp)
|
pascal@13287
|
140 adcb %bh, outStream+2(%bp)
|
pascal@13287
|
141 incw %cx
|
pascal@13287
|
142 #else
|
pascal@13287
|
143 movb $5, %cl
|
pascal@19391
|
144 mov DI, outStream(BP)
|
pascal@13287
|
145 #endif
|
pascal@13287
|
146
|
pascal@13287
|
147 // Byte previousByte = 0;
|
pascal@13287
|
148 xor BX, BX
|
pascal@13287
|
149
|
pascal@13287
|
150 // #define RC_INIT(buffer)
|
pascal@13287
|
151 // Buffer = buffer; Code = 0; Range = 0xFFFFFFFF;
|
pascal@13287
|
152 // { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }}
|
pascal@13287
|
153 // }
|
pascal@13287
|
154 // RC_INIT(inStream);
|
pascal@13287
|
155
|
pascal@17410
|
156 #ifndef NO_LZMA_HEADER
|
pascal@17410
|
157 #ifdef CHECK_LZMA_HEADER
|
pascal@17410
|
158 cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1)
|
pascal@17410
|
159 je lzip_header
|
pascal@17412
|
160 cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8)
|
pascal@17410
|
161 jne no_header
|
pascal@17410
|
162 add $13-6, SI // skip lzma header
|
pascal@17410
|
163 lzip_header:
|
pascal@17410
|
164 add $6, SI // skip lzip header
|
pascal@17410
|
165 no_header:
|
pascal@17410
|
166 #else
|
pascal@17410
|
167 add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8)
|
pascal@17410
|
168 #endif
|
pascal@17410
|
169 #endif
|
pascal@13287
|
170 setrep:
|
pascal@13287
|
171 call RC_LOAD_BYTE
|
pascal@13287
|
172 decb Range(BP)
|
pascal@13287
|
173 loop setrep
|
pascal@13287
|
174
|
pascal@13287
|
175 lzdmainlp:
|
pascal@13287
|
176 // while(1) {
|
pascal@13287
|
177 // CProb *prob;
|
pascal@13287
|
178 // int posState = (int)((nowPos) & posStateMask);
|
pascal@13287
|
179 //
|
pascal@13287
|
180 // prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState;
|
pascal@13287
|
181 // if (Bit0(prob)) { /* char */
|
pascal@13287
|
182
|
pascal@13287
|
183 xor DX, DX
|
pascal@13287
|
184 call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
|
pascal@13287
|
185 mov $state, DI
|
pascal@13287
|
186 jc lzdstring
|
pascal@13287
|
187
|
pascal@13287
|
188 // prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ *
|
pascal@13287
|
189 // ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc))));
|
pascal@13287
|
190
|
pascal@13287
|
191 #if PROP_LC != 0
|
pascal@20184
|
192 # ifdef ONLY8086
|
pascal@20184
|
193 movb $8-PROP_LC, %cl
|
pascal@20184
|
194 shrb %cl, %bl
|
pascal@20184
|
195 # else
|
pascal@13287
|
196 shrb $8-PROP_LC, %bl
|
pascal@20184
|
197 # endif
|
pascal@13287
|
198 #endif
|
pascal@13287
|
199
|
pascal@13287
|
200 #if PROP_LP != 0
|
pascal@13287
|
201 movb posState2(BP), %dl
|
pascal@20184
|
202 # ifdef ONLY8086
|
pascal@20184
|
203 movb $PROP_LC, %cl
|
pascal@20184
|
204 shl %cl, DX
|
pascal@20184
|
205 # else
|
pascal@13287
|
206 shl $PROP_LC, DX
|
pascal@20184
|
207 # endif
|
pascal@13287
|
208 movb $0, %bh
|
pascal@13287
|
209 add BX, DX
|
pascal@13287
|
210 #endif
|
pascal@13287
|
211
|
pascal@13287
|
212 movb $3, %ah
|
pascal@13287
|
213 mul BX // dx = 3*bh
|
pascal@13287
|
214 add $1846, AX
|
pascal@13287
|
215
|
pascal@13287
|
216 // int symbol = 1;
|
pascal@13287
|
217
|
pascal@13287
|
218 CWD
|
pascal@13287
|
219 inc DX // symbol = 1
|
pascal@13287
|
220 xchg AX, CX // save prob
|
pascal@13287
|
221
|
pascal@13287
|
222 // if (state >= kNumLitStates /*7*/) { /* previous was string */
|
pascal@13287
|
223 // if (state < 4) state = 0;
|
pascal@13287
|
224
|
pascal@13287
|
225 lzd6z:
|
pascal@13287
|
226 subb $3, (BP, DI)
|
pascal@13287
|
227
|
pascal@13287
|
228 // if (state < 4) state = 0;
|
pascal@13287
|
229
|
pascal@13287
|
230 jnc lzd6
|
pascal@13287
|
231 movb %dh, (BP, DI) // %dh = 0
|
pascal@13287
|
232
|
pascal@13287
|
233 lzd6:
|
pascal@13287
|
234 // else if (state < 10) state -= 3;
|
pascal@13287
|
235
|
pascal@13287
|
236 cmpb $10-3, (BP, DI)
|
pascal@13287
|
237
|
pascal@13287
|
238 // else state -= 6;
|
pascal@13287
|
239
|
pascal@13287
|
240 jnb lzd6z
|
pascal@13287
|
241 cmpb $7-3-1, (BP, DI)
|
pascal@13287
|
242 jbe lzd3
|
pascal@13287
|
243
|
pascal@13287
|
244 // int matchByte = outStream[nowPos - rep0];
|
pascal@13287
|
245
|
pascal@13287
|
246 call DicoRep02ESDI // %bl = outStream[nowPos - rep0];
|
pascal@13287
|
247
|
pascal@13287
|
248 // do {
|
pascal@13287
|
249 // int bit;
|
pascal@13287
|
250 // CProb *probLit;
|
pascal@13287
|
251 // matchByte <<= 1; bit = (matchByte & 0x100);
|
pascal@13287
|
252
|
pascal@13287
|
253 movb $1, %bh
|
pascal@13287
|
254 lzd4:
|
pascal@13287
|
255 shlb $1, %bl // matchByte <<= 1
|
pascal@13287
|
256 sbb DI, DI // save bit=C
|
pascal@13287
|
257
|
pascal@13287
|
258 // probLit = prob + 0x100 + bit + symbol;
|
pascal@13287
|
259
|
pascal@13287
|
260 mov CX, AX // restore prob
|
pascal@13287
|
261 adcb %bh, %ah // + bit + 0x100
|
pascal@13287
|
262
|
pascal@13287
|
263 // RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break)
|
pascal@13287
|
264
|
pascal@13287
|
265 call Bit1axdx // C,%ax = Bit1(prob+%ax)
|
pascal@13287
|
266 rclb $1, %dl // symbol <<= 1; symbol |= C
|
pascal@13287
|
267 jc lzd5 // if symbol >= 0x100
|
pascal@13287
|
268 cmp DI, AX
|
pascal@13287
|
269 jz lzd4 // if bit == Bit1(prob+%ax)
|
pascal@13287
|
270
|
pascal@13287
|
271 // } while (symbol < 0x100);
|
pascal@13287
|
272 // }
|
pascal@13287
|
273 lzd3:
|
pascal@13287
|
274 // while (symbol < 0x100) {
|
pascal@13287
|
275 // CProb *probLit = prob + symbol;
|
pascal@13287
|
276 // RC_GET_BIT(probLit, symbol)
|
pascal@13287
|
277 // }
|
pascal@13287
|
278
|
pascal@13287
|
279 xor BX, BX
|
pascal@13287
|
280 jmp lzd4
|
pascal@13287
|
281 lzd5:
|
pascal@13287
|
282
|
pascal@13287
|
283 // outStream[nowPos++] = previousByte = (Byte)symbol;
|
pascal@13287
|
284
|
pascal@13287
|
285 xchg AX, DX
|
pascal@13287
|
286 call outchar // %bl = outStream[nowPos++] = %al;
|
pascal@13287
|
287 jmp lzdmainlp
|
pascal@13287
|
288
|
pascal@13287
|
289 // }
|
pascal@13287
|
290
|
pascal@13287
|
291 lzdstring:
|
pascal@13287
|
292 mov $1, CX
|
pascal@13287
|
293
|
pascal@13287
|
294 // else { /* string */
|
pascal@13287
|
295 // prob = p + IsRep /*192*/ + state;
|
pascal@13287
|
296
|
pascal@13287
|
297 movb $192, %dl
|
pascal@13287
|
298 addb (BP, DI), %dl
|
pascal@13287
|
299 mov $rep0, DI
|
pascal@13287
|
300
|
pascal@13287
|
301 // if (Bit0(prob)) {
|
pascal@13287
|
302
|
pascal@13287
|
303 call Bit1dx // Bit1(prob)
|
pascal@13287
|
304 jc lzd8
|
pascal@13287
|
305
|
pascal@13287
|
306 // rep3 = rep2; rep2 = rep1; rep1 = rep0;
|
pascal@13287
|
307 // state = (state < kNumLitStates /*7*/) ? 0 : 3;
|
pascal@13287
|
308
|
pascal@13287
|
309 stc
|
pascal@13287
|
310
|
pascal@13287
|
311 // prob = p + LenCoder /*818*/;
|
pascal@13287
|
312
|
pascal@13287
|
313 mov $818, DX
|
pascal@13287
|
314
|
pascal@13287
|
315 // }
|
pascal@13287
|
316
|
pascal@13287
|
317 jmp lzd11a
|
pascal@13287
|
318
|
pascal@13287
|
319 // else {
|
pascal@13287
|
320 lzd8:
|
pascal@13287
|
321 // prob += kNumStates /*12*/;
|
pascal@13287
|
322 // if (Bit0(prob)) {
|
pascal@13287
|
323 call Bit1dx12 // prob += 12; Bit1(prob)
|
pascal@13287
|
324 jc lzd11
|
pascal@13287
|
325 // prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/)
|
pascal@13287
|
326 // + posState;
|
pascal@13287
|
327 movb $240, %dl // dh=0
|
pascal@13287
|
328
|
pascal@13287
|
329 // if (Bit0(prob)) {
|
pascal@13287
|
330
|
pascal@13287
|
331 call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
|
pascal@13287
|
332 jc lzd12
|
pascal@13287
|
333
|
pascal@13287
|
334 // // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR;
|
pascal@13287
|
335 // state = (state < kNumLitStates /*7*/) ? 9 : 11;
|
pascal@13287
|
336
|
pascal@13287
|
337 movb $9, %dl
|
pascal@13287
|
338
|
pascal@13287
|
339 // len++; goto string;
|
pascal@13287
|
340 jmp lzd13string // ax = 0
|
pascal@13287
|
341 // }
|
pascal@13287
|
342 // }
|
pascal@13287
|
343 // else {
|
pascal@13287
|
344 lzd11:
|
pascal@13287
|
345 // UInt32 distance = rep1;
|
pascal@13287
|
346 // prob += kNumStates /*12*/;
|
pascal@13287
|
347 // if (!Bit0(prob)) {
|
pascal@13287
|
348
|
pascal@13287
|
349 call Bit1dx12 // prob += 12; Bit1(prob)
|
pascal@13287
|
350 jnc lzd11z
|
pascal@13287
|
351
|
pascal@13287
|
352 // prob += kNumStates /*12*/;
|
pascal@13287
|
353 // if (Bit0(prob)) distance = rep2;
|
pascal@13287
|
354
|
pascal@13287
|
355 call Bit1dx12 // prob += 12; Bit1(prob)
|
pascal@13287
|
356 lzd11a:
|
pascal@13287
|
357 adcb %cl, %cl
|
pascal@13287
|
358
|
pascal@13287
|
359 // else { distance = rep3; rep3 = rep2; }
|
pascal@13287
|
360 // rep2 = rep1;
|
pascal@13287
|
361 // }
|
pascal@13287
|
362 // rep1 = rep0; rep0 = distance;
|
pascal@13287
|
363
|
pascal@13287
|
364 lzd11z:
|
pascal@20184
|
365 # ifdef ONLY8086
|
pascal@20184
|
366 shl $1, CX
|
pascal@20184
|
367 shl $1, CX // 8->32 bits
|
pascal@20184
|
368 sub CX, DI // &rep[cx]
|
pascal@20184
|
369 movw (BP, DI), %ax
|
pascal@20184
|
370 pushw 2(BP, DI)
|
pascal@20184
|
371 rotreplp:
|
pascal@20184
|
372 movb 4(BP, DI), %bl
|
pascal@20184
|
373 movb %bl, (BP, DI)
|
pascal@20184
|
374 inc DI
|
pascal@20184
|
375 loop rotreplp
|
pascal@20184
|
376 popw %bx
|
pascal@20184
|
377 testb %dh, %dh
|
pascal@20184
|
378 jnz lzd10
|
pascal@20184
|
379 movw %ax, (BP, DI)
|
pascal@20184
|
380 movw %bx, 2(BP, DI)
|
pascal@20184
|
381 # else
|
pascal@13287
|
382 shl $2, CX // 8->32 bits
|
pascal@13287
|
383 sub CX, DI // &rep[cx]
|
pascal@13287
|
384 movl (BP, DI), %eax
|
pascal@13287
|
385 rotreplp:
|
pascal@13287
|
386 movb 4(BP, DI), %bl
|
pascal@13287
|
387 movb %bl, (BP, DI)
|
pascal@13287
|
388 inc DI
|
pascal@13287
|
389 loop rotreplp
|
pascal@13287
|
390 testb %dh, %dh
|
pascal@13287
|
391 jnz lzd10
|
pascal@13287
|
392 movl %eax, (BP, DI)
|
pascal@20184
|
393 # endif
|
pascal@13287
|
394
|
pascal@13287
|
395 // }
|
pascal@13287
|
396 lzd12:
|
pascal@13287
|
397 // state = (state < kNumLitStates /*7*/) ? 8 : 11;
|
pascal@13287
|
398
|
pascal@13287
|
399 movb $0x08, %cl
|
pascal@13287
|
400
|
pascal@13287
|
401 // prob = p + RepLenCoder /*1332*/;
|
pascal@13287
|
402
|
pascal@13287
|
403 mov $1332, DX
|
pascal@13287
|
404
|
pascal@13287
|
405 // }
|
pascal@13287
|
406 lzd10:
|
pascal@13287
|
407 push CX // CX = 0
|
pascal@13287
|
408
|
pascal@13287
|
409 // { /* get len */
|
pascal@13287
|
410 // int numBits, offset;
|
pascal@13287
|
411 // CProb *probLen = prob + LenChoice /*0*/;
|
pascal@13287
|
412 // numBits = kLenNumLowBits /*3*/;
|
pascal@13287
|
413
|
pascal@13287
|
414 movb $8, %cl // numBits : 3,3,8
|
pascal@13287
|
415
|
pascal@13287
|
416 // if (Bit0(probLen)) {
|
pascal@13287
|
417
|
pascal@13287
|
418 call Bit1dx // Bit1(prob)
|
pascal@13287
|
419 xchg AX, BX
|
pascal@13287
|
420 inc DX
|
pascal@13287
|
421 jnc lzd15 // bx=0
|
pascal@13287
|
422
|
pascal@13287
|
423 // probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/);
|
pascal@13287
|
424 // offset = 0;
|
pascal@13287
|
425 // }
|
pascal@13287
|
426 // else {
|
pascal@13287
|
427 // probLen = prob + LenChoice2 /*1*/;
|
pascal@13287
|
428
|
pascal@13287
|
429 call Bit1dx // Bit1(prob)
|
pascal@13287
|
430 add AX, BX
|
pascal@13287
|
431
|
pascal@13287
|
432 #if PROP_PB != 0
|
pascal@13287
|
433 inc AX // ah=0
|
pascal@13287
|
434 #endif
|
pascal@13287
|
435 jc lzd16 // %ax=0, %bx=-2
|
pascal@13287
|
436 lzd15:
|
pascal@13287
|
437 #if PROP_PB != 0
|
pascal@13287
|
438 movb $8, %al
|
pascal@13287
|
439 mulb posState(BP)
|
pascal@13287
|
440 #endif
|
pascal@13287
|
441
|
pascal@13287
|
442 // if (Bit0(probLen)) {
|
pascal@13287
|
443 // probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/);
|
pascal@13287
|
444
|
pascal@13287
|
445 movb $3, %cl // numBits : 3,3,8
|
pascal@13287
|
446 lzd16:
|
pascal@13287
|
447 #if PROP_PB != 0
|
pascal@13287
|
448 add $2-128-1, AX // probLen : 2,130,258
|
pascal@13287
|
449 #else
|
pascal@13287
|
450 mov $2-128-1, AX // probLen : 2,130,258
|
pascal@13287
|
451 #endif
|
pascal@13287
|
452 add DX, AX
|
pascal@13287
|
453 mov $-8+1, DX // offset : 0,8,16
|
pascal@13287
|
454 lzdargslp:
|
pascal@13287
|
455 add $8, DX
|
pascal@13287
|
456 add $128, AX
|
pascal@13287
|
457 inc BX
|
pascal@13287
|
458 jle lzdargslp // leave with bx=1
|
pascal@13287
|
459
|
pascal@13287
|
460 // offset = kLenNumLowSymbols /*8*/;
|
pascal@13287
|
461 // //numBits = kLenNumMidBits /*3*/;
|
pascal@13287
|
462 // }
|
pascal@13287
|
463 // else {
|
pascal@13287
|
464 // probLen = prob + LenHigh /*258*/;
|
pascal@13287
|
465 // offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/;
|
pascal@13287
|
466 // numBits = kLenNumHighBits /*8*/;
|
pascal@13287
|
467 // }
|
pascal@13287
|
468 // }
|
pascal@13287
|
469 // RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset;
|
pascal@13287
|
470
|
pascal@13287
|
471 push DX
|
pascal@13287
|
472 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
|
pascal@13287
|
473 pop DX
|
pascal@13287
|
474 add DX, AX // offset
|
pascal@13287
|
475 pop DX // 0
|
pascal@13287
|
476 lzd13string:
|
pascal@13287
|
477 push AX
|
pascal@13287
|
478
|
pascal@13287
|
479 // state = (state < kNumLitStates /*7*/) ? dl : dl|3;
|
pascal@13287
|
480
|
pascal@13287
|
481 movb $7, %cl
|
pascal@13287
|
482 cmpb %cl, state(BP)
|
pascal@13287
|
483 jb new_state
|
pascal@13287
|
484 orb $3, %dl
|
pascal@13287
|
485 new_state:
|
pascal@13287
|
486 movb %dl, state(BP)
|
pascal@13287
|
487
|
pascal@13287
|
488 // } /* get len */
|
pascal@13287
|
489 // if (state < 4) {
|
pascal@13287
|
490
|
pascal@13287
|
491 cmpb $4-1, %dl
|
pascal@13287
|
492 ja lzd19
|
pascal@13287
|
493
|
pascal@13287
|
494 // int posSlot;
|
pascal@13287
|
495 // state += kNumLitStates /*7*/;
|
pascal@13287
|
496
|
pascal@13287
|
497 addb %cl, state(BP)
|
pascal@13287
|
498
|
pascal@13287
|
499 // prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ?
|
pascal@13287
|
500 // len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/);
|
pascal@13287
|
501
|
pascal@13287
|
502 cmp $4+1, AX
|
pascal@13287
|
503 jb lzd21
|
pascal@13287
|
504 mov $3+1, AX
|
pascal@13287
|
505
|
pascal@13287
|
506 lzd21:
|
pascal@13287
|
507
|
pascal@13287
|
508 dec CX // cx = 6
|
pascal@13287
|
509 shl %cl, AX
|
pascal@13287
|
510 add $432-64, AX
|
pascal@13287
|
511
|
pascal@13287
|
512 // RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot);
|
pascal@13287
|
513
|
pascal@13287
|
514 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
|
pascal@13287
|
515
|
pascal@13287
|
516 // if (posSlot >= kStartPosModelIndex /*4*/) {
|
pascal@13287
|
517 // int numDirectBits = ((posSlot >> 1) - 1);
|
pascal@13287
|
518
|
pascal@13287
|
519 #ifndef FLAT32
|
pascal@13287
|
520 movw %cx, 2(%bp, %di) // %cx = 0
|
pascal@13287
|
521 #endif
|
pascal@13287
|
522 mov AX, (BP, DI)
|
pascal@13287
|
523 mov AX, CX
|
pascal@13287
|
524 shrw $1, CX
|
pascal@13287
|
525 dec CX
|
pascal@13287
|
526 cmpb $4, %al
|
pascal@13287
|
527 jb lzd22
|
pascal@13287
|
528
|
pascal@13287
|
529 // rep0 = (2 | ((UInt32)posSlot & 1));
|
pascal@13287
|
530
|
pascal@13287
|
531 andb %bl, (BP, DI) // %bx=1
|
pascal@13287
|
532 orb $2, (BP, DI)
|
pascal@13287
|
533
|
pascal@13287
|
534 // if (posSlot < kEndPosModelIndex /*14*/) {
|
pascal@13287
|
535
|
pascal@13287
|
536 cmpb $14, %al
|
pascal@13287
|
537 jnb lzd23
|
pascal@13287
|
538
|
pascal@13287
|
539 // rep0 <<= numDirectBits;
|
pascal@13287
|
540
|
pascal@13287
|
541 neg AX
|
pascal@20184
|
542 # ifdef ONLY8086
|
pascal@20184
|
543 pushw %cx
|
pascal@20184
|
544 movb $0, %ch
|
pascal@20184
|
545 shllrep0:
|
pascal@20184
|
546 shlw $1, (BP, DI)
|
pascal@20184
|
547 rclw $1, 2(BP, DI)
|
pascal@20184
|
548 loop shllrep0
|
pascal@20184
|
549 popw %cx
|
pascal@20184
|
550 # else
|
pascal@13287
|
551 shll %cl, (BP, DI)
|
pascal@20184
|
552 # endif
|
pascal@13287
|
553 add (BP, DI), AX
|
pascal@13287
|
554
|
pascal@13287
|
555 // prob = p + SpecPos /*688*/ + rep0 - posSlot - 1;
|
pascal@13287
|
556
|
pascal@13287
|
557 add $687, AX
|
pascal@13287
|
558 jmp lzd24
|
pascal@13287
|
559
|
pascal@13287
|
560 // }
|
pascal@13287
|
561 // else {
|
pascal@13287
|
562 lzd23:
|
pascal@13287
|
563 // numDirectBits -= kNumAlignBits /*4*/;
|
pascal@13287
|
564 // do {
|
pascal@13287
|
565 // RC_NORMALIZE; Range >>= 1; rep0 <<= 1;
|
pascal@13287
|
566 // if (Code >= Range) { Code -= Range; rep0 |= 1; }
|
pascal@13287
|
567
|
pascal@13287
|
568 lzd23z:
|
pascal@13287
|
569 call RC_NORMALIZE
|
pascal@20184
|
570 # ifdef ONLY8086
|
pascal@20184
|
571 pushw %dx
|
pascal@20184
|
572 shrw $1, Range+2(BP)
|
pascal@20184
|
573 rcrw $1, Range(BP)
|
pascal@20184
|
574 movw Range(BP), %ax
|
pascal@20184
|
575 movw Range+2(BP), %dx
|
pascal@20184
|
576 cmpw Code+2(BP), %dx
|
pascal@20184
|
577 ja lzd25
|
pascal@20184
|
578 jb lzd25x
|
pascal@20184
|
579 cmpw Code(BP), %ax
|
pascal@20184
|
580 ja lzd25
|
pascal@20184
|
581 lzd25x:
|
pascal@20184
|
582 subw %ax, Code(BP)
|
pascal@20184
|
583 sbbw %dx, Code+2(BP)
|
pascal@20184
|
584 stc
|
pascal@20184
|
585 lzd25:
|
pascal@20184
|
586 popw %dx
|
pascal@20184
|
587 rclw $1, (BP, DI)
|
pascal@20184
|
588 rclw $1, 2(BP, DI)
|
pascal@20184
|
589 # else
|
pascal@13287
|
590 shrl $1, Range(BP)
|
pascal@13287
|
591 movl Range(BP), %eax
|
pascal@13287
|
592 cmpl Code(BP), %eax
|
pascal@13287
|
593 ja lzd25
|
pascal@13287
|
594 subl %eax, Code(BP)
|
pascal@13287
|
595 stc
|
pascal@13287
|
596 lzd25:
|
pascal@13287
|
597 rcll $1, (BP, DI)
|
pascal@20184
|
598 # endif
|
pascal@13287
|
599
|
pascal@13287
|
600 // } while (--numDirectBits != 0);
|
pascal@13287
|
601
|
pascal@13289
|
602 cmpb $4+1, %cl
|
pascal@13287
|
603 loopne lzd23z
|
pascal@13287
|
604
|
pascal@13287
|
605 // prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/;
|
pascal@13287
|
606 // rep0 <<= numDirectBits;
|
pascal@13287
|
607
|
pascal@20184
|
608 # ifdef ONLY8086
|
pascal@20184
|
609 pushw %cx
|
pascal@20184
|
610 movb $0, %ch
|
pascal@20184
|
611 shlrep0:
|
pascal@20184
|
612 shlw $1, (BP, DI)
|
pascal@20184
|
613 rclw $1, 2(BP, DI)
|
pascal@20184
|
614 loop shlrep0
|
pascal@20184
|
615 popw %cx
|
pascal@20184
|
616 # else
|
pascal@13287
|
617 shll %cl, (BP, DI)
|
pascal@20184
|
618 # endif
|
pascal@13287
|
619 mov $802, AX
|
pascal@13287
|
620 // }
|
pascal@13287
|
621
|
pascal@13287
|
622 lzd24:
|
pascal@13287
|
623 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
|
pascal@13287
|
624
|
pascal@13287
|
625 // {
|
pascal@13287
|
626 // int i = 1, mi = 1;
|
pascal@13287
|
627 // do {
|
pascal@13287
|
628 // CProb *prob3 = prob + mi;
|
pascal@13287
|
629 // RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
|
pascal@13287
|
630
|
pascal@13287
|
631 orb %dh, (BP, DI) // update rep0 with DirectBits
|
pascal@13287
|
632
|
pascal@13287
|
633 // i <<= 1;
|
pascal@13287
|
634 // } while(--numDirectBits != 0);
|
pascal@13287
|
635 // }
|
pascal@13287
|
636 // } else rep0 = posSlot;
|
pascal@13287
|
637 lzd22:
|
pascal@13287
|
638 // if (++rep0 == (UInt32)(0)) break; /* EOF */
|
pascal@13287
|
639
|
pascal@20184
|
640 # ifdef ONLY8086
|
pascal@20184
|
641 incw (BP, DI)
|
pascal@20184
|
642 jnz lzd19
|
pascal@20184
|
643 incw 2(BP, DI)
|
pascal@20184
|
644 # else
|
pascal@13287
|
645 incl (BP, DI)
|
pascal@20184
|
646 # endif
|
pascal@13287
|
647
|
pascal@13287
|
648 lzd19:
|
pascal@13287
|
649 pop CX
|
pascal@13287
|
650 jz lzdone
|
pascal@13287
|
651
|
pascal@13287
|
652 // }
|
pascal@13287
|
653 // len += kMatchMinLen;/*2*/
|
pascal@13287
|
654
|
pascal@13287
|
655 inc CX
|
pascal@13287
|
656
|
pascal@13287
|
657 // string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR;
|
pascal@13287
|
658 // do {
|
pascal@13287
|
659 lzd13z:
|
pascal@13287
|
660 // previousByte = outStream[nowPos - rep0];
|
pascal@13287
|
661 // outStream[nowPos++] = previousByte;
|
pascal@13287
|
662
|
pascal@13287
|
663 call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0]
|
pascal@13287
|
664
|
pascal@13287
|
665 // } while(--len != 0);
|
pascal@13287
|
666
|
pascal@13287
|
667 loop lzd13z
|
pascal@13287
|
668
|
pascal@13287
|
669 // } /* char/string */
|
pascal@13287
|
670 // }
|
pascal@13287
|
671
|
pascal@13287
|
672 jmp lzdmainlp
|
pascal@13287
|
673
|
pascal@13287
|
674 lzdone:
|
pascal@13287
|
675 // //RC_NORMALIZE;
|
pascal@13287
|
676 // //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos;
|
pascal@13287
|
677 // return LZMA_RESULT_OK;
|
pascal@13287
|
678 call Dico2ESDI // set es & di (rep0 = 0)
|
pascal@13287
|
679 lea ws2(BP), SP // dealloc
|
pascal@13287
|
680 ret
|
pascal@13287
|
681 // }
|
pascal@13287
|
682
|
pascal@13287
|
683 // al = outStream[nowPos - rep0];
|
pascal@13287
|
684
|
pascal@13287
|
685 /*
|
pascal@13287
|
686 * output es:di, al
|
pascal@13287
|
687 * scratch bh, cl, flags
|
pascal@13287
|
688 */
|
pascal@13287
|
689
|
pascal@13287
|
690 DicoRep02ESDI:
|
pascal@13287
|
691 stc
|
pascal@13287
|
692
|
pascal@13287
|
693 // bl = outStream[nowPos];
|
pascal@13287
|
694
|
pascal@13287
|
695 /*
|
pascal@13287
|
696 * output es:di, bl
|
pascal@13287
|
697 * scratch bh, cl, flags
|
pascal@13287
|
698 */
|
pascal@13287
|
699
|
pascal@13287
|
700 Dico2ESDI:
|
pascal@19391
|
701 #if !defined(FLAT32) && !defined(FLAT16OUT)
|
pascal@20184
|
702 # ifdef ONLY8086
|
pascal@20184
|
703 pushw %ax
|
pascal@20184
|
704 movw nowPos(%bp), %bx
|
pascal@20184
|
705 movw nowPos+2(%bp), %ax
|
pascal@20184
|
706 jnc Dico2ESDIz
|
pascal@20184
|
707 subw rep0(%bp), %bx
|
pascal@20184
|
708 sbbw rep0+2(%bp), %ax
|
pascal@20184
|
709 Dico2ESDIz:
|
pascal@20184
|
710 movw $0xF, %di
|
pascal@20184
|
711 andw %bx, %di
|
pascal@20184
|
712 pushw %cx
|
pascal@20184
|
713 movb $4, %cl
|
pascal@20184
|
714 shrw %cl, %bx
|
pascal@20184
|
715 shlw %cl, %ax
|
pascal@20184
|
716 popw %cx
|
pascal@20184
|
717 addb %al, %bh
|
pascal@20184
|
718 popw %ax
|
pascal@20184
|
719 # else
|
pascal@13287
|
720 movl nowPos(%bp), %ebx
|
pascal@13287
|
721 jnc Dico2ESDIz
|
pascal@13287
|
722 subl rep0(%bp), %ebx
|
pascal@13287
|
723 Dico2ESDIz:
|
pascal@13287
|
724 movw %bx, %di
|
pascal@13287
|
725 xorw %bx, %bx
|
pascal@13287
|
726 shrl $4, %ebx
|
pascal@20184
|
727 # endif
|
pascal@13287
|
728 movw %bx, %es
|
pascal@19391
|
729 #else
|
pascal@19396
|
730 mov nowPos(BP), DI
|
pascal@19391
|
731 jnc Dico2ESDIz
|
pascal@19396
|
732 sub rep0(BP), DI
|
pascal@19391
|
733 Dico2ESDIz:
|
pascal@19391
|
734 #endif
|
pascal@19391
|
735 #ifdef FLAT32
|
pascal@19391
|
736 movb (DI), %bl
|
pascal@19391
|
737 #else
|
pascal@13287
|
738 movb %es:(%di), %bl
|
pascal@13287
|
739 #endif
|
pascal@13287
|
740 ret
|
pascal@13287
|
741
|
pascal@13287
|
742 outcharDico:
|
pascal@13287
|
743
|
pascal@13287
|
744 // bl = outStream[nowPos++] = outStream[nowPos - rep0]
|
pascal@13287
|
745
|
pascal@13287
|
746 /*
|
pascal@13287
|
747 * output es:di, bl
|
pascal@13287
|
748 * update nowPos
|
pascal@13287
|
749 * scratch ax, dx, bh, cl, flags
|
pascal@13287
|
750 */
|
pascal@13287
|
751
|
pascal@13287
|
752 call DicoRep02ESDI // %bl = outStream[nowPos - rep0]
|
pascal@13287
|
753 xchg AX, BX
|
pascal@13287
|
754 outchar:
|
pascal@13287
|
755
|
pascal@13287
|
756 // bl = outStream[nowPos++] = previousByte = al;
|
pascal@13287
|
757
|
pascal@13287
|
758 /*
|
pascal@13287
|
759 * output bl
|
pascal@13287
|
760 * update nowPos
|
pascal@13287
|
761 * scratch ax, dx, bh, di, cl, flags
|
pascal@13287
|
762 */
|
pascal@13287
|
763
|
pascal@13287
|
764 clc
|
pascal@13287
|
765 call Dico2ESDI
|
pascal@13287
|
766 stosb
|
pascal@13287
|
767 xchg AX, BX // previous byte
|
pascal@13287
|
768
|
pascal@13287
|
769 // int posState = (int)((nowPos) & posStateMask);
|
pascal@13287
|
770
|
pascal@13287
|
771 #if PROP_PB != 0 && PROP_LP != 0
|
pascal@13287
|
772 addw $0x0101, posState2(BP)
|
pascal@13287
|
773 andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP)
|
pascal@13287
|
774 #else
|
pascal@13287
|
775 # if PROP_PB != 0
|
pascal@13287
|
776 incb posState(BP)
|
pascal@13287
|
777 andb $((1 << PROP_PB) -1), posState(BP)
|
pascal@13287
|
778 # endif
|
pascal@13287
|
779 # if PROP_LP != 0
|
pascal@13287
|
780 incb posState2(BP)
|
pascal@13287
|
781 andb $((1 << PROP_LP) -1), posState2(BP)
|
pascal@13287
|
782 # endif
|
pascal@13287
|
783 #endif
|
pascal@20184
|
784 #ifdef ONLY8086
|
pascal@20184
|
785 incw nowPos(BP)
|
pascal@20184
|
786 jnz incnowPosDone
|
pascal@20184
|
787 incw nowPos+2(BP)
|
pascal@20184
|
788 incnowPosDone:
|
pascal@20184
|
789 #else
|
pascal@13287
|
790 incl nowPos(BP)
|
pascal@20184
|
791 #endif
|
pascal@13287
|
792 ret
|
pascal@13287
|
793
|
pascal@13287
|
794 //
|
pascal@13287
|
795 // #define RC_NORMALIZE if (Range < kTopValue)
|
pascal@13287
|
796 // { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
|
pascal@13287
|
797
|
pascal@13287
|
798 /*
|
pascal@13287
|
799 * update Range, Code, ds:si
|
pascal@13287
|
800 * scratch flags
|
pascal@13287
|
801 */
|
pascal@13287
|
802
|
pascal@13287
|
803 RC_NORMALIZE:
|
pascal@13287
|
804 cmpb $0, Range+3(BP)
|
pascal@13287
|
805 jne RC_NORMALIZE_1
|
pascal@13287
|
806 RC_LOAD_BYTE:
|
pascal@13287
|
807 push AX
|
pascal@20184
|
808 #ifdef ONLY8086
|
pascal@20184
|
809 movw Range+1(BP), %ax
|
pascal@20184
|
810 movw %ax, Range+2(BP)
|
pascal@20184
|
811 movw Code+1(BP), %ax
|
pascal@20184
|
812 movw %ax, Code+2(BP)
|
pascal@20184
|
813 xorw %ax, %ax
|
pascal@20184
|
814 movb Range(BP), %ah
|
pascal@20184
|
815 movw %ax, Range(BP)
|
pascal@20184
|
816 movb Code(BP), %ah
|
pascal@20184
|
817 movw %ax, Code(BP)
|
pascal@20184
|
818 #else
|
pascal@13287
|
819 shll $8, Range(BP)
|
pascal@13287
|
820 shll $8, Code(BP)
|
pascal@20184
|
821 #endif
|
pascal@19391
|
822 #if !defined(FLAT16) && !defined(FLAT32)
|
pascal@13287
|
823 testw %si, %si
|
pascal@13287
|
824 jns RC_READ_BYTE
|
pascal@13287
|
825 movw %ds, %ax
|
pascal@13287
|
826 incw %ax
|
pascal@13287
|
827 movw %ax, %ds
|
pascal@13287
|
828 addw $-16, %si
|
pascal@13287
|
829 RC_READ_BYTE:
|
pascal@13287
|
830 #endif
|
pascal@13287
|
831 lodsb
|
pascal@13287
|
832 movb %al, Code(BP)
|
pascal@13287
|
833 pop AX
|
pascal@13287
|
834 RC_NORMALIZE_1:
|
pascal@13287
|
835 ret
|
pascal@13287
|
836
|
pascal@13287
|
837 // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
|
pascal@13287
|
838
|
pascal@13287
|
839 Bit1state:
|
pascal@13287
|
840 movb $16, %al
|
pascal@13287
|
841 mulb state(BP)
|
pascal@13287
|
842 # if PROP_PB != 0
|
pascal@13287
|
843 addb posState(BP), %al
|
pascal@13287
|
844 # endif
|
pascal@13287
|
845 Bit1axdx:
|
pascal@13287
|
846 add DX, AX
|
pascal@13287
|
847 jmp Bit1
|
pascal@13287
|
848
|
pascal@13287
|
849 // prob += 12; Bit1(prob)
|
pascal@13287
|
850
|
pascal@13287
|
851 Bit1dx12:
|
pascal@13287
|
852 add $12, DX
|
pascal@13287
|
853 Bit1dx:
|
pascal@13287
|
854 mov DX, AX
|
pascal@13287
|
855
|
pascal@13287
|
856 // static int Bit1(CProb *p)
|
pascal@13287
|
857
|
pascal@13287
|
858 Bit1:
|
pascal@13287
|
859 /*
|
pascal@13287
|
860 * input ax=p
|
pascal@13287
|
861 * output C, ax
|
pascal@13287
|
862 * update bound, Range, Code, ds:si
|
pascal@13287
|
863 * scratch flags
|
pascal@13287
|
864 */
|
pascal@13287
|
865
|
pascal@13287
|
866 // {
|
pascal@13287
|
867 // RC_NORMALIZE;
|
pascal@13287
|
868
|
pascal@13287
|
869 call RC_NORMALIZE // kill %ax, update %si
|
pascal@13287
|
870
|
pascal@20184
|
871 #ifdef ONLY8086
|
pascal@20184
|
872 pushw %ax
|
pascal@20184
|
873 pushw %cx
|
pascal@20184
|
874 pushw %dx
|
pascal@20184
|
875 pushw %di
|
pascal@20184
|
876 #else
|
pascal@13289
|
877 pushal
|
pascal@20184
|
878 #endif
|
pascal@13287
|
879
|
pascal@13287
|
880 xchg AX, DI
|
pascal@13287
|
881 add DI, DI // short *
|
pascal@13287
|
882
|
pascal@13287
|
883
|
pascal@13287
|
884 // bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p);
|
pascal@13287
|
885
|
pascal@20184
|
886 #ifdef ONLY8086
|
pascal@20184
|
887 movw Range(BP), %dx
|
pascal@20184
|
888 movw Range+2(BP), %ax
|
pascal@20184
|
889 movw $11, %cx
|
pascal@20184
|
890 shr11lp:
|
pascal@20184
|
891 shrw $1, %ax
|
pascal@20184
|
892 rcrw $1, %dx
|
pascal@20184
|
893 loop shr11lp
|
pascal@20184
|
894 movw %dx, %cx
|
pascal@20184
|
895 mulw (BP, DI)
|
pascal@20184
|
896 xchgw %ax, %cx
|
pascal@20184
|
897 mulw (BP, DI)
|
pascal@20184
|
898 addw %cx, %dx
|
pascal@20184
|
899 #else
|
pascal@13287
|
900 movl Range(BP), %eax
|
pascal@13287
|
901 shrl $11, %eax
|
pascal@13287
|
902 movzwl (BP, DI), %edx
|
pascal@13287
|
903 mull %edx
|
pascal@20184
|
904 #endif
|
pascal@13287
|
905
|
pascal@13287
|
906 // if (Code < bound) {
|
pascal@13287
|
907
|
pascal@20184
|
908 #ifdef ONLY8086
|
pascal@20184
|
909 cmpw Code+2(BP), %dx
|
pascal@20184
|
910 jb Bit1_1
|
pascal@20184
|
911 ja Bit1_1x
|
pascal@20184
|
912 cmpw Code(BP), %ax
|
pascal@20184
|
913 jbe Bit1_1
|
pascal@20184
|
914 Bit1_1x:
|
pascal@20184
|
915
|
pascal@20184
|
916 // Range = bound;
|
pascal@20184
|
917
|
pascal@20184
|
918 movw %ax, Range(BP)
|
pascal@20184
|
919 movw %dx, Range+2(BP)
|
pascal@20184
|
920 #else
|
pascal@13287
|
921 cmpl Code(BP), %eax
|
pascal@13287
|
922 jbe Bit1_1
|
pascal@13287
|
923
|
pascal@13287
|
924 // Range = bound;
|
pascal@13287
|
925
|
pascal@13287
|
926 movl %eax, Range(BP)
|
pascal@20184
|
927 #endif
|
pascal@13287
|
928
|
pascal@13287
|
929 // *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/;
|
pascal@13287
|
930
|
pascal@13287
|
931 movw $2048, %ax
|
pascal@13287
|
932
|
pascal@13287
|
933 // return 0;
|
pascal@13287
|
934
|
pascal@13287
|
935 jmp Bit1_2
|
pascal@13287
|
936
|
pascal@13287
|
937 // }
|
pascal@13287
|
938 // else {
|
pascal@13287
|
939
|
pascal@13287
|
940 Bit1_1:
|
pascal@13287
|
941
|
pascal@13287
|
942 // Range -= bound; Code -= bound;
|
pascal@13287
|
943
|
pascal@20184
|
944 #ifdef ONLY8086
|
pascal@20184
|
945 subw %ax, Range(BP)
|
pascal@20184
|
946 sbbw %dx, Range+2(BP)
|
pascal@20184
|
947 subw %ax, Code(BP)
|
pascal@20184
|
948 sbbw %dx, Code+2(BP)
|
pascal@20184
|
949 #else
|
pascal@13287
|
950 subl %eax, Range(BP)
|
pascal@13287
|
951 subl %eax, Code(BP)
|
pascal@20184
|
952 #endif
|
pascal@13287
|
953
|
pascal@13287
|
954 // *(p) -= (*(p)) >> kNumMoveBits /*5*/;
|
pascal@13287
|
955
|
pascal@13287
|
956 movw $31, %ax
|
pascal@13287
|
957
|
pascal@13287
|
958 // return 1;
|
pascal@13287
|
959
|
pascal@13287
|
960 stc
|
pascal@13287
|
961 Bit1_2:
|
pascal@13287
|
962 pushf
|
pascal@13287
|
963 subw (BP, DI), %ax
|
pascal@20184
|
964 #ifdef ONLY8086
|
pascal@20184
|
965 movb $5, %cl
|
pascal@20184
|
966 sarw %cl, %ax
|
pascal@20184
|
967 #else
|
pascal@13287
|
968 sarw $5, %ax
|
pascal@20184
|
969 #endif
|
pascal@13287
|
970 addw %ax, (BP, DI)
|
pascal@13287
|
971 popf
|
pascal@20184
|
972 #ifdef ONLY8086
|
pascal@20184
|
973 popw %di
|
pascal@20184
|
974 popw %dx
|
pascal@20184
|
975 popw %cx
|
pascal@20184
|
976 popw %ax
|
pascal@20184
|
977 #else
|
pascal@13289
|
978 popal
|
pascal@20184
|
979 #endif
|
pascal@13287
|
980 sbb AX, AX
|
pascal@13287
|
981
|
pascal@13287
|
982 // }
|
pascal@13287
|
983 // }
|
pascal@13287
|
984
|
pascal@13287
|
985 ret
|
pascal@13287
|
986
|
pascal@13287
|
987 RangeDecoder:
|
pascal@13287
|
988
|
pascal@13287
|
989 /*
|
pascal@13287
|
990 * input ax=probs cx=numLevels (< 8) bx=1
|
pascal@13287
|
991 * output ax=res (backward), dh (forward)
|
pascal@13287
|
992 * update bound, Range, Code, ds:si
|
pascal@13287
|
993 * scratch flags, cx=0, dl
|
pascal@13287
|
994 */
|
pascal@13287
|
995
|
pascal@13287
|
996 push BX
|
pascal@13287
|
997
|
pascal@13287
|
998 // { int i = numLevels; res = 1;
|
pascal@13287
|
999 mov BX, DX // res = 1
|
pascal@13287
|
1000
|
pascal@13287
|
1001 // do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0);
|
pascal@13287
|
1002
|
pascal@13287
|
1003 RangeDecoder_1:
|
pascal@13287
|
1004 push AX
|
pascal@13287
|
1005 call Bit1axdx // C,%ax = Bit1(prob+%ax)
|
pascal@13287
|
1006 rclb $1, %dl // res <<= 1; res |= C
|
pascal@13287
|
1007 andb %bl, %al // current bit
|
pascal@13287
|
1008 orb %al, %bh // store in bh
|
pascal@13287
|
1009 shlb $1, %bl // update max
|
pascal@13287
|
1010 pop AX
|
pascal@13287
|
1011 loop RangeDecoder_1
|
pascal@13287
|
1012
|
pascal@13287
|
1013 // res -= (1 << numLevels); }
|
pascal@13287
|
1014
|
pascal@13287
|
1015 xchg AX, BX // move bh to dh
|
pascal@13287
|
1016 xchg AX, DX // and dl to al
|
pascal@13287
|
1017 sub %dl, %al // sub max
|
pascal@13287
|
1018 pop BX
|
pascal@13287
|
1019 ret
|