wok view 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 source
1 // Lz4Decode:
2 #ifndef FLAT32
3 // input ds:si=inStream, es:di=outStream
4 // output outStream[], ds:si, es:di
5 .code16
6 #define AX %ax
7 #define BX %bx
8 #define CX %cx
9 #define SI %si
10 #define DI %di
11 #else
12 // input esi=inStream, edi=outStream
13 // output outStream[], ds:esi, es:edi
14 .code32
15 #define AX %eax
16 #define BX %ebx
17 #define CX %ecx
18 #define SI %esi
19 #define DI %edi
20 #endif
22 #define ARCHIVE_MAGICNUMBER 0x184C2102
24 //#define PARANOIA // cover rare cases, optional
26 lz4main:
27 #ifdef PARANOIA
28 cld
29 # if !defined(FLAT32) && !defined(FLAT16OUT)
30 xorl %cx, %cx
31 call lz4mov
32 # endif
33 #endif
34 lodsl // get chunkSize
35 #ifndef NO_LZ4_HEADER
36 cmpl $ARCHIVE_MAGICNUMBER, %eax
37 je lz4main
38 #endif
39 orl %eax, %eax // end of file ?
40 je lz4quit
41 xchgl %eax, %edx
42 lz4chunk: // uncompress chunk
43 lodsb // get token
44 movb %al, %bl
45 shrb $4, %al
46 call lz4len // get literal length
47 subl %ecx, %edx // count literal
48 #if !defined(FLAT32) && !defined(FLAT16OUT) && (!defined(FLAT16) || !defined(PARANOIA))
49 #define NeedLz4mov
50 call lz4mov // copy literals
51 #else
52 rep movsb
53 #endif
54 subl $1+2, %edx // count token & string address
55 jle lz4main
56 lodsw // get string address
57 xchg AX, BX
58 call lz4len // get string length
59 add $4, CX
60 #if !defined(FLAT32) && !defined(FLAT16OUT)
61 pushw %ds
62 pushw %si
63 movw %di, %si
64 subw %bx, %si
65 movw %es, %ax
66 jnc axok
67 subb $0x10, %ah
68 axok:
69 .macro norm reg
70 movw %si, \reg
71 andw $0xF, %si
72 shrw $4, \reg
73 addw \reg, %ax
74 movw %ax, %ds
75 movw %di, \reg
76 andw $0xF, %di
77 shrw $4, \reg
78 movw %es, %ax
79 addw \reg, %ax
80 movw %ax, %es
81 .endm
82 # if !defined (NeedLz4mov)
83 norm %bp
84 rep movsb
85 # else
86 call lz4movStr // copy string
87 # endif
88 popw %si
89 popw %ds
90 #else
91 xchg AX, SI
92 mov DI, SI
93 sub BX, SI
94 rep movsb %es:(SI), %es:(DI)
95 xchg AX, SI
96 #endif
97 jmp lz4chunk
99 #if defined(NeedLz4mov)
100 # if defined(PARANOIA)
101 lz4movlp:
102 xchgw %ax, %cx
103 movw $0x3C00, %cx
104 rep movsl
105 xchgw %ax, %cx
106 sub $0xF0, %ch
107 # endif
108 lz4mov:
109 movw %ds, %ax
110 lz4movStr:
111 norm %bp
112 # if defined(PARANOIA)
113 cmp $0xFF, %ch // catch FFFX case
114 jz lz4movlp
115 # endif
116 rep movsb
117 ret
118 #endif
120 lz4len: // get length in %ecx
121 andl $0xF, %eax
122 movl %eax, %ecx
123 cmpb $0xF, %al
124 jne lz4quit
125 lz4len2:
126 lodsb
127 decl %edx // remaining chunk size
128 addw %ax, %cx
129 cmpb $0xFF, %al
130 je lz4len2
131 lz4quit:
132 ret