Commit 8ef80a62 authored by Richard Townsend's avatar Richard Townsend Committed by Commit Bot

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/+/1569929Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652187}
parent 1c7b996b
...@@ -78,7 +78,9 @@ if (use_arm_neon_optimizations) { ...@@ -78,7 +78,9 @@ if (use_arm_neon_optimizations) {
defines += [ "ARMV8_OS_LINUX" ] defines += [ "ARMV8_OS_LINUX" ]
} else if (is_fuchsia) { } else if (is_fuchsia) {
defines += [ "ARMV8_OS_FUCHSIA" ] defines += [ "ARMV8_OS_FUCHSIA" ]
} else if (!is_win) { } else if (is_win) {
defines += [ "ARMV8_OS_WINDOWS" ]
} else {
assert(false, "Unsupported ARM OS") assert(false, "Unsupported ARM OS")
} }
} }
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
#include "arm_features.h" #include "arm_features.h"
#include "zutil.h" #include "zutil.h"
#include <stdint.h>
int ZLIB_INTERNAL arm_cpu_enable_crc32 = 0; int ZLIB_INTERNAL arm_cpu_enable_crc32 = 0;
int ZLIB_INTERNAL arm_cpu_enable_pmull = 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 <pthread.h>
#include <stdint.h> #endif
#if defined(ARMV8_OS_ANDROID) #if defined(ARMV8_OS_ANDROID)
#include <cpu-features.h> #include <cpu-features.h>
...@@ -25,18 +25,33 @@ int ZLIB_INTERNAL arm_cpu_enable_pmull = 0; ...@@ -25,18 +25,33 @@ int ZLIB_INTERNAL arm_cpu_enable_pmull = 0;
#include <zircon/features.h> #include <zircon/features.h>
#include <zircon/syscalls.h> #include <zircon/syscalls.h>
#include <zircon/types.h> #include <zircon/types.h>
#elif defined(ARMV8_OS_WINDOWS)
#include <windows.h>
#else #else
#error arm_features.c ARM feature detection in not defined for your platform #error arm_features.c ARM feature detection in not defined for your platform
#endif #endif
static pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
static void _arm_check_features(void); 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) void ZLIB_INTERNAL arm_check_features(void)
{ {
pthread_once(&cpu_check_inited_once, _arm_check_features); 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 * See http://bit.ly/2CcoEsr for run-time detection of ARM features and also
...@@ -68,36 +83,8 @@ static void _arm_check_features(void) ...@@ -68,36 +83,8 @@ static void _arm_check_features(void)
return; /* Report nothing if ASIMD(NEON) is missing */ return; /* Report nothing if ASIMD(NEON) is missing */
arm_cpu_enable_crc32 = !!(features & ZX_ARM64_FEATURE_ISA_CRC32); arm_cpu_enable_crc32 = !!(features & ZX_ARM64_FEATURE_ISA_CRC32);
arm_cpu_enable_pmull = !!(features & ZX_ARM64_FEATURE_ISA_PMULL); 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 #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 */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment