]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Replace global CPU feature flag variables with local variable in init_functable
authorVladislav Shchapov <vladislav@shchapov.ru>
Sat, 18 Feb 2023 16:25:55 +0000 (21:25 +0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Mon, 6 Mar 2023 12:26:09 +0000 (13:26 +0100)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
25 files changed:
arch/arm/arm_features.c
arch/arm/arm_features.h
arch/power/power_features.c
arch/power/power_features.h
arch/s390/crc32-vx.c
arch/s390/s390_features.c
arch/s390/s390_features.h
arch/x86/x86_features.c
arch/x86/x86_features.h
cpu_features.c
cpu_features.h
deflate.c
functable.c
inflate.c
test/benchmarks/benchmark_adler32.cc
test/benchmarks/benchmark_adler32_copy.cc
test/benchmarks/benchmark_compare256.cc
test/benchmarks/benchmark_crc32.cc
test/benchmarks/benchmark_main.cc
test/benchmarks/benchmark_slidehash.cc
test/test_adler32.cc
test/test_compare256.cc
test/test_cpu_features.h [new file with mode: 0644]
test/test_crc32.cc
test/test_main.cc

index d41c13acb074db1814a8bdd293472d1556def955..7394351fa1adae002ea1dfe9f7c31fd10ce49139 100644 (file)
@@ -1,4 +1,5 @@
 #include "../../zbuild.h"
+#include "arm_features.h"
 
 #if defined(__linux__) && defined(HAVE_SYS_AUXV_H)
 #  include <sys/auxv.h>
@@ -71,14 +72,11 @@ static inline int arm_has_neon() {
 }
 #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();
 }
index 7998e7942244a8af7510bb424b91225f82f464d2..6fcd8d3eb52b68f3f74eabb8c5c3aabbd870f0cb 100644 (file)
@@ -5,9 +5,11 @@
 #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_ */
index 0614ff0f25f9da3cf70aee365f988d1ec5597681..003a4c6e3cae44a5ece3bff8100c8b6c41c1bd33 100644 (file)
 #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__
@@ -27,7 +23,7 @@ void Z_INTERNAL power_check_features(void) {
 #endif
 
     if (hwcap & PPC_FEATURE_HAS_ALTIVEC)
-        power_cpu_has_altivec = 1;
+        features->has_altivec = 1;
 #endif
 
 #ifdef POWER_FEATURES
@@ -39,8 +35,8 @@ void Z_INTERNAL power_check_features(void) {
 #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
 }
index 8df9f9e958266f55894cd579dc67cbb492cfe7e1..9252364cc48d2f21996acf9affb14907cbdfd7f3 100644 (file)
@@ -7,10 +7,12 @@
 #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_ */
index 78c0be5ceef3aa793fe6469dd7e63adbfee8a9af..acfa21887e975b1e32cce97fd4a9fc25b4a3b528 100644 (file)
@@ -198,7 +198,7 @@ static uint32_t crc32_le_vgfm_16(uint32_t crc, const uint8_t *buf, size_t len) {
 #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)
index 0658e4bbeb2ebdc4f3366b8f0763f784d44933ae..711b7dd46083d7ed44aba927f35d652a84a44773 100644 (file)
@@ -5,10 +5,6 @@
 #  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;
 }
index 9e2608fa9e151edbe4b7930d3dbf9abb6080db7d..b8ffef74d8441e38ffe531af84517dadb158c3a6 100644 (file)
@@ -1,8 +1,10 @@
 #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
index 2c5cb54c656c95c96e6d7b31c6d14566c0745c17..4ff7f63ee8fe99e19e5ac6a7f76550b6c5e9865f 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #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];
@@ -68,27 +57,27 @@ static inline uint64_t xgetbv(unsigned int xcr) {
 #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) {
@@ -96,27 +85,27 @@ void Z_INTERNAL x86_check_features(void) {
 
         // 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;
     }
 }
index 06677b2e12f9cafd9815fac091ee626d9b57c3d3..00b510ffc1171547687b23ec001b00be763624af 100644 (file)
@@ -6,18 +6,20 @@
 #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_ */
index b5e72576962d898fed8f1b67396ea641af7ad646..b69a01304a706dd47e83d129f992e4dd4d247e3e 100644 (file)
@@ -4,21 +4,18 @@
  */
 
 #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;
 }
index 22d70da3d926db79364813df8e52d27e21425311..14eb19a751023d632922009f11db070db741fe81 100644 (file)
 #  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);
@@ -134,7 +146,7 @@ extern uint32_t crc32_acle(uint32_t crc, 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 */
index 273967b4263223e26e478cc023e56f50775a51c2..3ea92a82dd3b0ffae01d564cb29fa263f3f1fb28 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -48,7 +48,6 @@
  */
 
 #include "zbuild.h"
-#include "cpu_features.h"
 #include "deflate.h"
 #include "deflate_p.h"
 #include "functable.h"
@@ -195,8 +194,6 @@ int32_t ZNG_CONDEXPORT PREFIX(deflateInit2)(PREFIX3(stream) *strm, int32_t level
     deflate_state *s;
     int wrap = 1;
 
-    cpu_check_features();
-
     if (strm == NULL)
         return Z_STREAM_ERROR;
 
index da9d10ec5bd9aa4beb49106f858fa3789fd4d59f..c7d477c7f066a2934a05e91b019f04651d450731 100644 (file)
@@ -13,8 +13,9 @@
 
 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;
@@ -58,7 +59,7 @@ static void init_functable(void) {
     // 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;
@@ -74,18 +75,18 @@ static void init_functable(void) {
 #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;
@@ -94,7 +95,7 @@ static void init_functable(void) {
 #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;
@@ -104,7 +105,7 @@ static void init_functable(void) {
 #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;
@@ -119,20 +120,20 @@ static void init_functable(void) {
     }
 #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;
@@ -145,7 +146,7 @@ static void init_functable(void) {
     // ARM - NEON
 #ifdef ARM_NEON
 #  ifndef ARM_NOCHECK_NEON
-    if (arm_cpu_has_neon)
+    if (cf.arm.has_neon)
 #  endif
     {
         ft.adler32 = &adler32_neon;
@@ -162,7 +163,7 @@ static void init_functable(void) {
 #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;
@@ -173,14 +174,14 @@ static void init_functable(void) {
 
     // 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;
@@ -189,12 +190,12 @@ static void init_functable(void) {
     }
 #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;
@@ -204,8 +205,8 @@ static void init_functable(void) {
 
     // 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
index 506bb2a50a2c1dbd086c01aa645de7df1d791a78..df4c56a168d1805a813bf85377c5a4e4bf04d8a2 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -5,7 +5,6 @@
 
 #include "zbuild.h"
 #include "zutil.h"
-#include "cpu_features.h"
 #include "inftrees.h"
 #include "inflate.h"
 #include "inflate_p.h"
@@ -140,8 +139,6 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateInit2)(PREFIX3(stream) *strm, int32_t windo
     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 */
index 19691376fbb1eef7ec6fb91a26f2a740746693e1..5b0b65d67b2f98f4401ad3ae94103ed6ae25de75 100644 (file)
@@ -11,7 +11,7 @@
 extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
-#  include "cpu_features.h"
+#  include "../test_cpu_features.h"
 }
 
 #define MAX_RANDOM_INTS (1024 * 1024)
@@ -65,25 +65,25 @@ public:
 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
index d508a004aac03ae0e63903e3b96794ce138c9be7..cbee780b764063ce4e264f00e51a3f7e02959ee5 100644 (file)
@@ -12,7 +12,7 @@
 extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
-#  include "cpu_features.h"
+#  include "../test_cpu_features.h"
 }
 
 #define MAX_RANDOM_INTS (1024 * 1024)
@@ -87,32 +87,32 @@ BENCHMARK_ADLER32_BASELINE_COPY(c, adler32_c, 1);
 
 #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
index 54f6b14b84d3b4750615517e731c747dd6bfb8bb..00c6cc6f63ca9fcf9b8d8c142a9f450bdb8090b5 100644 (file)
@@ -10,7 +10,7 @@
 extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
-#  include "cpu_features.h"
+#  include "../test_cpu_features.h"
 }
 
 #define MAX_COMPARE_SIZE (256)
@@ -71,14 +71,14 @@ BENCHMARK_COMPARE256(unaligned_64, compare256_unaligned_64, 1);
 #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
index b5ecda517954c8f7c57888f6cd16341f5a0a059e..b2b9673d9f013ba8a44fa190849579ac92edade2 100644 (file)
@@ -11,7 +11,7 @@
 extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
-#  include "cpu_features.h"
+#  include "../test_cpu_features.h"
 }
 
 #define MAX_RANDOM_INTS (1024 * 1024)
@@ -58,12 +58,12 @@ public:
 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
index ee8b6148973eb57a51db53cb0366606c24fe5054..3ef2c5e87d107c6358bc8c6a3089400312b33ef2 100644 (file)
 #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);
index 5ffa7039d0ee05f4889cb1e564c2c88431f6b1a0..238cc1f6585bdf7a0b3197058fc96c17ac7e661c 100644 (file)
@@ -11,7 +11,7 @@ extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
 #  include "deflate.h"
-#  include "cpu_features.h"
+#  include "../test_cpu_features.h"
 }
 
 #define MAX_RANDOM_INTS 32768
@@ -69,18 +69,18 @@ public:
 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
index 7f88f255654fca5cb53feb542f1f91993754253a..4dfe63f203a4d765ef0a7fb492b84b0fa800b9d9 100644 (file)
@@ -10,7 +10,7 @@
 
 extern "C" {
 #  include "zbuild.h"
-#  include "cpu_features.h"
+#  include "test_cpu_features.h"
 }
 
 #include <gtest/gtest.h>
@@ -365,22 +365,22 @@ INSTANTIATE_TEST_SUITE_P(adler32, adler32_variant, testing::ValuesIn(tests));
 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
index 663ad96334b5ec5b5909eed9a225904836bbced3..f920d1d205325bd16ff0d361c239d6dbd141c74a 100644 (file)
@@ -10,7 +10,7 @@
 extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
-#  include "cpu_features.h"
+#  include "test_cpu_features.h"
 }
 
 #include <gtest/gtest.h>
@@ -70,14 +70,14 @@ TEST_COMPARE256(unaligned_64, compare256_unaligned_64, 1)
 #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
diff --git a/test/test_cpu_features.h b/test/test_cpu_features.h
new file mode 100644 (file)
index 0000000..1bb4b13
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef TEST_CPU_FEATURES_H
+#define TEST_CPU_FEATURES_H
+
+#include "cpu_features.h"
+
+extern struct cpu_features test_cpu_features;
+
+#endif
index 4d0b5b966afc124fc5e95fce814395d0c601abe0..f194b4ccf57a6d311cd328b159ba8526ff536bf2 100644 (file)
@@ -12,7 +12,7 @@
 extern "C" {
 #  include "zbuild.h"
 #  include "zutil_p.h"
-#  include "cpu_features.h"
+#  include "test_cpu_features.h"
 }
 
 #include <gtest/gtest.h>
@@ -209,14 +209,14 @@ INSTANTIATE_TEST_SUITE_P(crc32, crc32_variant, testing::ValuesIn(tests));
 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
index c129db259ff0bb46fa425440df7d705a117fc872..82b39e48748f03c972b4b74cf102eb62c019c76a 100644 (file)
@@ -6,12 +6,14 @@
 
 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
+}