wok diff plop/stuff/unlz4.S @ rev 25519
created recipes for libuv and libuv-dev 1.44.1
author | Hans-G?nter Theisgen |
---|---|
date | Fri Feb 24 15:35:59 2023 +0100 (21 months ago) |
parents | |
children | f2b4a9eb8bdd |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/plop/stuff/unlz4.S Fri Feb 24 15:35:59 2023 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +// Lz4Decode: 1.5 +#ifndef FLAT32 1.6 +// input ds:si=inStream, es:di=outStream 1.7 +// output outStream[], ds:si, es:di 1.8 + .code16 1.9 +#define AX %ax 1.10 +#define BX %bx 1.11 +#define CX %cx 1.12 +#define SI %si 1.13 +#define DI %di 1.14 +#else 1.15 +// input esi=inStream, edi=outStream 1.16 +// output outStream[], ds:esi, es:edi 1.17 + .code32 1.18 +#define AX %eax 1.19 +#define BX %ebx 1.20 +#define CX %ecx 1.21 +#define SI %esi 1.22 +#define DI %edi 1.23 +#endif 1.24 + 1.25 +#define ARCHIVE_MAGICNUMBER 0x184C2102 1.26 + 1.27 +//#define PARANOIA // cover rare cases, optional 1.28 + 1.29 +lz4main: 1.30 +#ifdef PARANOIA 1.31 + cld 1.32 +# if !defined(FLAT32) && !defined(FLAT16OUT) 1.33 + xorl %cx, %cx 1.34 + call lz4mov 1.35 +# endif 1.36 +#endif 1.37 + lodsl // get chunkSize 1.38 +#ifndef NO_LZ4_HEADER 1.39 + cmpl $ARCHIVE_MAGICNUMBER, %eax 1.40 + je lz4main 1.41 +#endif 1.42 + orl %eax, %eax // end of file ? 1.43 + je lz4quit 1.44 + xchgl %eax, %edx 1.45 +lz4chunk: // uncompress chunk 1.46 + lodsb // get token 1.47 + movb %al, %bl 1.48 + shrb $4, %al 1.49 + call lz4len // get literal length 1.50 + subl %ecx, %edx // count literal 1.51 +#if !defined(FLAT32) && !defined(FLAT16OUT) && (!defined(FLAT16) || !defined(PARANOIA)) 1.52 +#define NeedLz4mov 1.53 + call lz4mov // copy literals 1.54 +#else 1.55 + rep movsb 1.56 +#endif 1.57 + subl $1+2, %edx // count token & string address 1.58 + jle lz4main 1.59 + lodsw // get string address 1.60 + xchg AX, BX 1.61 + call lz4len // get string length 1.62 + add $4, CX 1.63 +#if !defined(FLAT32) && !defined(FLAT16OUT) 1.64 + pushw %ds 1.65 + pushw %si 1.66 + movw %di, %si 1.67 + subw %bx, %si 1.68 + movw %es, %ax 1.69 + jnc axok 1.70 + subb $0x10, %ah 1.71 +axok: 1.72 +.macro norm reg 1.73 + movw %si, \reg 1.74 + andw $0xF, %si 1.75 + shrw $4, \reg 1.76 + addw \reg, %ax 1.77 + movw %ax, %ds 1.78 + movw %di, \reg 1.79 + andw $0xF, %di 1.80 + shrw $4, \reg 1.81 + movw %es, %ax 1.82 + addw \reg, %ax 1.83 + movw %ax, %es 1.84 +.endm 1.85 +# if !defined (NeedLz4mov) 1.86 + norm %bp 1.87 + rep movsb 1.88 +# else 1.89 + call lz4movStr // copy string 1.90 +# endif 1.91 + popw %si 1.92 + popw %ds 1.93 +#else 1.94 + xchg AX, SI 1.95 + mov DI, SI 1.96 + sub BX, SI 1.97 + rep movsb %es:(SI), %es:(DI) 1.98 + xchg AX, SI 1.99 +#endif 1.100 + jmp lz4chunk 1.101 + 1.102 +#if defined(NeedLz4mov) 1.103 +# if defined(PARANOIA) 1.104 +lz4movlp: 1.105 + xchgw %ax, %cx 1.106 + movw $0x3C00, %cx 1.107 + rep movsl 1.108 + xchgw %ax, %cx 1.109 + sub $0xF0, %ch 1.110 +# endif 1.111 +lz4mov: 1.112 + movw %ds, %ax 1.113 +lz4movStr: 1.114 + norm %bp 1.115 +# if defined(PARANOIA) 1.116 + cmp $0xFF, %ch // catch FFFX case 1.117 + jz lz4movlp 1.118 +# endif 1.119 + rep movsb 1.120 + ret 1.121 +#endif 1.122 + 1.123 +lz4len: // get length in %ecx 1.124 + andl $0xF, %eax 1.125 + movl %eax, %ecx 1.126 + cmpb $0xF, %al 1.127 + jne lz4quit 1.128 +lz4len2: 1.129 + lodsb 1.130 + decl %edx // remaining chunk size 1.131 + addw %ax, %cx 1.132 + cmpb $0xFF, %al 1.133 + je lz4len2 1.134 +lz4quit: 1.135 + ret