Skip to content

Commit

Permalink
Merge pull request madler#6 from ClickHouse-Extras/backport-x86-arm-c…
Browse files Browse the repository at this point in the history
…heck-features-constructor

Backport Check for x86 features when the library is loaded.
  • Loading branch information
kitaisreal authored Apr 15, 2021
2 parents 527425a + 9dd963a commit 16b42c7
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 20 deletions.
2 changes: 0 additions & 2 deletions arch/arm/arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ void dummy_linker_glue();
extern int arm_cpu_has_neon;
extern int arm_cpu_has_crc32;

void Z_INTERNAL arm_check_features(void);

#endif /* ARM_H_ */
2 changes: 1 addition & 1 deletion arch/arm/armfeature.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static inline int arm_has_neon() {
Z_INTERNAL int arm_cpu_has_neon;
Z_INTERNAL int arm_cpu_has_crc32;

void Z_INTERNAL arm_check_features(void) {
static void __attribute__((constructor)) arm_check_features(void) {
#if defined(__aarch64__) || defined(_M_ARM64)
arm_cpu_has_neon = 1; /* always available */
#else
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ static void cpuidex(int info, int subinfo, unsigned* eax, unsigned* ebx, unsigne
#endif
}

void Z_INTERNAL x86_check_features(void) {
unsigned eax, ebx, ecx, edx;
unsigned maxbasic;
static void __attribute__((constructor)) x86_check_features(void) {
unsigned eax, ebx, ecx, edx;
unsigned maxbasic;

cpuid(0, &maxbasic, &ebx, &ecx, &edx);

Expand Down
2 changes: 0 additions & 2 deletions arch/x86/x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ extern int x86_cpu_has_sse42;
extern int x86_cpu_has_pclmulqdq;
extern int x86_cpu_has_tzcnt;

void Z_INTERNAL x86_check_features(void);

#endif /* CPU_H_ */
6 changes: 0 additions & 6 deletions deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@ int32_t Z_EXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int32_t level, int
int wrap = 1;
static const char my_version[] = PREFIX2(VERSION);

#if defined(X86_FEATURES)
x86_check_features();
#elif defined(ARM_FEATURES)
arm_check_features();
#endif

if (version == NULL || version[0] != my_version[0] || stream_size != sizeof(PREFIX3(stream))) {
return Z_VERSION_ERROR;
}
Expand Down
6 changes: 0 additions & 6 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ int32_t Z_EXPORT PREFIX(inflateInit2_)(PREFIX3(stream) *strm, int32_t windowBits
int32_t ret;
struct inflate_state *state;

#if defined(X86_FEATURES)
x86_check_features();
#elif defined(ARM_FEATURES)
arm_check_features();
#endif

if (version == NULL || version[0] != PREFIX2(VERSION)[0] || stream_size != (int)(sizeof(PREFIX3(stream))))
return Z_VERSION_ERROR;
if (strm == NULL)
Expand Down

0 comments on commit 16b42c7

Please sign in to comment.