wok view memtest/stuff/unlzma.S @ rev 25049
Update some wget_url
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jun 04 20:10:27 2022 +0000 (2022-06-04) |
parents | 8d938c826a9b |
children | 54dc5622a785 |
line source
1 // #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
2 //
3 // #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
4 // #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
5 // #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
6 //
7 //#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
8 // { UpdateBit0(p); mi <<= 1; A0; } else \
9 // { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
10 //
11 // #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
12 //
13 // #define RangeDecoderBitTreeDecode(probs, numLevels, res) \
14 // { int i = numLevels; res = 1; \
15 // do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
16 // res -= (1 << numLevels); }
17 /*
18 * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3
19 */
21 #define PROP_PB 2
22 #define PROP_LP 0
23 #define PROP_LC 3
24 #define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45))
26 // static const Byte *Buffer;
27 // static UInt32 bound, Code, Range;
29 /*
30 * Buffer register DS:SI
31 * all var based ws=ss:bp
32 */
34 rep0 = -4 // long
35 rep1 = rep0-4 // long
36 rep2 = rep0-8 // long
37 rep3 = rep0-12 // long
38 state = -17 // byte, 0..11
39 posState = state-1 // byte, 0..15
40 posState2 = posState-1 // byte, 0..15
41 scratched = rep0-16 // byte = 1
42 Code = -24 // long
43 outStream = -28 // long
44 nowPos = outStream // long
45 Range = Code-8 // long
46 #define LOCALS 32
48 // int LzmaDecode(CLzmaDecoderState *vs,
49 // const unsigned char *inStream,
50 // unsigned char *outStream)
51 // {
52 // CProb *p = vs->Probs;
53 // SizeT nowPos = 0;
54 // #define posStateMask = (1 << (vs->Properties.pb)) - 1;
55 // #define literalPosMask = (1 << (vs->Properties.lp)) - 1;
56 // int lc = vs->Properties.lc, state = 0, len = 0;
57 // UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
58 //
59 // {
60 // UInt32 i, numProbs = Literal /*1846*/
61 // + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp));
62 // for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1;
64 #define WS (1846+(768<<(PROP_LC+PROP_LP)))
65 #if (WS+WS+LOCALS) >= 65000
66 /* MAX WS = (1846+(768<<(8+4))) > 3MB! */
67 #error invalid (lc,lp,pb) : out of memory
68 #endif
70 ws1 = WS
71 ws2 = ws1*2
72 ws = ws2+LOCALS+15
74 #ifndef FLAT32
75 #define AX %ax
76 #define BX %bx
77 #define CX %cx
78 #define DX %dx
79 #define SI %si
80 #define DI %di
81 #define BP %bp
82 #define SP %sp
83 #define CWD cwd
84 #else
85 #define AX %eax
86 #define BX %ebx
87 #define CX %ecx
88 #define DX %edx
89 #define SI %esi
90 #define DI %edi
91 #define BP %ebp
92 #define SP %esp
93 #define CWD cdq
94 #endif
95 /*
96 * LzmaDecode:
97 #ifndef FLAT32
98 * input ds:si=inStream, es:di=outStream
99 * output outStream[], ds:si, es:di
100 .code 16
101 #else
102 * input esi=inStream, edi=outStream
103 * output outStream[], esi, edi
104 .code 32
105 #endif
106 */
108 mov $ws1, CX
109 #ifdef ONLY8086
110 .arch i8086
111 movw $2048/2, %ax
112 lzd1:
113 pushw %ax
114 #else
115 lzd1:
116 pushw $2048/2
117 #endif
118 loop lzd1
119 mov SP, BP
120 movb $((LOCALS+3)/4)*2, %cl
121 #ifdef ONLY8086
122 movw $1, %ax
123 cwd
124 initlocals:
125 pushw %dx
126 pushw %ax
127 #else
128 initlocals:
129 pushl $1
130 #endif
131 loop initlocals
133 #if !defined(FLAT32) && !defined(FLAT16OUT)
134 movb $4, %cl
135 movw %es, %bx
136 shrw %cl, %bx
137 movw %es, %dx
138 shlw %cl, %dx
139 addw %dx, %di
140 movw %di, outStream(%bp)
141 adcb %bh, outStream+2(%bp)
142 incw %cx
143 #else
144 movb $5, %cl
145 mov DI, outStream(BP)
146 #endif
148 // Byte previousByte = 0;
149 xor BX, BX
151 // #define RC_INIT(buffer)
152 // Buffer = buffer; Code = 0; Range = 0xFFFFFFFF;
153 // { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }}
154 // }
155 // RC_INIT(inStream);
157 #ifndef NO_LZMA_HEADER
158 #ifdef CHECK_LZMA_HEADER
159 cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1)
160 je lzip_header
161 cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8)
162 jne no_header
163 add $13-6, SI // skip lzma header
164 lzip_header:
165 add $6, SI // skip lzip header
166 no_header:
167 #else
168 add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8)
169 #endif
170 #endif
171 setrep:
172 call RC_LOAD_BYTE
173 decb Range(BP)
174 loop setrep
176 lzdmainlp:
177 // while(1) {
178 // CProb *prob;
179 // int posState = (int)((nowPos) & posStateMask);
180 //
181 // prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState;
182 // if (Bit0(prob)) { /* char */
184 xor DX, DX
185 call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
186 mov $state, DI
187 jc lzdstring
189 // prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ *
190 // ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc))));
192 #if PROP_LC != 0
193 # ifdef ONLY8086
194 movb $8-PROP_LC, %cl
195 shrb %cl, %bl
196 # else
197 shrb $8-PROP_LC, %bl
198 # endif
199 #else
200 xor %bx,%bx
201 #endif
203 #if PROP_LP != 0
204 movb posState2(BP), %dl
205 # if PROP_LC != 0
206 # ifdef ONLY8086
207 movb $PROP_LC, %cl
208 shl %cl, DX
209 # else
210 shl $PROP_LC, DX
211 # endif
212 movb $0, %bh
213 # endif
214 add BX, DX
215 #endif
217 #if PROP_LC == 0 && PROP_LP == 0
218 mov $1846, AX
219 #else
220 movb $3, %ah
221 mul BX // dx = 3*bh
222 add $1846, AX
223 #endif
225 // int symbol = 1;
227 CWD
228 inc DX // symbol = 1
229 xchg AX, CX // save prob
231 // if (state >= kNumLitStates /*7*/) { /* previous was string */
232 // if (state < 4) state = 0;
234 lzd6z:
235 subb $3, (BP, DI)
237 // if (state < 4) state = 0;
239 jnc lzd6
240 movb %dh, (BP, DI) // %dh = 0
242 lzd6:
243 // else if (state < 10) state -= 3;
245 cmpb $10-3, (BP, DI)
247 // else state -= 6;
249 jnb lzd6z
250 cmpb $7-3-1, (BP, DI)
251 jbe lzd3
253 // int matchByte = outStream[nowPos - rep0];
255 call DicoRep02ESDI // %bl = outStream[nowPos - rep0];
257 // do {
258 // int bit;
259 // CProb *probLit;
260 // matchByte <<= 1; bit = (matchByte & 0x100);
262 movb $1, %bh
263 lzd4:
264 shlb $1, %bl // matchByte <<= 1
265 sbb DI, DI // save bit=C
267 // probLit = prob + 0x100 + bit + symbol;
269 mov CX, AX // restore prob
270 adcb %bh, %ah // + bit + 0x100
272 // RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break)
274 call Bit1axdx // C,%ax = Bit1(prob+%ax)
275 rclb $1, %dl // symbol <<= 1; symbol |= C
276 jc lzd5 // if symbol >= 0x100
277 cmp DI, AX
278 jz lzd4 // if bit == Bit1(prob+%ax)
280 // } while (symbol < 0x100);
281 // }
282 lzd3:
283 // while (symbol < 0x100) {
284 // CProb *probLit = prob + symbol;
285 // RC_GET_BIT(probLit, symbol)
286 // }
288 xor BX, BX
289 jmp lzd4
290 lzd5:
292 // outStream[nowPos++] = previousByte = (Byte)symbol;
294 xchg AX, DX
295 call outchar // %bl = outStream[nowPos++] = %al;
296 jmp lzdmainlp
298 // }
300 lzdstring:
301 mov $1, CX
303 // else { /* string */
304 // prob = p + IsRep /*192*/ + state;
306 movb $192, %dl
307 addb (BP, DI), %dl
308 mov $rep0, DI
310 // if (Bit0(prob)) {
312 call Bit1dx // Bit1(prob)
313 jc lzd8
315 // rep3 = rep2; rep2 = rep1; rep1 = rep0;
316 // state = (state < kNumLitStates /*7*/) ? 0 : 3;
318 stc
320 // prob = p + LenCoder /*818*/;
322 mov $818, DX
324 // }
326 jmp lzd11a
328 // else {
329 lzd8:
330 // prob += kNumStates /*12*/;
331 // if (Bit0(prob)) {
332 call Bit1dx12 // prob += 12; Bit1(prob)
333 jc lzd11
334 // prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/)
335 // + posState;
336 movb $240, %dl // dh=0
338 // if (Bit0(prob)) {
340 call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
341 jc lzd12
343 // // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR;
344 // state = (state < kNumLitStates /*7*/) ? 9 : 11;
346 movb $9, %dl
348 // len++; goto string;
349 jmp lzd13string // ax = 0
350 // }
351 // }
352 // else {
353 lzd11:
354 // UInt32 distance = rep1;
355 // prob += kNumStates /*12*/;
356 // if (!Bit0(prob)) {
358 call Bit1dx12 // prob += 12; Bit1(prob)
359 jnc lzd11z
361 // prob += kNumStates /*12*/;
362 // if (Bit0(prob)) distance = rep2;
364 call Bit1dx12 // prob += 12; Bit1(prob)
365 lzd11a:
366 adcb %cl, %cl
368 // else { distance = rep3; rep3 = rep2; }
369 // rep2 = rep1;
370 // }
371 // rep1 = rep0; rep0 = distance;
373 lzd11z:
374 # ifdef ONLY8086
375 shl $1, CX
376 shl $1, CX // 8->32 bits
377 sub CX, DI // &rep[cx]
378 movw (BP, DI), %ax
379 pushw 2(BP, DI)
380 rotreplp:
381 movb 4(BP, DI), %bl
382 movb %bl, (BP, DI)
383 inc DI
384 loop rotreplp
385 popw %bx
386 testb %dh, %dh
387 jnz lzd10
388 movw %ax, (BP, DI)
389 movw %bx, 2(BP, DI)
390 # else
391 shl $2, CX // 8->32 bits
392 sub CX, DI // &rep[cx]
393 movl (BP, DI), %eax
394 rotreplp:
395 movb 4(BP, DI), %bl
396 movb %bl, (BP, DI)
397 inc DI
398 loop rotreplp
399 testb %dh, %dh
400 jnz lzd10
401 movl %eax, (BP, DI)
402 # endif
404 // }
405 lzd12:
406 // state = (state < kNumLitStates /*7*/) ? 8 : 11;
408 movb $0x08, %cl
410 // prob = p + RepLenCoder /*1332*/;
412 mov $1332, DX
414 // }
415 lzd10:
416 push CX // CX = 0
418 // { /* get len */
419 // int numBits, offset;
420 // CProb *probLen = prob + LenChoice /*0*/;
421 // numBits = kLenNumLowBits /*3*/;
423 movb $8, %cl // numBits : 3,3,8
425 // if (Bit0(probLen)) {
427 call Bit1dx // Bit1(prob)
428 xchg AX, BX
429 inc DX
430 jnc lzd15 // bx=0
432 // probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/);
433 // offset = 0;
434 // }
435 // else {
436 // probLen = prob + LenChoice2 /*1*/;
438 call Bit1dx // Bit1(prob)
439 add AX, BX
441 #if PROP_PB != 0
442 inc AX // ah=0
443 #endif
444 jc lzd16 // %ax=0, %bx=-2
445 lzd15:
446 #if PROP_PB != 0
447 movb $8, %al
448 mulb posState(BP)
449 #endif
451 // if (Bit0(probLen)) {
452 // probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/);
454 movb $3, %cl // numBits : 3,3,8
455 lzd16:
456 #if PROP_PB != 0
457 add $2-128-1, AX // probLen : 2,130,258
458 #else
459 mov $2-128-1, AX // probLen : 2,130,258
460 #endif
461 add DX, AX
462 mov $-8+1, DX // offset : 0,8,16
463 lzdargslp:
464 add $8, DX
465 add $128, AX
466 inc BX
467 jle lzdargslp // leave with bx=1
469 // offset = kLenNumLowSymbols /*8*/;
470 // //numBits = kLenNumMidBits /*3*/;
471 // }
472 // else {
473 // probLen = prob + LenHigh /*258*/;
474 // offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/;
475 // numBits = kLenNumHighBits /*8*/;
476 // }
477 // }
478 // RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset;
480 push DX
481 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
482 pop DX
483 add DX, AX // offset
484 pop DX // 0
485 lzd13string:
486 push AX
488 // state = (state < kNumLitStates /*7*/) ? dl : dl|3;
490 movb $7, %cl
491 cmpb %cl, state(BP)
492 jb new_state
493 orb $3, %dl
494 new_state:
495 movb %dl, state(BP)
497 // } /* get len */
498 // if (state < 4) {
500 cmpb $4-1, %dl
501 ja lzd19
503 // int posSlot;
504 // state += kNumLitStates /*7*/;
506 addb %cl, state(BP)
508 // prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ?
509 // len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/);
511 cmp $4+1, AX
512 jb lzd21
513 mov $3+1, AX
515 lzd21:
517 dec CX // cx = 6
518 shl %cl, AX
519 add $432-64, AX
521 // RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot);
523 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
525 // if (posSlot >= kStartPosModelIndex /*4*/) {
526 // int numDirectBits = ((posSlot >> 1) - 1);
528 #ifndef FLAT32
529 movw %cx, 2(%bp, %di) // %cx = 0
530 #endif
531 mov AX, (BP, DI)
532 mov AX, CX
533 shrw $1, CX
534 dec CX
535 cmpb $4, %al
536 jb lzd22
538 // rep0 = (2 | ((UInt32)posSlot & 1));
540 andb %bl, (BP, DI) // %bx=1
541 orb $2, (BP, DI)
543 // if (posSlot < kEndPosModelIndex /*14*/) {
545 cmpb $14, %al
546 jnb lzd23
548 // rep0 <<= numDirectBits;
550 neg AX
551 # ifdef ONLY8086
552 pushw %cx
553 movb $0, %ch
554 shllrep0:
555 shlw $1, (BP, DI)
556 rclw $1, 2(BP, DI)
557 loop shllrep0
558 popw %cx
559 # else
560 shll %cl, (BP, DI)
561 # endif
562 add (BP, DI), AX
564 // prob = p + SpecPos /*688*/ + rep0 - posSlot - 1;
566 add $687, AX
567 jmp lzd24
569 // }
570 // else {
571 lzd23:
572 // numDirectBits -= kNumAlignBits /*4*/;
573 // do {
574 // RC_NORMALIZE; Range >>= 1; rep0 <<= 1;
575 // if (Code >= Range) { Code -= Range; rep0 |= 1; }
577 lzd23z:
578 call RC_NORMALIZE
579 # ifdef ONLY8086
580 pushw %dx
581 shrw $1, Range+2(BP)
582 rcrw $1, Range(BP)
583 movw Range(BP), %ax
584 movw Range+2(BP), %dx
585 cmpw Code+2(BP), %dx
586 ja lzd25
587 jb lzd25x
588 cmpw Code(BP), %ax
589 ja lzd25
590 lzd25x:
591 subw %ax, Code(BP)
592 sbbw %dx, Code+2(BP)
593 stc
594 lzd25:
595 popw %dx
596 rclw $1, (BP, DI)
597 rclw $1, 2(BP, DI)
598 # else
599 shrl $1, Range(BP)
600 movl Range(BP), %eax
601 cmpl Code(BP), %eax
602 ja lzd25
603 subl %eax, Code(BP)
604 stc
605 lzd25:
606 rcll $1, (BP, DI)
607 # endif
609 // } while (--numDirectBits != 0);
611 cmpb $4+1, %cl
612 loopne lzd23z
614 // prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/;
615 // rep0 <<= numDirectBits;
617 # ifdef ONLY8086
618 pushw %cx
619 movb $0, %ch
620 shlrep0:
621 shlw $1, (BP, DI)
622 rclw $1, 2(BP, DI)
623 loop shlrep0
624 popw %cx
625 # else
626 shll %cl, (BP, DI)
627 # endif
628 mov $802, AX
629 // }
631 lzd24:
632 call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res
634 // {
635 // int i = 1, mi = 1;
636 // do {
637 // CProb *prob3 = prob + mi;
638 // RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
640 orb %dh, (BP, DI) // update rep0 with DirectBits
642 // i <<= 1;
643 // } while(--numDirectBits != 0);
644 // }
645 // } else rep0 = posSlot;
646 lzd22:
647 // if (++rep0 == (UInt32)(0)) break; /* EOF */
649 # ifdef ONLY8086
650 incw (BP, DI)
651 jnz lzd19
652 incw 2(BP, DI)
653 # else
654 incl (BP, DI)
655 # endif
657 lzd19:
658 pop CX
659 jz lzdone
661 // }
662 // len += kMatchMinLen;/*2*/
664 inc CX
666 // string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR;
667 // do {
668 lzd13z:
669 // previousByte = outStream[nowPos - rep0];
670 // outStream[nowPos++] = previousByte;
672 call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0]
674 // } while(--len != 0);
676 loop lzd13z
678 // } /* char/string */
679 // }
681 jmp lzdmainlp
683 lzdone:
684 // //RC_NORMALIZE;
685 // //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos;
686 // return LZMA_RESULT_OK;
687 call Dico2ESDI // set es & di (rep0 = 0)
688 lea ws2(BP), SP // dealloc
689 ret
690 // }
692 // al = outStream[nowPos - rep0];
694 /*
695 * output es:di, al
696 * scratch bh, cl, flags
697 */
699 DicoRep02ESDI:
700 stc
702 // bl = outStream[nowPos];
704 /*
705 * output es:di, bl
706 * scratch bh, cl, flags
707 */
709 Dico2ESDI:
710 #if !defined(FLAT32) && !defined(FLAT16OUT)
711 # ifdef ONLY8086
712 pushw %ax
713 movw nowPos(%bp), %bx
714 movw nowPos+2(%bp), %ax
715 jnc Dico2ESDIz
716 subw rep0(%bp), %bx
717 sbbw rep0+2(%bp), %ax
718 Dico2ESDIz:
719 movw $0xF, %di
720 andw %bx, %di
721 pushw %cx
722 movb $4, %cl
723 shrw %cl, %bx
724 shlw %cl, %ax
725 popw %cx
726 addb %al, %bh
727 popw %ax
728 # else
729 movl nowPos(%bp), %ebx
730 jnc Dico2ESDIz
731 subl rep0(%bp), %ebx
732 Dico2ESDIz:
733 movw %bx, %di
734 xorw %bx, %bx
735 shrl $4, %ebx
736 # endif
737 movw %bx, %es
738 #else
739 mov nowPos(BP), DI
740 jnc Dico2ESDIz
741 sub rep0(BP), DI
742 Dico2ESDIz:
743 #endif
744 #ifdef FLAT32
745 movb (DI), %bl
746 #else
747 movb %es:(%di), %bl
748 #endif
749 ret
751 outcharDico:
753 // bl = outStream[nowPos++] = outStream[nowPos - rep0]
755 /*
756 * output es:di, bl
757 * update nowPos
758 * scratch ax, dx, bh, cl, flags
759 */
761 call DicoRep02ESDI // %bl = outStream[nowPos - rep0]
762 xchg AX, BX
763 outchar:
765 // bl = outStream[nowPos++] = previousByte = al;
767 /*
768 * output bl
769 * update nowPos
770 * scratch ax, dx, bh, di, cl, flags
771 */
773 clc
774 call Dico2ESDI
775 stosb
776 xchg AX, BX // previous byte
778 // int posState = (int)((nowPos) & posStateMask);
780 #if PROP_PB != 0 && PROP_LP != 0
781 addw $0x0101, posState2(BP)
782 andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP)
783 #else
784 # if PROP_PB != 0
785 incb posState(BP)
786 andb $((1 << PROP_PB) -1), posState(BP)
787 # endif
788 # if PROP_LP != 0
789 incb posState2(BP)
790 andb $((1 << PROP_LP) -1), posState2(BP)
791 # endif
792 #endif
793 #ifdef ONLY8086
794 incw nowPos(BP)
795 jnz incnowPosDone
796 incw nowPos+2(BP)
797 incnowPosDone:
798 #else
799 incl nowPos(BP)
800 #endif
801 ret
803 //
804 // #define RC_NORMALIZE if (Range < kTopValue)
805 // { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
807 /*
808 * update Range, Code, ds:si
809 * scratch flags
810 */
812 RC_NORMALIZE:
813 cmpb $0, Range+3(BP)
814 jne RC_NORMALIZE_1
815 RC_LOAD_BYTE:
816 push AX
817 #ifdef ONLY8086
818 movw Range+1(BP), %ax
819 movw %ax, Range+2(BP)
820 movw Code+1(BP), %ax
821 movw %ax, Code+2(BP)
822 xorw %ax, %ax
823 movb Range(BP), %ah
824 movw %ax, Range(BP)
825 movb Code(BP), %ah
826 movw %ax, Code(BP)
827 #else
828 shll $8, Range(BP)
829 shll $8, Code(BP)
830 #endif
831 #if !defined(FLAT16) && !defined(FLAT32)
832 testw %si, %si
833 jns RC_READ_BYTE
834 movw %ds, %ax
835 incw %ax
836 movw %ax, %ds
837 addw $-16, %si
838 RC_READ_BYTE:
839 #endif
840 lodsb
841 movb %al, Code(BP)
842 pop AX
843 RC_NORMALIZE_1:
844 ret
846 // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState)
848 Bit1state:
849 movb $16, %al
850 mulb state(BP)
851 # if PROP_PB != 0
852 addb posState(BP), %al
853 # endif
854 Bit1axdx:
855 add DX, AX
856 jmp Bit1
858 // prob += 12; Bit1(prob)
860 Bit1dx12:
861 add $12, DX
862 Bit1dx:
863 mov DX, AX
865 // static int Bit1(CProb *p)
867 Bit1:
868 /*
869 * input ax=p
870 * output C, ax
871 * update bound, Range, Code, ds:si
872 * scratch flags
873 */
875 // {
876 // RC_NORMALIZE;
878 call RC_NORMALIZE // kill %ax, update %si
880 #ifdef ONLY8086
881 pushw %ax
882 pushw %cx
883 pushw %dx
884 pushw %di
885 #else
886 pushal
887 #endif
889 xchg AX, DI
890 add DI, DI // short *
893 // bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p);
895 #ifdef ONLY8086
896 movw Range(BP), %dx
897 movw Range+2(BP), %ax
898 movw $11, %cx
899 shr11lp:
900 shrw $1, %ax
901 rcrw $1, %dx
902 loop shr11lp
903 movw %dx, %cx
904 mulw (BP, DI)
905 xchgw %ax, %cx
906 mulw (BP, DI)
907 addw %cx, %dx
908 #else
909 movl Range(BP), %eax
910 shrl $11, %eax
911 movzwl (BP, DI), %edx
912 mull %edx
913 #endif
915 // if (Code < bound) {
917 #ifdef ONLY8086
918 cmpw Code+2(BP), %dx
919 jb Bit1_1
920 ja Bit1_1x
921 cmpw Code(BP), %ax
922 jbe Bit1_1
923 Bit1_1x:
925 // Range = bound;
927 movw %ax, Range(BP)
928 movw %dx, Range+2(BP)
929 #else
930 cmpl Code(BP), %eax
931 jbe Bit1_1
933 // Range = bound;
935 movl %eax, Range(BP)
936 #endif
938 // *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/;
940 movw $2048, %ax
942 // return 0;
944 jmp Bit1_2
946 // }
947 // else {
949 Bit1_1:
951 // Range -= bound; Code -= bound;
953 #ifdef ONLY8086
954 subw %ax, Range(BP)
955 sbbw %dx, Range+2(BP)
956 subw %ax, Code(BP)
957 sbbw %dx, Code+2(BP)
958 #else
959 subl %eax, Range(BP)
960 subl %eax, Code(BP)
961 #endif
963 // *(p) -= (*(p)) >> kNumMoveBits /*5*/;
965 movw $31, %ax
967 // return 1;
969 stc
970 Bit1_2:
971 pushf
972 subw (BP, DI), %ax
973 #ifdef ONLY8086
974 movb $5, %cl
975 sarw %cl, %ax
976 #else
977 sarw $5, %ax
978 #endif
979 addw %ax, (BP, DI)
980 popf
981 #ifdef ONLY8086
982 popw %di
983 popw %dx
984 popw %cx
985 popw %ax
986 #else
987 popal
988 #endif
989 sbb AX, AX
991 // }
992 // }
994 ret
996 RangeDecoder:
998 /*
999 * input ax=probs cx=numLevels (< 8) bx=1
1000 * output ax=res (backward), dh (forward)
1001 * update bound, Range, Code, ds:si
1002 * scratch flags, cx=0, dl
1003 */
1005 push BX
1007 // { int i = numLevels; res = 1;
1008 mov BX, DX // res = 1
1010 // do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0);
1012 RangeDecoder_1:
1013 push AX
1014 call Bit1axdx // C,%ax = Bit1(prob+%ax)
1015 rclb $1, %dl // res <<= 1; res |= C
1016 andb %bl, %al // current bit
1017 orb %al, %bh // store in bh
1018 shlb $1, %bl // update max
1019 pop AX
1020 loop RangeDecoder_1
1022 // res -= (1 << numLevels); }
1024 xchg AX, BX // move bh to dh
1025 xchg AX, DX // and dl to al
1026 sub %dl, %al // sub max
1027 pop BX
1028 ret