#include "../../zbuild.h"
+#include "arm_features.h"
#if defined(__linux__) && defined(HAVE_SYS_AUXV_H)
# include <sys/auxv.h>
}
#endif
-Z_INTERNAL int arm_cpu_has_neon;
-Z_INTERNAL int arm_cpu_has_crc32;
-
-void Z_INTERNAL arm_check_features(void) {
+void Z_INTERNAL arm_check_features(struct arm_cpu_features *features) {
#if defined(__aarch64__) || defined(_M_ARM64)
- arm_cpu_has_neon = 1; /* always available */
+ features->has_neon = 1; /* always available */
#else
- arm_cpu_has_neon = arm_has_neon();
+ features->has_neon = arm_has_neon();
#endif
- arm_cpu_has_crc32 = arm_has_crc32();
+ features->has_crc32 = arm_has_crc32();
}
#ifndef ARM_H_
#define ARM_H_
-extern int arm_cpu_has_neon;
-extern int arm_cpu_has_crc32;
+struct arm_cpu_features {
+ int has_neon;
+ int has_crc32;
+};
-void Z_INTERNAL arm_check_features(void);
+void Z_INTERNAL arm_check_features(struct arm_cpu_features *features);
#endif /* ARM_H_ */
#include "../../zbuild.h"
#include "power_features.h"
-Z_INTERNAL int power_cpu_has_altivec = 0;
-Z_INTERNAL int power_cpu_has_arch_2_07 = 0;
-Z_INTERNAL int power_cpu_has_arch_3_00 = 0;
-
-void Z_INTERNAL power_check_features(void) {
+void Z_INTERNAL power_check_features(struct power_cpu_features *features) {
#ifdef PPC_FEATURES
unsigned long hwcap;
#ifdef __FreeBSD__
#endif
if (hwcap & PPC_FEATURE_HAS_ALTIVEC)
- power_cpu_has_altivec = 1;
+ features->has_altivec = 1;
#endif
#ifdef POWER_FEATURES
#endif
if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
- power_cpu_has_arch_2_07 = 1;
+ features->has_arch_2_07 = 1;
if (hwcap2 & PPC_FEATURE2_ARCH_3_00)
- power_cpu_has_arch_3_00 = 1;
+ features->has_arch_3_00 = 1;
#endif
}
#ifndef POWER_H_
#define POWER_H_
-extern int power_cpu_has_altivec;
-extern int power_cpu_has_arch_2_07;
-extern int power_cpu_has_arch_3_00;
+struct power_cpu_features {
+ int has_altivec;
+ int has_arch_2_07;
+ int has_arch_3_00;
+};
-void Z_INTERNAL power_check_features(void);
+void Z_INTERNAL power_check_features(struct power_cpu_features *features);
#endif /* POWER_H_ */
#define VX_ALIGNMENT 16L
#define VX_ALIGN_MASK (VX_ALIGNMENT - 1)
-uint32_t Z_INTERNAL PREFIX(s390_crc32_vx)(uint32_t crc, const unsigned char *buf, size_t len) {
+uint32_t Z_INTERNAL crc32_s390_vx(uint32_t crc, const unsigned char *buf, size_t len) {
size_t prealign, aligned, remaining;
if (len < VX_MIN_LEN + VX_ALIGN_MASK)
# include <sys/auxv.h>
#endif
-Z_INTERNAL int PREFIX(s390_cpu_has_vx) = 0;
-
-void Z_INTERNAL PREFIX(s390_check_features)(void) {
-#ifdef S390_FEATURES
- PREFIX(s390_cpu_has_vx) = getauxval(AT_HWCAP) & HWCAP_S390_VX;
-#endif
+void Z_INTERNAL s390_check_features(struct s390_cpu_features *features) {
+ features->has_vx = getauxval(AT_HWCAP) & HWCAP_S390_VX;
}
#ifndef S390_FEATURES_H_
#define S390_FEATURES_H_
-extern int PREFIX(s390_cpu_has_vx);
+struct s390_cpu_features {
+ int has_vx;
+};
-void Z_INTERNAL PREFIX(s390_check_features)(void);
+void Z_INTERNAL s390_check_features(struct s390_cpu_features *features);
#endif
*/
#include "../../zbuild.h"
+#include "x86_features.h"
#ifdef _WIN32
# include <intrin.h>
#include <string.h>
-Z_INTERNAL int x86_cpu_has_avx2;
-Z_INTERNAL int x86_cpu_has_avx512;
-Z_INTERNAL int x86_cpu_has_avx512vnni;
-Z_INTERNAL int x86_cpu_has_sse2;
-Z_INTERNAL int x86_cpu_has_ssse3;
-Z_INTERNAL int x86_cpu_has_sse41;
-Z_INTERNAL int x86_cpu_has_sse42;
-Z_INTERNAL int x86_cpu_has_pclmulqdq;
-Z_INTERNAL int x86_cpu_has_vpclmulqdq;
-Z_INTERNAL int x86_cpu_has_os_save_ymm;
-Z_INTERNAL int x86_cpu_has_os_save_zmm;
-
static inline void cpuid(int info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) {
#ifdef _WIN32
unsigned int registers[4];
#endif
}
-void Z_INTERNAL x86_check_features(void) {
+void Z_INTERNAL x86_check_features(struct x86_cpu_features *features) {
unsigned eax, ebx, ecx, edx;
unsigned maxbasic;
cpuid(0, &maxbasic, &ebx, &ecx, &edx);
cpuid(1 /*CPU_PROCINFO_AND_FEATUREBITS*/, &eax, &ebx, &ecx, &edx);
- x86_cpu_has_sse2 = edx & 0x4000000;
- x86_cpu_has_ssse3 = ecx & 0x200;
- x86_cpu_has_sse41 = ecx & 0x80000;
- x86_cpu_has_sse42 = ecx & 0x100000;
- x86_cpu_has_pclmulqdq = ecx & 0x2;
+ features->has_sse2 = edx & 0x4000000;
+ features->has_ssse3 = ecx & 0x200;
+ features->has_sse41 = ecx & 0x80000;
+ features->has_sse42 = ecx & 0x100000;
+ features->has_pclmulqdq = ecx & 0x2;
if (ecx & 0x08000000) {
uint64_t xfeature = xgetbv(0);
- x86_cpu_has_os_save_ymm = ((xfeature & 0x06) == 0x06);
- x86_cpu_has_os_save_zmm = ((xfeature & 0xe6) == 0xe6);
+ features->has_os_save_ymm = ((xfeature & 0x06) == 0x06);
+ features->has_os_save_zmm = ((xfeature & 0xe6) == 0xe6);
} else {
- x86_cpu_has_os_save_ymm = 0;
- x86_cpu_has_os_save_zmm = 0;
+ features->has_os_save_ymm = 0;
+ features->has_os_save_zmm = 0;
}
if (maxbasic >= 7) {
// check BMI1 bit
// Reference: https://software.intel.com/sites/default/files/article/405250/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family.pdf
- x86_cpu_has_vpclmulqdq = ecx & 0x400;
+ features->has_vpclmulqdq = ecx & 0x400;
// check AVX2 bit if the OS supports saving YMM registers
- if (x86_cpu_has_os_save_ymm) {
- x86_cpu_has_avx2 = ebx & 0x20;
+ if (features->has_os_save_ymm) {
+ features->has_avx2 = ebx & 0x20;
} else {
- x86_cpu_has_avx2 = 0;
+ features->has_avx2 = 0;
}
// check AVX512 bits if the OS supports saving ZMM registers
- if (x86_cpu_has_os_save_zmm) {
- x86_cpu_has_avx512 = ebx & 0x00010000;
- x86_cpu_has_avx512vnni = ecx & 0x800;
+ if (features->has_os_save_zmm) {
+ features->has_avx512 = ebx & 0x00010000;
+ features->has_avx512vnni = ecx & 0x800;
} else {
- x86_cpu_has_avx512 = 0;
- x86_cpu_has_avx512vnni = 0;
+ features->has_avx512 = 0;
+ features->has_avx512vnni = 0;
}
} else {
- x86_cpu_has_avx2 = 0;
- x86_cpu_has_avx512 = 0;
- x86_cpu_has_avx512vnni = 0;
- x86_cpu_has_vpclmulqdq = 0;
+ features->has_avx2 = 0;
+ features->has_avx512 = 0;
+ features->has_avx512vnni = 0;
+ features->has_vpclmulqdq = 0;
}
}
#ifndef X86_FEATURES_H_
#define X86_FEATURES_H_
-extern int x86_cpu_has_avx2;
-extern int x86_cpu_has_avx512;
-extern int x86_cpu_has_avx512vnni;
-extern int x86_cpu_has_sse2;
-extern int x86_cpu_has_ssse3;
-extern int x86_cpu_has_sse41;
-extern int x86_cpu_has_sse42;
-extern int x86_cpu_has_pclmulqdq;
-extern int x86_cpu_has_vpclmulqdq;
-extern int x86_cpu_has_os_save_ymm;
-extern int x86_cpu_has_os_save_zmm;
+struct x86_cpu_features {
+ int has_avx2;
+ int has_avx512;
+ int has_avx512vnni;
+ int has_sse2;
+ int has_ssse3;
+ int has_sse41;
+ int has_sse42;
+ int has_pclmulqdq;
+ int has_vpclmulqdq;
+ int has_os_save_ymm;
+ int has_os_save_zmm;
+};
-void Z_INTERNAL x86_check_features(void);
+void Z_INTERNAL x86_check_features(struct x86_cpu_features *features);
#endif /* CPU_H_ */
*/
#include "zbuild.h"
-
#include "cpu_features.h"
+#include <string.h>
-Z_INTERNAL void cpu_check_features(void) {
- static int features_checked = 0;
- if (features_checked)
- return;
+Z_INTERNAL void cpu_check_features(struct cpu_features *features) {
+ memset(features, 0, sizeof(struct cpu_features));
#if defined(X86_FEATURES)
- x86_check_features();
+ x86_check_features(&features->x86);
#elif defined(ARM_FEATURES)
- arm_check_features();
+ arm_check_features(&features->arm);
#elif defined(PPC_FEATURES) || defined(POWER_FEATURES)
- power_check_features();
+ power_check_features(&features->power);
#elif defined(S390_FEATURES)
- PREFIX(s390_check_features)();
+ s390_check_features(&features->s390);
#endif
- features_checked = 1;
}
# include "arch/s390/s390_features.h"
#endif
-extern void cpu_check_features(void);
+struct cpu_features {
+#if defined(X86_FEATURES)
+ struct x86_cpu_features x86;
+#elif defined(ARM_FEATURES)
+ struct arm_cpu_features arm;
+#elif defined(PPC_FEATURES) || defined(POWER_FEATURES)
+ struct power_cpu_features power;
+#elif defined(S390_FEATURES)
+ struct s390_cpu_features s390;
+#endif
+};
+
+extern void cpu_check_features(struct cpu_features *features);
/* adler32 */
typedef uint32_t (*adler32_func)(uint32_t adler, const uint8_t *buf, size_t len);
#elif defined(POWER8_VSX)
extern uint32_t crc32_power8(uint32_t crc, const uint8_t *buf, size_t len);
#elif defined(S390_CRC32_VX)
-extern uint32_t PREFIX(s390_crc32_vx)(uint32_t crc, const uint8_t *buf, size_t len);
+extern uint32_t crc32_s390_vx(uint32_t crc, const uint8_t *buf, size_t len);
#endif
/* compare256 */
*/
#include "zbuild.h"
-#include "cpu_features.h"
#include "deflate.h"
#include "deflate_p.h"
#include "functable.h"
deflate_state *s;
int wrap = 1;
- cpu_check_features();
-
if (strm == NULL)
return Z_STREAM_ERROR;
static void init_functable(void) {
struct functable_s ft;
+ struct cpu_features cf;
- cpu_check_features();
+ cpu_check_features(&cf);
// Generic code
ft.adler32 = &adler32_c;
// X86 - SSE2
#ifdef X86_SSE2
# if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2)
- if (x86_cpu_has_sse2)
+ if (cf.x86.has_sse2)
# endif
{
ft.chunkmemset_safe = &chunkmemset_safe_sse2;
#endif
// X86 - SSSE3
#ifdef X86_SSSE3
- if (x86_cpu_has_ssse3)
+ if (cf.x86.has_ssse3)
ft.adler32 = &adler32_ssse3;
#endif
// X86 - SSE4
#if defined(X86_SSE41) && defined(X86_SSE2)
- if (x86_cpu_has_sse41) {
+ if (cf.x86.has_sse41) {
ft.chunkmemset_safe = &chunkmemset_safe_sse41;
ft.inflate_fast = &inflate_fast_sse41;
}
#endif
#ifdef X86_SSE42
- if (x86_cpu_has_sse42) {
+ if (cf.x86.has_sse42) {
ft.adler32_fold_copy = &adler32_fold_copy_sse42;
ft.insert_string = &insert_string_sse4;
ft.quick_insert_string = &quick_insert_string_sse4;
#endif
// X86 - PCLMUL
#ifdef X86_PCLMULQDQ_CRC
- if (x86_cpu_has_pclmulqdq) {
+ if (cf.x86.has_pclmulqdq) {
ft.crc32 = &crc32_pclmulqdq;
ft.crc32_fold = &crc32_fold_pclmulqdq;
ft.crc32_fold_copy = &crc32_fold_pclmulqdq_copy;
#endif
// X86 - AVX
#ifdef X86_AVX2
- if (x86_cpu_has_avx2) {
+ if (cf.x86.has_avx2) {
ft.adler32 = &adler32_avx2;
ft.adler32_fold_copy = &adler32_fold_copy_avx2;
ft.chunkmemset_safe = &chunkmemset_safe_avx;
}
#endif
#ifdef X86_AVX512
- if (x86_cpu_has_avx512) {
+ if (cf.x86.has_avx512) {
ft.adler32 = &adler32_avx512;
ft.adler32_fold_copy = &adler32_fold_copy_avx512;
}
#endif
#ifdef X86_AVX512VNNI
- if (x86_cpu_has_avx512vnni) {
+ if (cf.x86.has_avx512vnni) {
ft.adler32 = &adler32_avx512_vnni;
ft.adler32_fold_copy = &adler32_fold_copy_avx512_vnni;
}
#endif
// X86 - VPCLMULQDQ
#if defined(X86_PCLMULQDQ_CRC) && defined(X86_VPCLMULQDQ_CRC)
- if (x86_cpu_has_pclmulqdq && x86_cpu_has_avx512 && x86_cpu_has_vpclmulqdq) {
+ if (cf.x86.has_pclmulqdq && cf.x86.has_avx512 && cf.x86.has_vpclmulqdq) {
ft.crc32 = &crc32_vpclmulqdq;
ft.crc32_fold = &crc32_fold_vpclmulqdq;
ft.crc32_fold_copy = &crc32_fold_vpclmulqdq_copy;
// ARM - NEON
#ifdef ARM_NEON
# ifndef ARM_NOCHECK_NEON
- if (arm_cpu_has_neon)
+ if (cf.arm.has_neon)
# endif
{
ft.adler32 = &adler32_neon;
#endif
// ARM - ACLE
#ifdef ARM_ACLE
- if (arm_cpu_has_crc32) {
+ if (cf.arm.has_crc32) {
ft.crc32 = &crc32_acle;
ft.insert_string = &insert_string_acle;
ft.quick_insert_string = &quick_insert_string_acle;
// Power - VMX
#ifdef PPC_VMX
- if (power_cpu_has_altivec) {
+ if (cf.power.has_altivec) {
ft.adler32 = &adler32_vmx;
ft.slide_hash = &slide_hash_vmx;
}
#endif
// Power8 - VSX
#ifdef POWER8_VSX
- if (power_cpu_has_arch_2_07) {
+ if (cf.power.has_arch_2_07) {
ft.adler32 = &adler32_power8;
ft.chunkmemset_safe = &chunkmemset_safe_power8;
ft.chunksize = &chunksize_power8;
}
#endif
#ifdef POWER8_VSX_CRC32
- if (power_cpu_has_arch_2_07)
+ if (cf.power.has_arch_2_07)
ft.crc32 = &crc32_power8;
#endif
// Power9
#ifdef POWER9
- if (power_cpu_has_arch_3_00) {
+ if (cf.power.has_arch_3_00) {
ft.compare256 = &compare256_power9;
ft.longest_match = &longest_match_power9;
ft.longest_match_slow = &longest_match_slow_power9;
// S390
#ifdef S390_CRC32_VX
- if (PREFIX(s390_cpu_has_vx))
- ft.crc32 = &PREFIX(s390_crc32_vx);
+ if (cf.s390.has_vx)
+ ft.crc32 = crc32_s390_vx;
#endif
// Assign function pointers individually for atomic operation
#include "zbuild.h"
#include "zutil.h"
-#include "cpu_features.h"
#include "inftrees.h"
#include "inflate.h"
#include "inflate_p.h"
int32_t ret;
struct inflate_state *state;
- cpu_check_features();
-
if (strm == NULL)
return Z_STREAM_ERROR;
strm->msg = NULL; /* in case we return an error */
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
-# include "cpu_features.h"
+# include "../test_cpu_features.h"
}
#define MAX_RANDOM_INTS (1024 * 1024)
BENCHMARK_ADLER32(c, adler32_c, 1);
#ifdef ARM_NEON
-BENCHMARK_ADLER32(neon, adler32_neon, arm_cpu_has_neon);
+BENCHMARK_ADLER32(neon, adler32_neon, test_cpu_features.arm.has_neon);
#endif
#ifdef PPC_VMX
-BENCHMARK_ADLER32(vmx, adler32_vmx, power_cpu_has_altivec);
+BENCHMARK_ADLER32(vmx, adler32_vmx, test_cpu_features.power.has_altivec);
#endif
#ifdef POWER8_VSX
-BENCHMARK_ADLER32(power8, adler32_power8, power_cpu_has_arch_2_07);
+BENCHMARK_ADLER32(power8, adler32_power8, test_cpu_features.power.has_arch_2_07);
#endif
#ifdef X86_SSSE3
-BENCHMARK_ADLER32(ssse3, adler32_ssse3, x86_cpu_has_ssse3);
+BENCHMARK_ADLER32(ssse3, adler32_ssse3, test_cpu_features.x86.has_ssse3);
#endif
#ifdef X86_AVX2
-BENCHMARK_ADLER32(avx2, adler32_avx2, x86_cpu_has_avx2);
+BENCHMARK_ADLER32(avx2, adler32_avx2, test_cpu_features.x86.has_avx2);
#endif
#ifdef X86_AVX512
-BENCHMARK_ADLER32(avx512, adler32_avx512, x86_cpu_has_avx512);
+BENCHMARK_ADLER32(avx512, adler32_avx512, test_cpu_features.x86.has_avx512);
#endif
#ifdef X86_AVX512VNNI
-BENCHMARK_ADLER32(avx512_vnni, adler32_avx512_vnni, x86_cpu_has_avx512vnni);
+BENCHMARK_ADLER32(avx512_vnni, adler32_avx512_vnni, test_cpu_features.x86.has_avx512vnni);
#endif
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
-# include "cpu_features.h"
+# include "../test_cpu_features.h"
}
#define MAX_RANDOM_INTS (1024 * 1024)
#ifdef ARM_NEON
/* If we inline this copy for neon, the function would go here */
-//BENCHMARK_ADLER32_COPY(neon, adler32_neon, arm_cpu_has_neon);
-BENCHMARK_ADLER32_BASELINE_COPY(neon_copy_baseline, adler32_neon, arm_cpu_has_neon);
+//BENCHMARK_ADLER32_COPY(neon, adler32_neon, test_cpu_features.arm.has_neon);
+BENCHMARK_ADLER32_BASELINE_COPY(neon_copy_baseline, adler32_neon, test_cpu_features.arm.has_neon);
#endif
#ifdef PPC_VMX
-//BENCHMARK_ADLER32_COPY(vmx_inline_copy, adler32_fold_copy_vmx, power_cpu_has_altivec);
-BENCHMARK_ADLER32_BASELINE_COPY(vmx_copy_baseline, adler32_vmx, power_cpu_has_altivec);
+//BENCHMARK_ADLER32_COPY(vmx_inline_copy, adler32_fold_copy_vmx, test_cpu_features.power.has_altivec);
+BENCHMARK_ADLER32_BASELINE_COPY(vmx_copy_baseline, adler32_vmx, test_cpu_features.power.has_altivec);
#endif
#ifdef POWER8_VSX
-//BENCHMARK_ADLER32_COPY(power8_inline_copy, adler32_fold_copy_power8, power_cpu_has_arch_2_07);
-BENCHMARK_ADLER32_BASELINE_COPY(power8, adler32_power8, power_cpu_has_arch_2_07);
+//BENCHMARK_ADLER32_COPY(power8_inline_copy, adler32_fold_copy_power8, test_cpu_features.power.has_arch_2_07);
+BENCHMARK_ADLER32_BASELINE_COPY(power8, adler32_power8, test_cpu_features.power.has_arch_2_07);
#endif
#ifdef X86_SSE42
-BENCHMARK_ADLER32_BASELINE_COPY(sse42_baseline, adler32_ssse3, x86_cpu_has_ssse3);
-BENCHMARK_ADLER32_COPY(sse42, adler32_fold_copy_sse42, x86_cpu_has_sse42);
+BENCHMARK_ADLER32_BASELINE_COPY(sse42_baseline, adler32_ssse3, test_cpu_features.x86.has_ssse3);
+BENCHMARK_ADLER32_COPY(sse42, adler32_fold_copy_sse42, test_cpu_features.x86.has_sse42);
#endif
#ifdef X86_AVX2
-BENCHMARK_ADLER32_BASELINE_COPY(avx2_baseline, adler32_avx2, x86_cpu_has_avx2);
-BENCHMARK_ADLER32_COPY(avx2, adler32_fold_copy_avx2, x86_cpu_has_avx2);
+BENCHMARK_ADLER32_BASELINE_COPY(avx2_baseline, adler32_avx2, test_cpu_features.x86.has_avx2);
+BENCHMARK_ADLER32_COPY(avx2, adler32_fold_copy_avx2, test_cpu_features.x86.has_avx2);
#endif
#ifdef X86_AVX512
-BENCHMARK_ADLER32_BASELINE_COPY(avx512_baseline, adler32_avx512, x86_cpu_has_avx512);
-BENCHMARK_ADLER32_COPY(avx512, adler32_fold_copy_avx512, x86_cpu_has_avx512);
+BENCHMARK_ADLER32_BASELINE_COPY(avx512_baseline, adler32_avx512, test_cpu_features.x86.has_avx512);
+BENCHMARK_ADLER32_COPY(avx512, adler32_fold_copy_avx512, test_cpu_features.x86.has_avx512);
#endif
#ifdef X86_AVX512VNNI
-BENCHMARK_ADLER32_BASELINE_COPY(avx512_vnni_baseline, adler32_avx512_vnni, x86_cpu_has_avx512vnni);
-BENCHMARK_ADLER32_COPY(avx512_vnni, adler32_fold_copy_avx512_vnni, x86_cpu_has_avx512vnni);
+BENCHMARK_ADLER32_BASELINE_COPY(avx512_vnni_baseline, adler32_avx512_vnni, test_cpu_features.x86.has_avx512vnni);
+BENCHMARK_ADLER32_COPY(avx512_vnni, adler32_fold_copy_avx512_vnni, test_cpu_features.x86.has_avx512vnni);
#endif
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
-# include "cpu_features.h"
+# include "../test_cpu_features.h"
}
#define MAX_COMPARE_SIZE (256)
#endif
#endif
#if defined(X86_SSE2) && defined(HAVE_BUILTIN_CTZ)
-BENCHMARK_COMPARE256(sse2, compare256_sse2, x86_cpu_has_sse2);
+BENCHMARK_COMPARE256(sse2, compare256_sse2, test_cpu_features.x86.has_sse2);
#endif
#if defined(X86_AVX2) && defined(HAVE_BUILTIN_CTZ)
-BENCHMARK_COMPARE256(avx2, compare256_avx2, x86_cpu_has_avx2);
+BENCHMARK_COMPARE256(avx2, compare256_avx2, test_cpu_features.x86.has_avx2);
#endif
#if defined(ARM_NEON) && defined(HAVE_BUILTIN_CTZLL)
-BENCHMARK_COMPARE256(neon, compare256_neon, arm_cpu_has_neon);
+BENCHMARK_COMPARE256(neon, compare256_neon, test_cpu_features.arm.has_neon);
#endif
#ifdef POWER9
-BENCHMARK_COMPARE256(power9, compare256_power9, power_cpu_has_arch_3_00);
+BENCHMARK_COMPARE256(power9, compare256_power9, test_cpu_features.power.has_arch_3_00);
#endif
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
-# include "cpu_features.h"
+# include "../test_cpu_features.h"
}
#define MAX_RANDOM_INTS (1024 * 1024)
BENCHMARK_CRC32(braid, PREFIX(crc32_braid), 1);
#ifdef ARM_ACLE
-BENCHMARK_CRC32(acle, crc32_acle, arm_cpu_has_crc32);
+BENCHMARK_CRC32(acle, crc32_acle, test_cpu_features.arm.has_crc32);
#elif defined(POWER8_VSX)
-BENCHMARK_CRC32(power8, crc32_power8, power_cpu_has_arch_2_07);
+BENCHMARK_CRC32(power8, crc32_power8, test_cpu_features.power.has_arch_2_07);
#elif defined(S390_CRC32_VX)
-BENCHMARK_CRC32(vx, PREFIX(s390_crc32_vx), PREFIX(s390_cpu_has_vx));
+BENCHMARK_CRC32(vx, crc32_s390_vx, test_cpu_features.s390.has_vx);
#elif defined(X86_PCLMULQDQ_CRC)
/* CRC32 fold does a memory copy while hashing */
-BENCHMARK_CRC32(pclmulqdq, crc32_pclmulqdq, x86_cpu_has_pclmulqdq);
+BENCHMARK_CRC32(pclmulqdq, crc32_pclmulqdq, test_cpu_features.x86.has_pclmulqdq);
#endif
#ifndef BUILD_ALT
extern "C" {
# include "zbuild.h"
-# include "cpu_features.h"
+# include "../test_cpu_features.h"
+
+ struct cpu_features test_cpu_features;
}
#endif
int main(int argc, char** argv) {
#ifndef BUILD_ALT
- cpu_check_features();
+ cpu_check_features(&test_cpu_features);
#endif
::benchmark::Initialize(&argc, argv);
# include "zbuild.h"
# include "zutil_p.h"
# include "deflate.h"
-# include "cpu_features.h"
+# include "../test_cpu_features.h"
}
#define MAX_RANDOM_INTS 32768
BENCHMARK_SLIDEHASH(c, slide_hash_c, 1);
#ifdef ARM_NEON
-BENCHMARK_SLIDEHASH(neon, slide_hash_neon, arm_cpu_has_neon);
+BENCHMARK_SLIDEHASH(neon, slide_hash_neon, test_cpu_features.arm.has_neon);
#endif
#ifdef POWER8_VSX
-BENCHMARK_SLIDEHASH(power8, slide_hash_power8, power_cpu_has_arch_2_07);
+BENCHMARK_SLIDEHASH(power8, slide_hash_power8, test_cpu_features.power.has_arch_2_07);
#endif
#ifdef PPC_VMX
-BENCHMARK_SLIDEHASH(vmx, slide_hash_vmx, power_cpu_has_altivec);
+BENCHMARK_SLIDEHASH(vmx, slide_hash_vmx, test_cpu_features.power.has_altivec);
#endif
#ifdef X86_SSE2
-BENCHMARK_SLIDEHASH(sse2, slide_hash_sse2, x86_cpu_has_sse2);
+BENCHMARK_SLIDEHASH(sse2, slide_hash_sse2, test_cpu_features.x86.has_sse2);
#endif
#ifdef X86_AVX2
-BENCHMARK_SLIDEHASH(avx2, slide_hash_avx2, x86_cpu_has_avx2);
+BENCHMARK_SLIDEHASH(avx2, slide_hash_avx2, test_cpu_features.x86.has_avx2);
#endif
extern "C" {
# include "zbuild.h"
-# include "cpu_features.h"
+# include "test_cpu_features.h"
}
#include <gtest/gtest.h>
TEST_ADLER32(c, adler32_c, 1)
#ifdef ARM_NEON
-TEST_ADLER32(neon, adler32_neon, arm_cpu_has_neon)
+TEST_ADLER32(neon, adler32_neon, test_cpu_features.arm.has_neon)
#elif defined(POWER8_VSX)
-TEST_ADLER32(power8, adler32_power8, power_cpu_has_arch_2_07)
+TEST_ADLER32(power8, adler32_power8, test_cpu_features.power.has_arch_2_07)
#elif defined(PPC_VMX)
-TEST_ADLER32(vmx, adler32_vmx, power_cpu_has_altivec)
+TEST_ADLER32(vmx, adler32_vmx, test_cpu_features.power.has_altivec)
#endif
#ifdef X86_SSSE3
-TEST_ADLER32(ssse3, adler32_ssse3, x86_cpu_has_ssse3)
+TEST_ADLER32(ssse3, adler32_ssse3, test_cpu_features.x86.has_ssse3)
#endif
#ifdef X86_AVX2
-TEST_ADLER32(avx2, adler32_avx2, x86_cpu_has_avx2)
+TEST_ADLER32(avx2, adler32_avx2, test_cpu_features.x86.has_avx2)
#endif
#ifdef X86_AVX512
-TEST_ADLER32(avx512, adler32_avx512, x86_cpu_has_avx512)
+TEST_ADLER32(avx512, adler32_avx512, test_cpu_features.x86.has_avx512)
#endif
#ifdef X86_AVX512VNNI
-TEST_ADLER32(avx512_vnni, adler32_avx512_vnni, x86_cpu_has_avx512vnni)
+TEST_ADLER32(avx512_vnni, adler32_avx512_vnni, test_cpu_features.x86.has_avx512vnni)
#endif
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
-# include "cpu_features.h"
+# include "test_cpu_features.h"
}
#include <gtest/gtest.h>
#endif
#endif
#if defined(X86_SSE2) && defined(HAVE_BUILTIN_CTZ)
-TEST_COMPARE256(sse2, compare256_sse2, x86_cpu_has_sse2)
+TEST_COMPARE256(sse2, compare256_sse2, test_cpu_features.x86.has_sse2)
#endif
#if defined(X86_AVX2) && defined(HAVE_BUILTIN_CTZ)
-TEST_COMPARE256(avx2, compare256_avx2, x86_cpu_has_avx2)
+TEST_COMPARE256(avx2, compare256_avx2, test_cpu_features.x86.has_avx2)
#endif
#if defined(ARM_NEON) && defined(HAVE_BUILTIN_CTZLL)
-TEST_COMPARE256(neon, compare256_neon, arm_cpu_has_neon)
+TEST_COMPARE256(neon, compare256_neon, test_cpu_features.arm.has_neon)
#endif
#ifdef POWER9
-TEST_COMPARE256(power9, compare256_power9, power_cpu_has_arch_3_00)
+TEST_COMPARE256(power9, compare256_power9, test_cpu_features.power.has_arch_3_00)
#endif
--- /dev/null
+#ifndef TEST_CPU_FEATURES_H
+#define TEST_CPU_FEATURES_H
+
+#include "cpu_features.h"
+
+extern struct cpu_features test_cpu_features;
+
+#endif
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
-# include "cpu_features.h"
+# include "test_cpu_features.h"
}
#include <gtest/gtest.h>
TEST_CRC32(braid, PREFIX(crc32_braid), 1)
#ifdef ARM_ACLE
-TEST_CRC32(acle, crc32_acle, arm_cpu_has_crc32)
+TEST_CRC32(acle, crc32_acle, test_cpu_features.arm.has_crc32)
#elif defined(POWER8_VSX_CRC32)
-TEST_CRC32(power8, crc32_power8, power_cpu_has_arch_2_07)
+TEST_CRC32(power8, crc32_power8, test_cpu_features.power.has_arch_2_07)
#elif defined(S390_CRC32_VX)
-TEST_CRC32(vx, PREFIX(s390_crc32_vx), PREFIX(s390_cpu_has_vx))
+TEST_CRC32(vx, crc32_s390_vx, test_cpu_features.s390.has_vx)
#elif defined(X86_PCLMULQDQ_CRC)
-TEST_CRC32(pclmulqdq, crc32_pclmulqdq, x86_cpu_has_pclmulqdq)
+TEST_CRC32(pclmulqdq, crc32_pclmulqdq, test_cpu_features.x86.has_pclmulqdq)
# ifdef X86_VPCLMULQDQ_CRC
-TEST_CRC32(vpclmulqdq, crc32_vpclmulqdq, (x86_cpu_has_pclmulqdq && x86_cpu_has_avx512 && x86_cpu_has_vpclmulqdq))
+TEST_CRC32(vpclmulqdq, crc32_vpclmulqdq, (test_cpu_features.x86.has_pclmulqdq && test_cpu_features.x86.has_avx512 && test_cpu_features.x86.has_vpclmulqdq))
# endif
#endif
extern "C" {
# include "zbuild.h"
-# include "cpu_features.h"
+# include "test_cpu_features.h"
+
+ struct cpu_features test_cpu_features;
}
GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from %s\n", __FILE__);
- cpu_check_features();
+ cpu_check_features(&test_cpu_features);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
-}
\ No newline at end of file
+}