mirror of
https://github.com/google/cpu_features.git
synced 2025-07-01 13:21:13 +02:00
Add OpenBSD Arm64 support (#367)
This commit is contained in:
11
BUILD.bazel
11
BUILD.bazel
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||||
load("//:bazel/platforms.bzl", "PLATFORM_CPU_ARM", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_MIPS", "PLATFORM_CPU_PPC", "PLATFORM_CPU_RISCV32", "PLATFORM_CPU_RISCV64", "PLATFORM_CPU_X86_64")
|
load("//:bazel/platforms.bzl", "PLATFORM_CPU_ARM", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_MIPS", "PLATFORM_CPU_PPC", "PLATFORM_CPU_RISCV32", "PLATFORM_CPU_RISCV64", "PLATFORM_CPU_X86_64")
|
||||||
load("//:bazel/platforms.bzl", "PLATFORM_OS_MACOS", "PLATFORM_OS_LINUX", "PLATFORM_OS_FREEBSD", "PLATFORM_OS_ANDROID")
|
load("//:bazel/platforms.bzl", "PLATFORM_OS_MACOS", "PLATFORM_OS_LINUX", "PLATFORM_OS_FREEBSD", "PLATFORM_OS_OPENBSD", "PLATFORM_OS_ANDROID")
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
@ -170,13 +170,14 @@ cc_library(
|
|||||||
name = "hwcaps",
|
name = "hwcaps",
|
||||||
srcs = [
|
srcs = [
|
||||||
"src/hwcaps.c",
|
"src/hwcaps.c",
|
||||||
"src/hwcaps_freebsd.c",
|
"src/hwcaps_freebsd_or_openbsd.c",
|
||||||
"src/hwcaps_linux_or_android.c",
|
"src/hwcaps_linux_or_android.c",
|
||||||
],
|
],
|
||||||
copts = C99_FLAGS,
|
copts = C99_FLAGS,
|
||||||
defines = selects.with_or({
|
defines = selects.with_or({
|
||||||
PLATFORM_OS_MACOS: ["HAVE_DLFCN_H"],
|
PLATFORM_OS_MACOS: ["HAVE_DLFCN_H"],
|
||||||
PLATFORM_OS_FREEBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
|
PLATFORM_OS_FREEBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
|
||||||
|
PLATFORM_OS_OPENBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
|
||||||
PLATFORM_OS_LINUX: ["HAVE_STRONG_GETAUXVAL"],
|
PLATFORM_OS_LINUX: ["HAVE_STRONG_GETAUXVAL"],
|
||||||
PLATFORM_OS_ANDROID: ["HAVE_STRONG_GETAUXVAL"],
|
PLATFORM_OS_ANDROID: ["HAVE_STRONG_GETAUXVAL"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
@ -195,7 +196,7 @@ cc_library(
|
|||||||
testonly = 1,
|
testonly = 1,
|
||||||
srcs = [
|
srcs = [
|
||||||
"src/hwcaps.c",
|
"src/hwcaps.c",
|
||||||
"src/hwcaps_freebsd.c",
|
"src/hwcaps_freebsd_or_openbsd.c",
|
||||||
"src/hwcaps_linux_or_android.c",
|
"src/hwcaps_linux_or_android.c",
|
||||||
"test/hwcaps_for_testing.cc",
|
"test/hwcaps_for_testing.cc",
|
||||||
],
|
],
|
||||||
@ -230,7 +231,7 @@ cc_library(
|
|||||||
"src/impl_aarch64_linux_or_android.c",
|
"src/impl_aarch64_linux_or_android.c",
|
||||||
"src/impl_aarch64_macos_or_iphone.c",
|
"src/impl_aarch64_macos_or_iphone.c",
|
||||||
"src/impl_aarch64_windows.c",
|
"src/impl_aarch64_windows.c",
|
||||||
"src/impl_aarch64_freebsd.c",
|
"src/impl_aarch64_freebsd_or_openbsd.c",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
|
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
|
||||||
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
|
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
|
||||||
@ -295,7 +296,7 @@ cc_library(
|
|||||||
"src/impl_aarch64_linux_or_android.c",
|
"src/impl_aarch64_linux_or_android.c",
|
||||||
"src/impl_aarch64_macos_or_iphone.c",
|
"src/impl_aarch64_macos_or_iphone.c",
|
||||||
"src/impl_aarch64_windows.c",
|
"src/impl_aarch64_windows.c",
|
||||||
"src/impl_aarch64_freebsd.c",
|
"src/impl_aarch64_freebsd_or_openbsd.c",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
|
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
|
||||||
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
|
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
|
||||||
|
@ -148,7 +148,7 @@ if(UNIX)
|
|||||||
add_library(unix_based_hardware_detection OBJECT
|
add_library(unix_based_hardware_detection OBJECT
|
||||||
${PROJECT_SOURCE_DIR}/include/internal/hwcaps.h
|
${PROJECT_SOURCE_DIR}/include/internal/hwcaps.h
|
||||||
${PROJECT_SOURCE_DIR}/src/hwcaps_linux_or_android.c
|
${PROJECT_SOURCE_DIR}/src/hwcaps_linux_or_android.c
|
||||||
${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd.c
|
${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd_or_openbsd.c
|
||||||
${PROJECT_SOURCE_DIR}/src/hwcaps.c
|
${PROJECT_SOURCE_DIR}/src/hwcaps.c
|
||||||
)
|
)
|
||||||
setup_include_and_definitions(unix_based_hardware_detection)
|
setup_include_and_definitions(unix_based_hardware_detection)
|
||||||
|
@ -22,3 +22,5 @@ PLATFORM_OS_LINUX = ("@platforms//os:linux")
|
|||||||
PLATFORM_OS_ANDROID = ("@platforms//os:android")
|
PLATFORM_OS_ANDROID = ("@platforms//os:android")
|
||||||
|
|
||||||
PLATFORM_OS_FREEBSD = ("@platforms//os:freebsd")
|
PLATFORM_OS_FREEBSD = ("@platforms//os:freebsd")
|
||||||
|
|
||||||
|
PLATFORM_OS_OPENBSD = ("@platforms//os:openbsd")
|
||||||
|
@ -95,6 +95,10 @@
|
|||||||
#define CPU_FEATURES_OS_FREEBSD
|
#define CPU_FEATURES_OS_FREEBSD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__OpenBSD__)
|
||||||
|
#define CPU_FEATURES_OS_OPENBSD
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define CPU_FEATURES_OS_ANDROID
|
#define CPU_FEATURES_OS_ANDROID
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "cpu_features_macros.h"
|
#include "cpu_features_macros.h"
|
||||||
|
|
||||||
#ifdef CPU_FEATURES_OS_FREEBSD
|
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
|
||||||
|
|
||||||
#include "internal/hwcaps.h"
|
#include "internal/hwcaps.h"
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ const char *CpuFeatures_GetPlatformPointer(void) { return NULL; }
|
|||||||
const char *CpuFeatures_GetBasePlatformPointer(void) { return NULL; }
|
const char *CpuFeatures_GetBasePlatformPointer(void) { return NULL; }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error "FreeBSD needs support for elf_aux_info"
|
#error "FreeBSD / OpenBSD needs support for elf_aux_info"
|
||||||
#endif // HAVE_STRONG_ELF_AUX_INFO
|
#endif // HAVE_STRONG_ELF_AUX_INFO
|
||||||
|
|
||||||
#endif // CPU_FEATURES_TEST
|
#endif // CPU_FEATURES_TEST
|
||||||
#endif // CPU_FEATURES_OS_FREEBSD
|
#endif // CPU_FEATURES_OS_FREEBSD || CPU_FEATURES_OS_OPENBSD
|
@ -15,8 +15,8 @@
|
|||||||
#include "cpu_features_macros.h"
|
#include "cpu_features_macros.h"
|
||||||
|
|
||||||
#ifdef CPU_FEATURES_ARCH_AARCH64
|
#ifdef CPU_FEATURES_ARCH_AARCH64
|
||||||
#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) || \
|
#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || \
|
||||||
defined(CPU_FEATURES_OS_ANDROID))
|
defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID))
|
||||||
#if (defined(CPU_FEATURES_COMPILER_GCC) || defined(CPU_FEATURES_COMPILER_CLANG))
|
#if (defined(CPU_FEATURES_COMPILER_GCC) || defined(CPU_FEATURES_COMPILER_CLANG))
|
||||||
|
|
||||||
#include "internal/cpuid_aarch64.h"
|
#include "internal/cpuid_aarch64.h"
|
||||||
@ -35,6 +35,6 @@ uint64_t GetMidrEl1(void) {
|
|||||||
#error "Unsupported compiler, aarch64 cpuid requires either GCC or Clang."
|
#error "Unsupported compiler, aarch64 cpuid requires either GCC or Clang."
|
||||||
#endif // (defined(CPU_FEATURES_COMPILER_GCC) ||
|
#endif // (defined(CPU_FEATURES_COMPILER_GCC) ||
|
||||||
// defined(CPU_FEATURES_COMPILER_CLANG))
|
// defined(CPU_FEATURES_COMPILER_CLANG))
|
||||||
#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
|
#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
|
||||||
// || defined(CPU_FEATURES_OS_ANDROID))
|
// || defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID))
|
||||||
#endif // CPU_FEATURES_ARCH_AARCH64
|
#endif // CPU_FEATURES_ARCH_AARCH64
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#include "cpu_features_macros.h"
|
#include "cpu_features_macros.h"
|
||||||
|
|
||||||
#ifdef CPU_FEATURES_ARCH_AARCH64
|
#ifdef CPU_FEATURES_ARCH_AARCH64
|
||||||
#ifdef CPU_FEATURES_OS_FREEBSD
|
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
|
||||||
|
|
||||||
#include "cpuinfo_aarch64.h"
|
#include "cpuinfo_aarch64.h"
|
||||||
#include "impl_aarch64__base_implementation.inl"
|
#include "impl_aarch64__base_implementation.inl"
|
||||||
@ -42,5 +42,5 @@ Aarch64Info GetAarch64Info(void) {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CPU_FEATURES_OS_FREEBSD
|
#endif // CPU_FEATURES_OS_FREEBSD || CPU_FEATURES_OS_OPENBSD
|
||||||
#endif // CPU_FEATURES_ARCH_AARCH64
|
#endif // CPU_FEATURES_ARCH_AARCH64
|
@ -25,7 +25,7 @@ target_link_libraries(stack_line_reader_for_test string_view filesystem_for_test
|
|||||||
add_library(all_libraries
|
add_library(all_libraries
|
||||||
../src/hwcaps.c
|
../src/hwcaps.c
|
||||||
../src/hwcaps_linux_or_android.c
|
../src/hwcaps_linux_or_android.c
|
||||||
../src/hwcaps_freebsd.c
|
../src/hwcaps_freebsd_or_openbsd.c
|
||||||
../src/stack_line_reader.c)
|
../src/stack_line_reader.c)
|
||||||
target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view)
|
target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view)
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ if(PROCESSOR_IS_AARCH64)
|
|||||||
../src/impl_aarch64_linux_or_android.c
|
../src/impl_aarch64_linux_or_android.c
|
||||||
../src/impl_aarch64_windows.c
|
../src/impl_aarch64_windows.c
|
||||||
../src/impl_aarch64_macos_or_iphone.c
|
../src/impl_aarch64_macos_or_iphone.c
|
||||||
../src/impl_aarch64_freebsd.c
|
../src/impl_aarch64_freebsd_or_openbsd.c
|
||||||
)
|
)
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_SYSCTL_AARCH64)
|
target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_SYSCTL_AARCH64)
|
||||||
|
@ -22,13 +22,13 @@
|
|||||||
#if defined(CPU_FEATURES_OS_WINDOWS)
|
#if defined(CPU_FEATURES_OS_WINDOWS)
|
||||||
#include "internal/windows_utils.h"
|
#include "internal/windows_utils.h"
|
||||||
#endif // CPU_FEATURES_OS_WINDOWS
|
#endif // CPU_FEATURES_OS_WINDOWS
|
||||||
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
|
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
|
||||||
#include "internal/cpuid_aarch64.h"
|
#include "internal/cpuid_aarch64.h"
|
||||||
#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
|
#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
|
||||||
|
|
||||||
namespace cpu_features {
|
namespace cpu_features {
|
||||||
class FakeCpuAarch64 {
|
class FakeCpuAarch64 {
|
||||||
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
|
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
|
||||||
public:
|
public:
|
||||||
uint64_t GetMidrEl1() const { return _midr_el1; }
|
uint64_t GetMidrEl1() const { return _midr_el1; }
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ static FakeCpuAarch64& cpu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Define OS dependent mock functions
|
// Define OS dependent mock functions
|
||||||
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
|
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
|
||||||
extern "C" uint64_t GetMidrEl1(void) { return cpu().GetMidrEl1(); }
|
extern "C" uint64_t GetMidrEl1(void) { return cpu().GetMidrEl1(); }
|
||||||
#elif defined(CPU_FEATURES_OS_MACOS)
|
#elif defined(CPU_FEATURES_OS_MACOS)
|
||||||
extern "C" bool GetDarwinSysCtlByName(const char* name) {
|
extern "C" bool GetDarwinSysCtlByName(const char* name) {
|
||||||
@ -137,7 +137,7 @@ TEST_F(CpuidAarch64Test, Aarch64FeaturesEnum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AT_HWCAP tests
|
// AT_HWCAP tests
|
||||||
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD)
|
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
|
||||||
TEST_F(CpuidAarch64Test, FromHardwareCap) {
|
TEST_F(CpuidAarch64Test, FromHardwareCap) {
|
||||||
ResetHwcaps();
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
|
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
|
||||||
@ -205,7 +205,7 @@ TEST_F(CpuidAarch64Test, FromHardwareCap2) {
|
|||||||
EXPECT_FALSE(info.features.dgh);
|
EXPECT_FALSE(info.features.dgh);
|
||||||
EXPECT_FALSE(info.features.rng);
|
EXPECT_FALSE(info.features.rng);
|
||||||
}
|
}
|
||||||
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD)
|
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
|
||||||
|
|
||||||
// OS dependent tests
|
// OS dependent tests
|
||||||
#if defined(CPU_FEATURES_OS_LINUX)
|
#if defined(CPU_FEATURES_OS_LINUX)
|
||||||
@ -415,7 +415,7 @@ TEST_F(CpuidAarch64Test, WINDOWS_AARCH64_RPI4) {
|
|||||||
EXPECT_FALSE(info.features.jscvt);
|
EXPECT_FALSE(info.features.jscvt);
|
||||||
EXPECT_FALSE(info.features.lrcpc);
|
EXPECT_FALSE(info.features.lrcpc);
|
||||||
}
|
}
|
||||||
#elif defined(CPU_FEATURES_OS_FREEBSD)
|
#elif defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
|
||||||
TEST_F(CpuidAarch64Test, MrsMidrEl1_RPI4) {
|
TEST_F(CpuidAarch64Test, MrsMidrEl1_RPI4) {
|
||||||
ResetHwcaps();
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_CPUID, 0);
|
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_CPUID, 0);
|
||||||
|
Reference in New Issue
Block a user