wok-tiny diff linux/stuff/unlzma.S @ rev 142
Remove ashism ==
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Feb 27 17:43:23 2019 +0100 (2019-02-27) |
parents | |
children | eb617e43dc08 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/linux/stuff/unlzma.S Wed Feb 27 17:43:23 2019 +0100 1.3 @@ -0,0 +1,1019 @@ 1.4 +// #define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 1.5 +// 1.6 +// #define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) 1.7 +// #define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; 1.8 +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; 1.9 +// 1.10 +//#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ 1.11 +// { UpdateBit0(p); mi <<= 1; A0; } else \ 1.12 +// { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 1.13 +// 1.14 +// #define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) 1.15 +// 1.16 +// #define RangeDecoderBitTreeDecode(probs, numLevels, res) \ 1.17 +// { int i = numLevels; res = 1; \ 1.18 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ 1.19 +// res -= (1 << numLevels); } 1.20 +/* 1.21 + * Compression with : lzma e src dst -eos -pb2 -lp0 -lc3 1.22 + */ 1.23 + 1.24 +#define PROP_PB 2 1.25 +#define PROP_LP 0 1.26 +#define PROP_LC 3 1.27 +#define PROPS (PROP_LC+(PROP_LP*9)+(PROP_PB*45)) 1.28 + 1.29 +// static const Byte *Buffer; 1.30 +// static UInt32 bound, Code, Range; 1.31 + 1.32 +/* 1.33 + * Buffer register DS:SI 1.34 + * all var based ws=ss:bp 1.35 + */ 1.36 + 1.37 +rep0 = -4 // long 1.38 +rep1 = rep0-4 // long 1.39 +rep2 = rep0-8 // long 1.40 +rep3 = rep0-12 // long 1.41 +state = -17 // byte, 0..11 1.42 +posState = state-1 // byte, 0..15 1.43 +posState2 = posState-1 // byte, 0..15 1.44 +scratched = rep0-16 // byte = 1 1.45 +Code = -24 // long 1.46 +outStream = -28 // long 1.47 +nowPos = outStream // long 1.48 +Range = Code-8 // long 1.49 +#define LOCALS 32 1.50 + 1.51 +// int LzmaDecode(CLzmaDecoderState *vs, 1.52 +// const unsigned char *inStream, 1.53 +// unsigned char *outStream) 1.54 +// { 1.55 +// CProb *p = vs->Probs; 1.56 +// SizeT nowPos = 0; 1.57 +// #define posStateMask = (1 << (vs->Properties.pb)) - 1; 1.58 +// #define literalPosMask = (1 << (vs->Properties.lp)) - 1; 1.59 +// int lc = vs->Properties.lc, state = 0, len = 0; 1.60 +// UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 1.61 +// 1.62 +// { 1.63 +// UInt32 i, numProbs = Literal /*1846*/ 1.64 +// + ((UInt32)LZMA_LIT_SIZE /*768*/ << (lc + vs->Properties.lp)); 1.65 +// for (i = 0; i < numProbs; i++) p[i] = kBitModelTotal /*2048*/ >> 1; 1.66 + 1.67 +#define WS (1846+(768<<(PROP_LC+PROP_LP))) 1.68 +#if (WS+WS+LOCALS) >= 65000 1.69 +/* MAX WS = (1846+(768<<(8+4))) > 3MB! */ 1.70 +#error invalid (lc,lp,pb) : out of memory 1.71 +#endif 1.72 + 1.73 +ws1 = WS 1.74 +ws2 = ws1*2 1.75 +ws = ws2+LOCALS+15 1.76 + 1.77 +#ifndef FLAT32 1.78 +#define AX %ax 1.79 +#define BX %bx 1.80 +#define CX %cx 1.81 +#define DX %dx 1.82 +#define SI %si 1.83 +#define DI %di 1.84 +#define BP %bp 1.85 +#define SP %sp 1.86 +#define CWD cwd 1.87 +#else 1.88 +#define AX %eax 1.89 +#define BX %ebx 1.90 +#define CX %ecx 1.91 +#define DX %edx 1.92 +#define SI %esi 1.93 +#define DI %edi 1.94 +#define BP %ebp 1.95 +#define SP %esp 1.96 +#define CWD cdq 1.97 +#endif 1.98 +/* 1.99 + * LzmaDecode: 1.100 +#ifndef FLAT32 1.101 + * input ds:si=inStream, es:di=outStream 1.102 + * output outStream[], ds:si, es:di 1.103 + .code 16 1.104 +#else 1.105 + * input esi=inStream, edi=outStream 1.106 + * output outStream[], esi, edi 1.107 + .code 32 1.108 +#endif 1.109 + */ 1.110 + 1.111 + mov $ws1, CX 1.112 +#ifdef ONLY8086 1.113 + movw $2048/2, %ax 1.114 +lzd1: 1.115 + pushw %ax 1.116 +#else 1.117 +lzd1: 1.118 + pushw $2048/2 1.119 +#endif 1.120 + loop lzd1 1.121 + mov SP, BP 1.122 + movb $((LOCALS+3)/4)*2, %cl 1.123 +#ifdef ONLY8086 1.124 + movw $1, %ax 1.125 + cwd 1.126 +initlocals: 1.127 + pushw %dx 1.128 + pushw %ax 1.129 +#else 1.130 +initlocals: 1.131 + pushl $1 1.132 +#endif 1.133 + loop initlocals 1.134 + 1.135 +#if !defined(FLAT32) && !defined(FLAT16OUT) 1.136 + movb $4, %cl 1.137 + movw %es, %bx 1.138 + shrw %cl, %bx 1.139 + movw %es, %dx 1.140 + shlw %cl, %dx 1.141 + addw %dx, %di 1.142 + movw %di, outStream(%bp) 1.143 + adcb %bh, outStream+2(%bp) 1.144 + incw %cx 1.145 +#else 1.146 + movb $5, %cl 1.147 + mov DI, outStream(BP) 1.148 +#endif 1.149 + 1.150 +// Byte previousByte = 0; 1.151 + xor BX, BX 1.152 + 1.153 +// #define RC_INIT(buffer) 1.154 +// Buffer = buffer; Code = 0; Range = 0xFFFFFFFF; 1.155 +// { int i; for(i=0; i<5; i++) { Code = (Code<<8) | RC_READ_BYTE; }} 1.156 +// } 1.157 +// RC_INIT(inStream); 1.158 + 1.159 +#ifndef NO_LZMA_HEADER 1.160 +#ifdef CHECK_LZMA_HEADER 1.161 + cmp.w $0x5A4C, (SI) // lzip header ('LZIP' version:1 dicobits:1) 1.162 + je lzip_header 1.163 + cmp.w $0x5D, (SI) // lzma header (0x5D dicosz:4 orgsz:8) 1.164 + jne no_header 1.165 + add $13-6, SI // skip lzma header 1.166 +lzip_header: 1.167 + add $6, SI // skip lzip header 1.168 +no_header: 1.169 +#else 1.170 + add $13, SI // skip lzma header (0x5D dicosz:4 orgsz:8) 1.171 +#endif 1.172 +#endif 1.173 +setrep: 1.174 + call RC_LOAD_BYTE 1.175 + decb Range(BP) 1.176 + loop setrep 1.177 + 1.178 +lzdmainlp: 1.179 +// while(1) { 1.180 +// CProb *prob; 1.181 +// int posState = (int)((nowPos) & posStateMask); 1.182 +// 1.183 +// prob = p + IsMatch /*0*/ + (state << kNumPosBitsMax /*4*/) + posState; 1.184 +// if (Bit0(prob)) { /* char */ 1.185 + 1.186 + xor DX, DX 1.187 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 1.188 + mov $state, DI 1.189 + jc lzdstring 1.190 + 1.191 +// prob = p + Literal /*1846*/ + (LZMA_LIT_SIZE /*768*/ * 1.192 +// ((((nowPos) & literalPosMask) << lc) + (previousByte >> (8 - lc)))); 1.193 + 1.194 +#if PROP_LC != 0 1.195 +# ifdef ONLY8086 1.196 + movb $8-PROP_LC, %cl 1.197 + shrb %cl, %bl 1.198 +# else 1.199 + shrb $8-PROP_LC, %bl 1.200 +# endif 1.201 +#endif 1.202 + 1.203 +#if PROP_LP != 0 1.204 + movb posState2(BP), %dl 1.205 +# ifdef ONLY8086 1.206 + movb $PROP_LC, %cl 1.207 + shl %cl, DX 1.208 +# else 1.209 + shl $PROP_LC, DX 1.210 +# endif 1.211 + movb $0, %bh 1.212 + add BX, DX 1.213 +#endif 1.214 + 1.215 + movb $3, %ah 1.216 + mul BX // dx = 3*bh 1.217 + add $1846, AX 1.218 + 1.219 +// int symbol = 1; 1.220 + 1.221 + CWD 1.222 + inc DX // symbol = 1 1.223 + xchg AX, CX // save prob 1.224 + 1.225 +// if (state >= kNumLitStates /*7*/) { /* previous was string */ 1.226 +// if (state < 4) state = 0; 1.227 + 1.228 +lzd6z: 1.229 + subb $3, (BP, DI) 1.230 + 1.231 +// if (state < 4) state = 0; 1.232 + 1.233 + jnc lzd6 1.234 + movb %dh, (BP, DI) // %dh = 0 1.235 + 1.236 +lzd6: 1.237 +// else if (state < 10) state -= 3; 1.238 + 1.239 + cmpb $10-3, (BP, DI) 1.240 + 1.241 +// else state -= 6; 1.242 + 1.243 + jnb lzd6z 1.244 + cmpb $7-3-1, (BP, DI) 1.245 + jbe lzd3 1.246 + 1.247 +// int matchByte = outStream[nowPos - rep0]; 1.248 + 1.249 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0]; 1.250 + 1.251 +// do { 1.252 +// int bit; 1.253 +// CProb *probLit; 1.254 +// matchByte <<= 1; bit = (matchByte & 0x100); 1.255 + 1.256 + movb $1, %bh 1.257 +lzd4: 1.258 + shlb $1, %bl // matchByte <<= 1 1.259 + sbb DI, DI // save bit=C 1.260 + 1.261 +// probLit = prob + 0x100 + bit + symbol; 1.262 + 1.263 + mov CX, AX // restore prob 1.264 + adcb %bh, %ah // + bit + 0x100 1.265 + 1.266 +// RC_GET_BIT2(probLit, symbol, if (bit) break, if (!bit) break) 1.267 + 1.268 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 1.269 + rclb $1, %dl // symbol <<= 1; symbol |= C 1.270 + jc lzd5 // if symbol >= 0x100 1.271 + cmp DI, AX 1.272 + jz lzd4 // if bit == Bit1(prob+%ax) 1.273 + 1.274 +// } while (symbol < 0x100); 1.275 +// } 1.276 +lzd3: 1.277 +// while (symbol < 0x100) { 1.278 +// CProb *probLit = prob + symbol; 1.279 +// RC_GET_BIT(probLit, symbol) 1.280 +// } 1.281 + 1.282 + xor BX, BX 1.283 + jmp lzd4 1.284 +lzd5: 1.285 + 1.286 +// outStream[nowPos++] = previousByte = (Byte)symbol; 1.287 + 1.288 + xchg AX, DX 1.289 + call outchar // %bl = outStream[nowPos++] = %al; 1.290 + jmp lzdmainlp 1.291 + 1.292 +// } 1.293 + 1.294 +lzdstring: 1.295 + mov $1, CX 1.296 + 1.297 +// else { /* string */ 1.298 +// prob = p + IsRep /*192*/ + state; 1.299 + 1.300 + movb $192, %dl 1.301 + addb (BP, DI), %dl 1.302 + mov $rep0, DI 1.303 + 1.304 +// if (Bit0(prob)) { 1.305 + 1.306 + call Bit1dx // Bit1(prob) 1.307 + jc lzd8 1.308 + 1.309 +// rep3 = rep2; rep2 = rep1; rep1 = rep0; 1.310 +// state = (state < kNumLitStates /*7*/) ? 0 : 3; 1.311 + 1.312 + stc 1.313 + 1.314 +// prob = p + LenCoder /*818*/; 1.315 + 1.316 + mov $818, DX 1.317 + 1.318 +// } 1.319 + 1.320 + jmp lzd11a 1.321 + 1.322 +// else { 1.323 +lzd8: 1.324 +// prob += kNumStates /*12*/; 1.325 +// if (Bit0(prob)) { 1.326 + call Bit1dx12 // prob += 12; Bit1(prob) 1.327 + jc lzd11 1.328 +// prob = p + IsRep0Long /*240*/ + (state << kNumPosBitsMax /*4*/) 1.329 +// + posState; 1.330 + movb $240, %dl // dh=0 1.331 + 1.332 +// if (Bit0(prob)) { 1.333 + 1.334 + call Bit1state // Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 1.335 + jc lzd12 1.336 + 1.337 +// // if (nowPos == 0) return LZMA_RESULT_DATA_ERROR; 1.338 +// state = (state < kNumLitStates /*7*/) ? 9 : 11; 1.339 + 1.340 + movb $9, %dl 1.341 + 1.342 +// len++; goto string; 1.343 + jmp lzd13string // ax = 0 1.344 +// } 1.345 +// } 1.346 +// else { 1.347 +lzd11: 1.348 +// UInt32 distance = rep1; 1.349 +// prob += kNumStates /*12*/; 1.350 +// if (!Bit0(prob)) { 1.351 + 1.352 + call Bit1dx12 // prob += 12; Bit1(prob) 1.353 + jnc lzd11z 1.354 + 1.355 +// prob += kNumStates /*12*/; 1.356 +// if (Bit0(prob)) distance = rep2; 1.357 + 1.358 + call Bit1dx12 // prob += 12; Bit1(prob) 1.359 +lzd11a: 1.360 + adcb %cl, %cl 1.361 + 1.362 +// else { distance = rep3; rep3 = rep2; } 1.363 +// rep2 = rep1; 1.364 +// } 1.365 +// rep1 = rep0; rep0 = distance; 1.366 + 1.367 +lzd11z: 1.368 +# ifdef ONLY8086 1.369 + shl $1, CX 1.370 + shl $1, CX // 8->32 bits 1.371 + sub CX, DI // &rep[cx] 1.372 + movw (BP, DI), %ax 1.373 + pushw 2(BP, DI) 1.374 +rotreplp: 1.375 + movb 4(BP, DI), %bl 1.376 + movb %bl, (BP, DI) 1.377 + inc DI 1.378 + loop rotreplp 1.379 + popw %bx 1.380 + testb %dh, %dh 1.381 + jnz lzd10 1.382 + movw %ax, (BP, DI) 1.383 + movw %bx, 2(BP, DI) 1.384 +# else 1.385 + shl $2, CX // 8->32 bits 1.386 + sub CX, DI // &rep[cx] 1.387 + movl (BP, DI), %eax 1.388 +rotreplp: 1.389 + movb 4(BP, DI), %bl 1.390 + movb %bl, (BP, DI) 1.391 + inc DI 1.392 + loop rotreplp 1.393 + testb %dh, %dh 1.394 + jnz lzd10 1.395 + movl %eax, (BP, DI) 1.396 +# endif 1.397 + 1.398 +// } 1.399 +lzd12: 1.400 +// state = (state < kNumLitStates /*7*/) ? 8 : 11; 1.401 + 1.402 + movb $0x08, %cl 1.403 + 1.404 +// prob = p + RepLenCoder /*1332*/; 1.405 + 1.406 + mov $1332, DX 1.407 + 1.408 +// } 1.409 +lzd10: 1.410 + push CX // CX = 0 1.411 + 1.412 +// { /* get len */ 1.413 +// int numBits, offset; 1.414 +// CProb *probLen = prob + LenChoice /*0*/; 1.415 +// numBits = kLenNumLowBits /*3*/; 1.416 + 1.417 + movb $8, %cl // numBits : 3,3,8 1.418 + 1.419 +// if (Bit0(probLen)) { 1.420 + 1.421 + call Bit1dx // Bit1(prob) 1.422 + xchg AX, BX 1.423 + inc DX 1.424 + jnc lzd15 // bx=0 1.425 + 1.426 +// probLen = prob + LenLow/*2*/ + (posState << kLenNumLowBits/*3*/); 1.427 +// offset = 0; 1.428 +// } 1.429 +// else { 1.430 +// probLen = prob + LenChoice2 /*1*/; 1.431 + 1.432 + call Bit1dx // Bit1(prob) 1.433 + add AX, BX 1.434 + 1.435 +#if PROP_PB != 0 1.436 + inc AX // ah=0 1.437 +#endif 1.438 + jc lzd16 // %ax=0, %bx=-2 1.439 +lzd15: 1.440 +#if PROP_PB != 0 1.441 + movb $8, %al 1.442 + mulb posState(BP) 1.443 +#endif 1.444 + 1.445 +// if (Bit0(probLen)) { 1.446 +// probLen = prob + LenMid/*130*/ + (posState << kLenNumMidBits/*3*/); 1.447 + 1.448 + movb $3, %cl // numBits : 3,3,8 1.449 +lzd16: 1.450 +#if PROP_PB != 0 1.451 + add $2-128-1, AX // probLen : 2,130,258 1.452 +#else 1.453 + mov $2-128-1, AX // probLen : 2,130,258 1.454 +#endif 1.455 + add DX, AX 1.456 + mov $-8+1, DX // offset : 0,8,16 1.457 +lzdargslp: 1.458 + add $8, DX 1.459 + add $128, AX 1.460 + inc BX 1.461 + jle lzdargslp // leave with bx=1 1.462 + 1.463 +// offset = kLenNumLowSymbols /*8*/; 1.464 +// //numBits = kLenNumMidBits /*3*/; 1.465 +// } 1.466 +// else { 1.467 +// probLen = prob + LenHigh /*258*/; 1.468 +// offset = kLenNumLowSymbols /*8*/ + kLenNumMidSymbols /*8*/; 1.469 +// numBits = kLenNumHighBits /*8*/; 1.470 +// } 1.471 +// } 1.472 +// RangeDecoderBitTreeDecode(probLen, numBits, len); len += offset; 1.473 + 1.474 + push DX 1.475 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 1.476 + pop DX 1.477 + add DX, AX // offset 1.478 + pop DX // 0 1.479 +lzd13string: 1.480 + push AX 1.481 + 1.482 +// state = (state < kNumLitStates /*7*/) ? dl : dl|3; 1.483 + 1.484 + movb $7, %cl 1.485 + cmpb %cl, state(BP) 1.486 + jb new_state 1.487 + orb $3, %dl 1.488 +new_state: 1.489 + movb %dl, state(BP) 1.490 + 1.491 +// } /* get len */ 1.492 +// if (state < 4) { 1.493 + 1.494 + cmpb $4-1, %dl 1.495 + ja lzd19 1.496 + 1.497 +// int posSlot; 1.498 +// state += kNumLitStates /*7*/; 1.499 + 1.500 + addb %cl, state(BP) 1.501 + 1.502 +// prob = p + PosSlot /*432*/ + (((len < kNumLenToPosStates /*4*/) ? 1.503 +// len : kNumLenToPosStates - 1) << kNumPosSlotBits /*6*/); 1.504 + 1.505 + cmp $4+1, AX 1.506 + jb lzd21 1.507 + mov $3+1, AX 1.508 + 1.509 +lzd21: 1.510 + 1.511 + dec CX // cx = 6 1.512 + shl %cl, AX 1.513 + add $432-64, AX 1.514 + 1.515 +// RangeDecoderBitTreeDecode(prob, kNumPosSlotBits /*6*/, posSlot); 1.516 + 1.517 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 1.518 + 1.519 +// if (posSlot >= kStartPosModelIndex /*4*/) { 1.520 +// int numDirectBits = ((posSlot >> 1) - 1); 1.521 + 1.522 +#ifndef FLAT32 1.523 + movw %cx, 2(%bp, %di) // %cx = 0 1.524 +#endif 1.525 + mov AX, (BP, DI) 1.526 + mov AX, CX 1.527 + shrw $1, CX 1.528 + dec CX 1.529 + cmpb $4, %al 1.530 + jb lzd22 1.531 + 1.532 +// rep0 = (2 | ((UInt32)posSlot & 1)); 1.533 + 1.534 + andb %bl, (BP, DI) // %bx=1 1.535 + orb $2, (BP, DI) 1.536 + 1.537 +// if (posSlot < kEndPosModelIndex /*14*/) { 1.538 + 1.539 + cmpb $14, %al 1.540 + jnb lzd23 1.541 + 1.542 +// rep0 <<= numDirectBits; 1.543 + 1.544 + neg AX 1.545 +# ifdef ONLY8086 1.546 + pushw %cx 1.547 + movb $0, %ch 1.548 +shllrep0: 1.549 + shlw $1, (BP, DI) 1.550 + rclw $1, 2(BP, DI) 1.551 + loop shllrep0 1.552 + popw %cx 1.553 +# else 1.554 + shll %cl, (BP, DI) 1.555 +# endif 1.556 + add (BP, DI), AX 1.557 + 1.558 +// prob = p + SpecPos /*688*/ + rep0 - posSlot - 1; 1.559 + 1.560 + add $687, AX 1.561 + jmp lzd24 1.562 + 1.563 +// } 1.564 +// else { 1.565 +lzd23: 1.566 +// numDirectBits -= kNumAlignBits /*4*/; 1.567 +// do { 1.568 +// RC_NORMALIZE; Range >>= 1; rep0 <<= 1; 1.569 +// if (Code >= Range) { Code -= Range; rep0 |= 1; } 1.570 + 1.571 +lzd23z: 1.572 + call RC_NORMALIZE 1.573 +# ifdef ONLY8086 1.574 + pushw %dx 1.575 + shrw $1, Range+2(BP) 1.576 + rcrw $1, Range(BP) 1.577 + movw Range(BP), %ax 1.578 + movw Range+2(BP), %dx 1.579 + cmpw Code+2(BP), %dx 1.580 + ja lzd25 1.581 + jb lzd25x 1.582 + cmpw Code(BP), %ax 1.583 + ja lzd25 1.584 +lzd25x: 1.585 + subw %ax, Code(BP) 1.586 + sbbw %dx, Code+2(BP) 1.587 + stc 1.588 +lzd25: 1.589 + popw %dx 1.590 + rclw $1, (BP, DI) 1.591 + rclw $1, 2(BP, DI) 1.592 +# else 1.593 + shrl $1, Range(BP) 1.594 + movl Range(BP), %eax 1.595 + cmpl Code(BP), %eax 1.596 + ja lzd25 1.597 + subl %eax, Code(BP) 1.598 + stc 1.599 +lzd25: 1.600 + rcll $1, (BP, DI) 1.601 +# endif 1.602 + 1.603 +// } while (--numDirectBits != 0); 1.604 + 1.605 + cmpb $4+1, %cl 1.606 + loopne lzd23z 1.607 + 1.608 +// prob = p + Align /* 802 */; numDirectBits = kNumAlignBits /*4*/; 1.609 +// rep0 <<= numDirectBits; 1.610 + 1.611 +# ifdef ONLY8086 1.612 + pushw %cx 1.613 + movb $0, %ch 1.614 +shlrep0: 1.615 + shlw $1, (BP, DI) 1.616 + rclw $1, 2(BP, DI) 1.617 + loop shlrep0 1.618 + popw %cx 1.619 +# else 1.620 + shll %cl, (BP, DI) 1.621 +# endif 1.622 + mov $802, AX 1.623 +// } 1.624 + 1.625 +lzd24: 1.626 + call RangeDecoder // %ax=probs, %cx=numLevels, %ax=res 1.627 + 1.628 +// { 1.629 +// int i = 1, mi = 1; 1.630 +// do { 1.631 +// CProb *prob3 = prob + mi; 1.632 +// RC_GET_BIT2(prob3, mi, ; , rep0 |= i); 1.633 + 1.634 + orb %dh, (BP, DI) // update rep0 with DirectBits 1.635 + 1.636 +// i <<= 1; 1.637 +// } while(--numDirectBits != 0); 1.638 +// } 1.639 +// } else rep0 = posSlot; 1.640 +lzd22: 1.641 +// if (++rep0 == (UInt32)(0)) break; /* EOF */ 1.642 + 1.643 +# ifdef ONLY8086 1.644 + incw (BP, DI) 1.645 + jnz lzd19 1.646 + incw 2(BP, DI) 1.647 +# else 1.648 + incl (BP, DI) 1.649 +# endif 1.650 + 1.651 +lzd19: 1.652 + pop CX 1.653 + jz lzdone 1.654 + 1.655 +// } 1.656 +// len += kMatchMinLen;/*2*/ 1.657 + 1.658 + inc CX 1.659 + 1.660 +// string: // if (rep0 > nowPos) return LZMA_RESULT_DATA_ERROR; 1.661 +// do { 1.662 +lzd13z: 1.663 +// previousByte = outStream[nowPos - rep0]; 1.664 +// outStream[nowPos++] = previousByte; 1.665 + 1.666 + call outcharDico // %bl = outStream[nowPos++] = outStream[nowPos - rep0] 1.667 + 1.668 +// } while(--len != 0); 1.669 + 1.670 + loop lzd13z 1.671 + 1.672 +// } /* char/string */ 1.673 +// } 1.674 + 1.675 + jmp lzdmainlp 1.676 + 1.677 +lzdone: 1.678 +// //RC_NORMALIZE; 1.679 +// //*inSizeProcessed = (SizeT)(Buffer - inStream); *outSizeProcessed = nowPos; 1.680 +// return LZMA_RESULT_OK; 1.681 + call Dico2ESDI // set es & di (rep0 = 0) 1.682 + lea ws2(BP), SP // dealloc 1.683 + ret 1.684 +// } 1.685 + 1.686 +// al = outStream[nowPos - rep0]; 1.687 + 1.688 +/* 1.689 + * output es:di, al 1.690 + * scratch bh, cl, flags 1.691 + */ 1.692 + 1.693 +DicoRep02ESDI: 1.694 + stc 1.695 + 1.696 +// bl = outStream[nowPos]; 1.697 + 1.698 +/* 1.699 + * output es:di, bl 1.700 + * scratch bh, cl, flags 1.701 + */ 1.702 + 1.703 +Dico2ESDI: 1.704 +#if !defined(FLAT32) && !defined(FLAT16OUT) 1.705 +# ifdef ONLY8086 1.706 + pushw %ax 1.707 + movw nowPos(%bp), %bx 1.708 + movw nowPos+2(%bp), %ax 1.709 + jnc Dico2ESDIz 1.710 + subw rep0(%bp), %bx 1.711 + sbbw rep0+2(%bp), %ax 1.712 +Dico2ESDIz: 1.713 + movw $0xF, %di 1.714 + andw %bx, %di 1.715 + pushw %cx 1.716 + movb $4, %cl 1.717 + shrw %cl, %bx 1.718 + shlw %cl, %ax 1.719 + popw %cx 1.720 + addb %al, %bh 1.721 + popw %ax 1.722 +# else 1.723 + movl nowPos(%bp), %ebx 1.724 + jnc Dico2ESDIz 1.725 + subl rep0(%bp), %ebx 1.726 +Dico2ESDIz: 1.727 + movw %bx, %di 1.728 + xorw %bx, %bx 1.729 + shrl $4, %ebx 1.730 +# endif 1.731 + movw %bx, %es 1.732 +#else 1.733 + mov nowPos(BP), DI 1.734 + jnc Dico2ESDIz 1.735 + sub rep0(BP), DI 1.736 +Dico2ESDIz: 1.737 +#endif 1.738 +#ifdef FLAT32 1.739 + movb (DI), %bl 1.740 +#else 1.741 + movb %es:(%di), %bl 1.742 +#endif 1.743 + ret 1.744 + 1.745 +outcharDico: 1.746 + 1.747 +// bl = outStream[nowPos++] = outStream[nowPos - rep0] 1.748 + 1.749 +/* 1.750 + * output es:di, bl 1.751 + * update nowPos 1.752 + * scratch ax, dx, bh, cl, flags 1.753 + */ 1.754 + 1.755 + call DicoRep02ESDI // %bl = outStream[nowPos - rep0] 1.756 + xchg AX, BX 1.757 +outchar: 1.758 + 1.759 +// bl = outStream[nowPos++] = previousByte = al; 1.760 + 1.761 +/* 1.762 + * output bl 1.763 + * update nowPos 1.764 + * scratch ax, dx, bh, di, cl, flags 1.765 + */ 1.766 + 1.767 + clc 1.768 + call Dico2ESDI 1.769 + stosb 1.770 + xchg AX, BX // previous byte 1.771 + 1.772 +// int posState = (int)((nowPos) & posStateMask); 1.773 + 1.774 +#if PROP_PB != 0 && PROP_LP != 0 1.775 + addw $0x0101, posState2(BP) 1.776 + andb $(((1 << PROP_PB) -1)<<8)+((1 << PROP_LP) -1), posState2(BP) 1.777 +#else 1.778 +# if PROP_PB != 0 1.779 + incb posState(BP) 1.780 + andb $((1 << PROP_PB) -1), posState(BP) 1.781 +# endif 1.782 +# if PROP_LP != 0 1.783 + incb posState2(BP) 1.784 + andb $((1 << PROP_LP) -1), posState2(BP) 1.785 +# endif 1.786 +#endif 1.787 +#ifdef ONLY8086 1.788 + incw nowPos(BP) 1.789 + jnz incnowPosDone 1.790 + incw nowPos+2(BP) 1.791 +incnowPosDone: 1.792 +#else 1.793 + incl nowPos(BP) 1.794 +#endif 1.795 + ret 1.796 + 1.797 +// 1.798 +// #define RC_NORMALIZE if (Range < kTopValue) 1.799 +// { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } 1.800 + 1.801 +/* 1.802 + * update Range, Code, ds:si 1.803 + * scratch flags 1.804 + */ 1.805 + 1.806 +RC_NORMALIZE: 1.807 + cmpb $0, Range+3(BP) 1.808 + jne RC_NORMALIZE_1 1.809 +RC_LOAD_BYTE: 1.810 + push AX 1.811 +#ifdef ONLY8086 1.812 + movw Range+1(BP), %ax 1.813 + movw %ax, Range+2(BP) 1.814 + movw Code+1(BP), %ax 1.815 + movw %ax, Code+2(BP) 1.816 + xorw %ax, %ax 1.817 + movb Range(BP), %ah 1.818 + movw %ax, Range(BP) 1.819 + movb Code(BP), %ah 1.820 + movw %ax, Code(BP) 1.821 +#else 1.822 + shll $8, Range(BP) 1.823 + shll $8, Code(BP) 1.824 +#endif 1.825 +#if !defined(FLAT16) && !defined(FLAT32) 1.826 + testw %si, %si 1.827 + jns RC_READ_BYTE 1.828 + movw %ds, %ax 1.829 + incw %ax 1.830 + movw %ax, %ds 1.831 + addw $-16, %si 1.832 +RC_READ_BYTE: 1.833 +#endif 1.834 + lodsb 1.835 + movb %al, Code(BP) 1.836 + pop AX 1.837 +RC_NORMALIZE_1: 1.838 + ret 1.839 + 1.840 +// Bit1(dx + (state << kNumPosBitsMax /*4*/) + posState) 1.841 + 1.842 +Bit1state: 1.843 + movb $16, %al 1.844 + mulb state(BP) 1.845 +# if PROP_PB != 0 1.846 + addb posState(BP), %al 1.847 +# endif 1.848 +Bit1axdx: 1.849 + add DX, AX 1.850 + jmp Bit1 1.851 + 1.852 +// prob += 12; Bit1(prob) 1.853 + 1.854 +Bit1dx12: 1.855 + add $12, DX 1.856 +Bit1dx: 1.857 + mov DX, AX 1.858 + 1.859 +// static int Bit1(CProb *p) 1.860 + 1.861 +Bit1: 1.862 +/* 1.863 + * input ax=p 1.864 + * output C, ax 1.865 + * update bound, Range, Code, ds:si 1.866 + * scratch flags 1.867 + */ 1.868 + 1.869 +// { 1.870 +// RC_NORMALIZE; 1.871 + 1.872 + call RC_NORMALIZE // kill %ax, update %si 1.873 + 1.874 +#ifdef ONLY8086 1.875 + pushw %ax 1.876 + pushw %cx 1.877 + pushw %dx 1.878 + pushw %di 1.879 +#else 1.880 + pushal 1.881 +#endif 1.882 + 1.883 + xchg AX, DI 1.884 + add DI, DI // short * 1.885 + 1.886 + 1.887 +// bound = (Range>>kNumBitModelTotalBits /*11*/) * *(p); 1.888 + 1.889 +#ifdef ONLY8086 1.890 + movw Range(BP), %dx 1.891 + movw Range+2(BP), %ax 1.892 + movw $11, %cx 1.893 +shr11lp: 1.894 + shrw $1, %ax 1.895 + rcrw $1, %dx 1.896 + loop shr11lp 1.897 + movw %dx, %cx 1.898 + mulw (BP, DI) 1.899 + xchgw %ax, %cx 1.900 + mulw (BP, DI) 1.901 + addw %cx, %dx 1.902 +#else 1.903 + movl Range(BP), %eax 1.904 + shrl $11, %eax 1.905 + movzwl (BP, DI), %edx 1.906 + mull %edx 1.907 +#endif 1.908 + 1.909 +// if (Code < bound) { 1.910 + 1.911 +#ifdef ONLY8086 1.912 + cmpw Code+2(BP), %dx 1.913 + jb Bit1_1 1.914 + ja Bit1_1x 1.915 + cmpw Code(BP), %ax 1.916 + jbe Bit1_1 1.917 +Bit1_1x: 1.918 + 1.919 +// Range = bound; 1.920 + 1.921 + movw %ax, Range(BP) 1.922 + movw %dx, Range+2(BP) 1.923 +#else 1.924 + cmpl Code(BP), %eax 1.925 + jbe Bit1_1 1.926 + 1.927 +// Range = bound; 1.928 + 1.929 + movl %eax, Range(BP) 1.930 +#endif 1.931 + 1.932 +// *(p) += (kBitModelTotal /*2048*/ - *(p)) >> kNumMoveBits /*5*/; 1.933 + 1.934 + movw $2048, %ax 1.935 + 1.936 +// return 0; 1.937 + 1.938 + jmp Bit1_2 1.939 + 1.940 +// } 1.941 +// else { 1.942 + 1.943 +Bit1_1: 1.944 + 1.945 +// Range -= bound; Code -= bound; 1.946 + 1.947 +#ifdef ONLY8086 1.948 + subw %ax, Range(BP) 1.949 + sbbw %dx, Range+2(BP) 1.950 + subw %ax, Code(BP) 1.951 + sbbw %dx, Code+2(BP) 1.952 +#else 1.953 + subl %eax, Range(BP) 1.954 + subl %eax, Code(BP) 1.955 +#endif 1.956 + 1.957 +// *(p) -= (*(p)) >> kNumMoveBits /*5*/; 1.958 + 1.959 + movw $31, %ax 1.960 + 1.961 +// return 1; 1.962 + 1.963 + stc 1.964 +Bit1_2: 1.965 + pushf 1.966 + subw (BP, DI), %ax 1.967 +#ifdef ONLY8086 1.968 + movb $5, %cl 1.969 + sarw %cl, %ax 1.970 +#else 1.971 + sarw $5, %ax 1.972 +#endif 1.973 + addw %ax, (BP, DI) 1.974 + popf 1.975 +#ifdef ONLY8086 1.976 + popw %di 1.977 + popw %dx 1.978 + popw %cx 1.979 + popw %ax 1.980 +#else 1.981 + popal 1.982 +#endif 1.983 + sbb AX, AX 1.984 + 1.985 +// } 1.986 +// } 1.987 + 1.988 + ret 1.989 + 1.990 +RangeDecoder: 1.991 + 1.992 +/* 1.993 + * input ax=probs cx=numLevels (< 8) bx=1 1.994 + * output ax=res (backward), dh (forward) 1.995 + * update bound, Range, Code, ds:si 1.996 + * scratch flags, cx=0, dl 1.997 + */ 1.998 + 1.999 + push BX 1.1000 + 1.1001 +// { int i = numLevels; res = 1; 1.1002 + mov BX, DX // res = 1 1.1003 + 1.1004 +// do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); 1.1005 + 1.1006 +RangeDecoder_1: 1.1007 + push AX 1.1008 + call Bit1axdx // C,%ax = Bit1(prob+%ax) 1.1009 + rclb $1, %dl // res <<= 1; res |= C 1.1010 + andb %bl, %al // current bit 1.1011 + orb %al, %bh // store in bh 1.1012 + shlb $1, %bl // update max 1.1013 + pop AX 1.1014 + loop RangeDecoder_1 1.1015 + 1.1016 +// res -= (1 << numLevels); } 1.1017 + 1.1018 + xchg AX, BX // move bh to dh 1.1019 + xchg AX, DX // and dl to al 1.1020 + sub %dl, %al // sub max 1.1021 + pop BX 1.1022 + ret