From d24d5dcdcbb748c52747823a0d3df20864fad600 Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Tue, 15 Oct 2024 10:22:12 +0100 Subject: [PATCH] [FMV][AArch64] Run the aarch64-init-cpu-features test on Linux. (#172) Currently we are only running this test on Darwin platforms. I had to adjust the runtime initialization routine because on Linux the dynamic loader will pass a HWCAP parameter to the ifunc resolver function, whereas on Darwin no arguments are passed. --- SingleSource/Benchmarks/Misc/CMakeLists.txt | 18 ++++++++++++++---- .../Misc/aarch64-init-cpu-features.c | 14 ++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/SingleSource/Benchmarks/Misc/CMakeLists.txt b/SingleSource/Benchmarks/Misc/CMakeLists.txt index a3dce54fa..30743459f 100644 --- a/SingleSource/Benchmarks/Misc/CMakeLists.txt +++ b/SingleSource/Benchmarks/Misc/CMakeLists.txt @@ -35,10 +35,20 @@ if(NOT ARCH STREQUAL "PowerPC" OR NOT TARGET_OS STREQUAL "Darwin") list(APPEND Source dt.c) endif() if(ARCH STREQUAL "AArch64") - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CheckHaveAArch64FMV.h "void __init_cpu_features_resolver(void);") - check_symbol_exists(__init_cpu_features_resolver ${CMAKE_CURRENT_BINARY_DIR}/CheckHaveAArch64FMV.h HAVE_AARCH64_FMV) - if(HAVE_AARCH64_FMV AND TARGET_OS STREQUAL "Darwin") - list(APPEND Source aarch64-init-cpu-features.c) + if(TARGET_OS STREQUAL "Darwin") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h "void __init_cpu_features_resolver(void);") + check_symbol_exists(__init_cpu_features_resolver ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h HAS_AARCH64_FMV) + if(HAS_AARCH64_FMV) + list(APPEND CFLAGS -DHAS_DARWIN_FMV) + list(APPEND Source aarch64-init-cpu-features.c) + endif() + elseif(TARGET_OS STREQUAL "Linux") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h "void __init_cpu_features(void);") + check_symbol_exists(__init_cpu_features ${CMAKE_CURRENT_BINARY_DIR}/CheckHasAArch64FMV.h HAS_AARCH64_FMV) + if(HAS_AARCH64_FMV) + list(APPEND CFLAGS -DHAS_LINUX_FMV) + list(APPEND Source aarch64-init-cpu-features.c) + endif() endif() endif() llvm_singlesource() diff --git a/SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.c b/SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.c index 6d6a3ee35..39c3f6683 100644 --- a/SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.c +++ b/SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.c @@ -4,15 +4,21 @@ extern struct { unsigned long long features; } __aarch64_cpu_features; -void __init_cpu_features_resolver(void); +#if HAS_DARWIN_FMV +# define RUNTIME_INIT __init_cpu_features_resolver +#elif HAS_LINUX_FMV +# define RUNTIME_INIT __init_cpu_features +#endif + +void RUNTIME_INIT(void); int main() { - __init_cpu_features_resolver(); + RUNTIME_INIT(); const unsigned long long first = __aarch64_cpu_features.features; // Manually reset it, so we can check that the result is consistent. __aarch64_cpu_features.features = 0; - __init_cpu_features_resolver(); + RUNTIME_INIT(); if (__aarch64_cpu_features.features != first) { printf("FAILED consistency test: 0x%llx != 0x%llx\n", first, @@ -24,6 +30,6 @@ int main() { // per-iteration measurement in microseconds. for (int i = 0; i < 1000000; i++) { __aarch64_cpu_features.features = 0; - __init_cpu_features_resolver(); + RUNTIME_INIT(); } }