From 410544f4e6439d0fc1ecb05eb7f58d5d6ba78fcf Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Fri, 3 Jan 2020 10:01:23 +0100 Subject: [PATCH] Fast 6502 LZSA2 depacker: smaller size, same speed --- asm/6502/decompress_faster_v2.asm | 189 ++++++++++++++++++++---------- 1 file changed, 124 insertions(+), 65 deletions(-) diff --git a/asm/6502/decompress_faster_v2.asm b/asm/6502/decompress_faster_v2.asm index c8768c8..d535774 100644 --- a/asm/6502/decompress_faster_v2.asm +++ b/asm/6502/decompress_faster_v2.asm @@ -5,10 +5,12 @@ ; ; NMOS 6502 decompressor for data stored in Emmanuel Marty's LZSA2 format. ; +; This code is written for the ACME assembler. +; ; Optional code is presented for two minor 6502 optimizations that break ; compatibility with the current LZSA2 format standard. ; -; This code is written for the ACME assembler. +; The code is 241 bytes for the small version, and 256 bytes for the normal. ; ; Copyright John Brandwood 2019. ; @@ -28,7 +30,7 @@ ; ; - ; Save 7 bytes of code, and 21 cycles every time that a + ; Save 7 bytes of code, and 21 cycles every time that a ; 16-bit length is decoded? ; ; N.B. Setting this breaks compatibility with LZSA v1.2 @@ -46,12 +48,34 @@ LZSA_SWAP_LEN16 = 0 LZSA_SWAP_XZY = 0 ; - ; Remove code inlining to save space? - ; - ; This saves 15 bytes of code, but decompression is 7% slower. + ; Choose size over space (within sane limits)? ; -LZSA_BEST_SIZE = 0 +LZSA_SMALL_SIZE = 0 + + ; + ; Remove code inlining to save space? + ; + ; This saves 15 bytes of code at the cost of 7% speed. + ; + + !if LZSA_SMALL_SIZE { +LZSA_NO_INLINE = 1 + } else { +LZSA_NO_INLINE = 0 + } + + ; + ; Use smaller code for copying literals? + ; + ; This saves 11 bytes of code at the cost of 5% speed. + ; + + !if LZSA_SMALL_SIZE { +LZSA_SHORT_CP = 1 + } else { +LZSA_SHORT_CP = 1 + } ; ; Assume that we're decompessing from a large multi-bank @@ -66,62 +90,61 @@ LZSA_FROM_BANK = 0 ; !if LZSA_FROM_BANK { - - !macro LZSA_INC_PAGE { - jsr .next_page - } - + !macro LZSA_INC_PAGE { + jsr .next_page + } } else { - - !macro LZSA_INC_PAGE { - inc