Skip to content

Commit

Permalink
Fix "RLE" compression with big endian architectures
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
KungFuJesus authored and Dead2 committed Dec 22, 2024
1 parent 04d1b75 commit 90913e8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compare256_rle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 90913e8

Please sign in to comment.