Commit 3c3166e6 for xz
commit 3c3166e6abcc1b2d9a53ef53ea655759fbd2995f
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Mon Oct 26 15:17:33 2026 +0200
liblzma: Add a speed optimization to the x86 filter
Since at least five bytes of input are available, one can compare
five bytes until checking for i < size again.
If unaligned access is fast, one could use 32-bit reads and check each
byte in the uint32_t. On some systems with specific inputs it was
slightly faster, but the benefit wasn't big enough and consistent enough
compared to this endianness-neutral byte-by-byte version.
diff --git a/src/liblzma/simple/x86.c b/src/liblzma/simple/x86.c
index 96036b4a..5b71bba8 100644
--- a/src/liblzma/simple/x86.c
+++ b/src/liblzma/simple/x86.c
@@ -39,8 +39,22 @@ x86_code(void *simple_ptr, uint32_t now_pos, bool is_encoder,
size_t i;
for (i = 0; i < size; ++i) {
+#ifdef HAVE_SMALL
if ((buffer[i] & 0xFE) != 0xE8)
continue;
+#else
+ while ((buffer[i] & 0xFE) != 0xE8
+ && (buffer[++i] & 0xFE) != 0xE8
+ && (buffer[++i] & 0xFE) != 0xE8
+ && (buffer[++i] & 0xFE) != 0xE8
+ && (buffer[++i] & 0xFE) != 0xE8
+ && ++i < size) ;
+
+ if (i >= size) {
+ i = size;
+ break;
+ }
+#endif
prev_pos = i - prev_pos;
prev_mask = prev_pos > 3 ? 0 : prev_mask >> prev_pos;