Tidy and further integrate Arm feature detection for Windows
This CL integrates feature detection across the file so that similar
sections do similar things across all operating systems.
Bug: 810125
Change-Id: I066226be69453ada72fa67632d09567ce246a860
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569929
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#652187}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8ef80a6282ba32c909c8a4ca52c767c192f0a6bd
diff --git a/BUILD.gn b/BUILD.gn
index 8d54d2a..1a9cd3b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -78,7 +78,9 @@
defines += [ "ARMV8_OS_LINUX" ]
} else if (is_fuchsia) {
defines += [ "ARMV8_OS_FUCHSIA" ]
- } else if (!is_win) {
+ } else if (is_win) {
+ defines += [ "ARMV8_OS_WINDOWS" ]
+ } else {
assert(false, "Unsupported ARM OS")
}
}
diff --git a/arm_features.c b/arm_features.c
index 73aca42..f5641c3 100644
--- a/arm_features.c
+++ b/arm_features.c
@@ -7,14 +7,14 @@
#include "arm_features.h"
#include "zutil.h"
+#include <stdint.h>
int ZLIB_INTERNAL arm_cpu_enable_crc32 = 0;
int ZLIB_INTERNAL arm_cpu_enable_pmull = 0;
-#if !defined(_MSC_VER)
-
+#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA)
#include <pthread.h>
-#include <stdint.h>
+#endif
#if defined(ARMV8_OS_ANDROID)
#include <cpu-features.h>
@@ -25,18 +25,33 @@
#include <zircon/features.h>
#include <zircon/syscalls.h>
#include <zircon/types.h>
+#elif defined(ARMV8_OS_WINDOWS)
+#include <windows.h>
#else
#error arm_features.c ARM feature detection in not defined for your platform
#endif
-static pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
-
static void _arm_check_features(void);
+#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA)
+static pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
void ZLIB_INTERNAL arm_check_features(void)
{
pthread_once(&cpu_check_inited_once, _arm_check_features);
}
+#elif defined(ARMV8_OS_WINDOWS)
+static INIT_ONCE cpu_check_inited_once = INIT_ONCE_STATIC_INIT;
+static BOOL CALLBACK _arm_check_features_forwarder(PINIT_ONCE once, PVOID param, PVOID* context)
+{
+ _arm_check_features();
+ return TRUE;
+}
+void ZLIB_INTERNAL arm_check_features(void)
+{
+ InitOnceExecuteOnce(&cpu_check_inited_once, _arm_check_features_forwarder,
+ NULL, NULL);
+}
+#endif
/*
* See http://bit.ly/2CcoEsr for run-time detection of ARM features and also
@@ -68,36 +83,8 @@
return; /* Report nothing if ASIMD(NEON) is missing */
arm_cpu_enable_crc32 = !!(features & ZX_ARM64_FEATURE_ISA_CRC32);
arm_cpu_enable_pmull = !!(features & ZX_ARM64_FEATURE_ISA_PMULL);
+#elif defined(ARMV8_OS_WINDOWS)
+ arm_cpu_enable_crc32 = IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
+ arm_cpu_enable_pmull = IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
#endif
}
-
-#else /* _MSC_VER */
-
-#include <windows.h>
-
-static INIT_ONCE cpu_check_inited_once = INIT_ONCE_STATIC_INIT;
-
-static BOOL CALLBACK _arm_check_features(PINIT_ONCE once,
- PVOID param,
- PVOID *context);
-
-void ZLIB_INTERNAL arm_check_features(void)
-{
- InitOnceExecuteOnce(&cpu_check_inited_once, _arm_check_features,
- NULL, NULL);
-}
-
-static BOOL CALLBACK _arm_check_features(PINIT_ONCE once,
- PVOID param,
- PVOID *context)
-{
- if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE))
- arm_cpu_enable_crc32 = 1;
-
- if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE))
- arm_cpu_enable_pmull = 1;
-
- return TRUE;
-}
-
-#endif /* _MSC_VER */