Skip to content

Commit

Permalink
Ensure that unaligned compare256 variants are only used on little end…
Browse files Browse the repository at this point in the history
…ian systems
  • Loading branch information
ccawley2011 authored and Dead2 committed Apr 25, 2023
1 parent fc49c98 commit 38aa575
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compare256.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions cpu_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion functable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/benchmark_compare256.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class compare256: public benchmark::Fixture {

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);
Expand Down
2 changes: 1 addition & 1 deletion test/test_compare256.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38aa575

Please sign in to comment.