Skip to content

Commit be028cc

Browse files
committed
upd
1 parent a48dca0 commit be028cc

28 files changed

Lines changed: 2415 additions & 0 deletions

compression/blz_depack_x86.asm

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
; BriefLZ depacker in 92 bytes of x86 assembly (optimized for size)
3+
; Odzhan
4+
5+
bits 32
6+
7+
%ifndef BIN
8+
global blz_depackx
9+
global _blz_depackx
10+
%endif
11+
12+
blz_depack:
13+
_blz_depack:
14+
pushad
15+
lea esi, [esp+32+4] ;
16+
lodsd
17+
xchg edi, eax ; bs.dst = outbuf
18+
lodsd
19+
lea ebx, [edi+eax] ; end = bs.dst + outlen
20+
lodsd
21+
xchg esi, eax ; bs.src = inbuf
22+
call blz_init_getbit
23+
blz_getbit:
24+
add ax, ax ; tag <<= 1
25+
jnz blz_exit_getbit ; continue for all bits
26+
lodsw ; read 16-bit tag
27+
adc ax, ax ; carry over previous bit
28+
blz_exit_getbit:
29+
ret
30+
blz_init_getbit:
31+
pop ebp ; ebp = blz_getbit
32+
mov ax, 8000h ;
33+
blz_literal:
34+
movsb ; *out++ = *bs.src++
35+
blz_main:
36+
cmp edi, ebx ; while(out < end)
37+
jnb blz_exit
38+
39+
call ebp ; cf = blz_getbit
40+
jnc blz_literal ; if(cf==0) goto blz_literal
41+
;
42+
blz_getgamma:
43+
pushfd ; save cf
44+
cdq ; result = 1
45+
inc edx
46+
blz_gamma_loop:
47+
call ebp ; cf = blz_getbit()
48+
adc edx, edx ; result = (result << 1) + cf
49+
call ebp ; cf = blz_getbit()
50+
jc blz_gamma_loop ; while(cf == 1)
51+
52+
popfd ; restore cf
53+
cmovc ecx, edx ; ecx = cf ? edx : ecx
54+
cmc ; complement carry
55+
jnc blz_getgamma ; loop twice
56+
57+
; ofs = blz_getgamma(&bs) - 2;
58+
dec edx
59+
dec edx
60+
61+
; len = blz_getgamma(&bs) + 2;
62+
inc ecx
63+
inc ecx
64+
65+
; ofs = (ofs << 8) + (uint32_t)*bs.src++ + 1;
66+
shl edx, 8
67+
mov dl, [esi]
68+
inc esi
69+
inc edx
70+
71+
; ptr = out - ofs;
72+
push esi
73+
mov esi, edi
74+
sub esi, edx
75+
rep movsb
76+
pop esi
77+
jmp blz_main
78+
blz_exit:
79+
; return (out - (uint8_t*)outbuf);
80+
sub edi, [esp+32+4]
81+
mov [esp+28], edi
82+
popad
83+
ret
84+

0 commit comments

Comments
 (0)