mirror of
https://github.com/exoticorn/upkr.git
synced 2026-01-20 11:36:42 +01:00
z80_unpacker: optimisations: -2B and -27T in decode_bit = 180B
This commit is contained in:
@@ -207,8 +207,9 @@ decode_bit:
|
|||||||
inc a
|
inc a
|
||||||
; ** adjust state
|
; ** adjust state
|
||||||
push af
|
push af
|
||||||
|
push bc
|
||||||
|
ld c,l ; C = (upkr_state & 255); (preserving the value)
|
||||||
push af
|
push af
|
||||||
push hl
|
|
||||||
push af
|
push af
|
||||||
jr nc,.bit_is_0
|
jr nc,.bit_is_0
|
||||||
neg ; A = -prob == (256-prob), CF=1 preserved
|
neg ; A = -prob == (256-prob), CF=1 preserved
|
||||||
@@ -216,22 +217,19 @@ decode_bit:
|
|||||||
ld d,0
|
ld d,0
|
||||||
ld e,a ; DE = state_scale ; prob || (256-prob)
|
ld e,a ; DE = state_scale ; prob || (256-prob)
|
||||||
ld l,d ; H:L = (upkr_state>>8) : 0
|
ld l,d ; H:L = (upkr_state>>8) : 0
|
||||||
ld a,8 ; counter
|
ld b,8 ; counter
|
||||||
.mulLoop:
|
.mulLoop:
|
||||||
add hl,hl
|
add hl,hl
|
||||||
jr nc,.mul0
|
jr nc,.mul0
|
||||||
add hl,de
|
add hl,de
|
||||||
.mul0:
|
.mul0:
|
||||||
dec a
|
djnz .mulLoop ; until HL = state_scale * (upkr_state>>8), also BC becomes (upkr_state & 255)
|
||||||
jr nz,.mulLoop ; until HL = state_scale * (upkr_state>>8)
|
add hl,bc ; HL = state_scale * (upkr_state >> 8) + (upkr_state & 255)
|
||||||
pop af
|
pop af
|
||||||
jr nc,.bit_is_0_2
|
jr nc,.bit_is_0_2
|
||||||
dec d ; D = 0xFF (DE = -prob)
|
dec h
|
||||||
add hl,de ; HL += -prob
|
add hl,de ; HL += -prob (HL += (256 - prob) - 256)
|
||||||
.bit_is_0_2: ; HL = state_offset + state_scale * (upkr_state >> 8)
|
.bit_is_0_2: ; HL = state_offset + state_scale * (upkr_state >> 8) + (upkr_state & 255) ; new upkr_state
|
||||||
pop de
|
|
||||||
ld d,0 ; DE = (upkr_state & 255)
|
|
||||||
add hl,de ; HL = state_offset + state_scale * (upkr_state >> 8) + (upkr_state & 255) ; new upkr_state
|
|
||||||
; *** adjust probs[context_index]
|
; *** adjust probs[context_index]
|
||||||
pop af ; restore prob and bit
|
pop af ; restore prob and bit
|
||||||
ld e,a
|
ld e,a
|
||||||
@@ -246,6 +244,7 @@ decode_bit:
|
|||||||
adc a,d ; A = -prob_offset + ((prob + 8) >> 4)
|
adc a,d ; A = -prob_offset + ((prob + 8) >> 4)
|
||||||
neg
|
neg
|
||||||
add a,e ; A = prob_offset + prob - ((prob + 8) >> 4)
|
add a,e ; A = prob_offset + prob - ((prob + 8) >> 4)
|
||||||
|
pop bc
|
||||||
ld (bc),a ; update probs[context_index]
|
ld (bc),a ; update probs[context_index]
|
||||||
pop af ; restore resulting CF = bit
|
pop af ; restore resulting CF = bit
|
||||||
pop de
|
pop de
|
||||||
|
|||||||
Reference in New Issue
Block a user