]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Ensure that unaligned compare256 variants are only used on little endian systems
authorCameron Cawley <ccawley2011@gmail.com>
Sat, 15 Apr 2023 18:08:05 +0000 (19:08 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 25 Apr 2023 10:07:55 +0000 (12:07 +0200)
compare256.c
cpu_features.h
functable.c
test/benchmarks/benchmark_compare256.cc
test/test_compare256.cc

index 94b88e756f57b28047f1a2bd07ff8774f5173212..82551cdd579ece16e4995a4c9272f06dc57e93b4 100644 (file)
@@ -56,7 +56,7 @@ Z_INTERNAL uint32_t compare256_c(const uint8_t *src0, const uint8_t *src1) {
 
 #include "match_tpl.h"
 
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 /* 16-bit unaligned integer comparison */
 static inline uint32_t compare256_unaligned_16_static(const uint8_t *src0, const uint8_t *src1) {
     uint32_t len = 0;
index b8ec883a226f33bf8a07e966c10bf2a57e7c21ae..2e1a888e38794225ff85ecfa80577a04b67f35c4 100644 (file)
@@ -155,7 +155,7 @@ extern uint32_t crc32_s390_vx(uint32_t crc, const uint8_t *buf, size_t len);
 typedef uint32_t (*compare256_func)(const uint8_t *src0, const uint8_t *src1);
 
 extern uint32_t compare256_c(const uint8_t *src0, const uint8_t *src1);
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 extern uint32_t compare256_unaligned_16(const uint8_t *src0, const uint8_t *src1);
 #ifdef HAVE_BUILTIN_CTZ
 extern uint32_t compare256_unaligned_32(const uint8_t *src0, const uint8_t *src1);
@@ -188,7 +188,7 @@ extern void insert_string_acle(deflate_state *const s, const uint32_t str, uint3
 
 /* longest_match */
 extern uint32_t longest_match_c(deflate_state *const s, Pos cur_match);
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 extern uint32_t longest_match_unaligned_16(deflate_state *const s, Pos cur_match);
 #ifdef HAVE_BUILTIN_CTZ
 extern uint32_t longest_match_unaligned_32(deflate_state *const s, Pos cur_match);
@@ -212,7 +212,7 @@ extern uint32_t longest_match_power9(deflate_state *const s, Pos cur_match);
 
 /* longest_match_slow */
 extern uint32_t longest_match_slow_c(deflate_state *const s, Pos cur_match);
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 extern uint32_t longest_match_slow_unaligned_16(deflate_state *const s, Pos cur_match);
 extern uint32_t longest_match_slow_unaligned_32(deflate_state *const s, Pos cur_match);
 #ifdef UNALIGNED64_OK
index aa018c0d64dbda3d941814ffe20c5f65d0a665b5..d2009829221677d683377ca562ff7a8e10bf42f2 100644 (file)
@@ -33,7 +33,7 @@ static void init_functable(void) {
     ft.slide_hash = &slide_hash_c;
     ft.update_hash = &update_hash_c;
 
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 #  if defined(UNALIGNED64_OK) && defined(HAVE_BUILTIN_CTZLL)
     ft.longest_match = &longest_match_unaligned_64;
     ft.longest_match_slow = &longest_match_slow_unaligned_64;
index 00c6cc6f63ca9fcf9b8d8c142a9f450bdb8090b5..3ab04d2022117f386501ad11b8a5217427b61cac 100644 (file)
@@ -61,7 +61,7 @@ public:
 
 BENCHMARK_COMPARE256(c, compare256_c, 1);
 
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 BENCHMARK_COMPARE256(unaligned_16, compare256_unaligned_16, 1);
 #ifdef HAVE_BUILTIN_CTZ
 BENCHMARK_COMPARE256(unaligned_32, compare256_unaligned_32, 1);
index f920d1d205325bd16ff0d361c239d6dbd141c74a..0e656da3713766e3d97777f7509ede2ea0e11ece 100644 (file)
@@ -60,7 +60,7 @@ static inline void compare256_match_check(compare256_func compare256) {
 
 TEST_COMPARE256(c, compare256_c, 1)
 
-#ifdef UNALIGNED_OK
+#if defined(UNALIGNED_OK) && BYTE_ORDER == LITTLE_ENDIAN
 TEST_COMPARE256(unaligned_16, compare256_unaligned_16, 1)
 #ifdef HAVE_BUILTIN_CTZ
 TEST_COMPARE256(unaligned_32, compare256_unaligned_32, 1)