From 90913e8d05f0a8d77366be57107514c5e203f702 Mon Sep 17 00:00:00 2001 From: Adam Stylinski Date: Sat, 21 Dec 2024 10:09:58 -0500 Subject: [PATCH] Fix "RLE" compression with big endian architectures 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compare256_rle.h b/compare256_rle.h index ccfbeba2..c7a4086a 100644 --- a/compare256_rle.h +++ b/compare256_rle.h @@ -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; } -- 2.47.2