]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix "RLE" compression with big endian architectures
authorAdam Stylinski <kungfujesus06@gmail.com>
Sat, 21 Dec 2024 15:09:58 +0000 (10:09 -0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 22 Dec 2024 00:44:23 +0000 (01:44 +0100)
This was missed in #1831. The RLE methods compare a string of bytes
directly with itself to directly derive a simple run length encoding.
They use similar but not identical methods to compare256. This needs
a similar endianness check at compile time to know which compare bit
count to use (leading or trailing).

compare256_rle.h

index ccfbeba2a635bd9e20253d933b7f4d52d002ca22..c7a4086af663cfbaf4d358a638f3e0fa40a77082 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "zbuild.h"
 #include "fallback_builtins.h"
+#include "zendian.h"
 
 typedef uint32_t (*compare256_rle_func)(const uint8_t* src0, const uint8_t* src1);
 
@@ -88,7 +89,11 @@ static inline uint32_t compare256_rle_unaligned_32(const uint8_t *src0, const ui
 
         diff = sv ^ mv;
         if (diff) {
+#if BYTE_ORDER == LITTLE_ENDIAN
             uint32_t match_byte = __builtin_ctz(diff) / 8;
+#else
+            uint32_t match_byte = __builtin_clz(diff) / 8;
+#endif
             return len + match_byte;
         }
 
@@ -118,7 +123,11 @@ static inline uint32_t compare256_rle_unaligned_64(const uint8_t *src0, const ui
 
         diff = sv ^ mv;
         if (diff) {
+#if BYTE_ORDER == LITTLE_ENDIAN
             uint64_t match_byte = __builtin_ctzll(diff) / 8;
+#else
+            uint64_t match_byte = __builtin_clzll(diff) / 8;
+#endif
             return len + (uint32_t)match_byte;
         }