From caa66aea951e8b0513b4fcc6d0aea4ad9ecbd655 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Mon, 7 Apr 2025 21:01:05 +0200 Subject: [PATCH] Add decompress_lz4 C implementation as comment For reference. --- libsrc/common/lz4.s | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/libsrc/common/lz4.s b/libsrc/common/lz4.s index 57773c86a..c53841897 100644 --- a/libsrc/common/lz4.s +++ b/libsrc/common/lz4.s @@ -6,6 +6,60 @@ ; Almost 7 times faster, uses no RAM (vs 14 bytes BSS), and takes 1/4 the space ; vs the official C source. ; +; +; C implementation was: + +; void decompress_lz4 (unsigned char *in, unsigned char *out, const int outlen) { +; unsigned char token, tmp; +; unsigned int offset; +; unsigned char *end = out+outlen; +; unsigned char *copysrc; +; +; while (out < end) { +; token = *in++; +; offset = token >> 4; +; +; token &= 0x0f; +; token += 4; // Minmatch +; +; if (offset == 15) { +; moreliterals: +; tmp = *in++; +; offset += tmp; +; if (tmp == 255) +; goto moreliterals; +; } +; +; if (offset) { +; memcpy(out, in, offset); +; out += offset; +; in += offset; +; } +; +; if (out >= end) { +; return; +; } +; +; offset = (*in); +; in++; +; offset += (*in)<<8; +; in++; +; +; copysrc = out - offset; +; offset = token; +; +; if (token == 19) { +; morematches: +; tmp = *in++; +; offset += tmp; +; if (tmp == 255) +; goto morematches; +; } +; +; memcpy(out, copysrc, offset); +; out += offset; +; } +; } .importzp sp, sreg, regsave, regbank .importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4