Skip to content

Commit

Permalink
[FMV][AArch64] Run the aarch64-init-cpu-features test on Linux. (#172)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
labrinea authored Oct 15, 2024
1 parent f5baaae commit d24d5dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 14 additions & 4 deletions SingleSource/Benchmarks/Misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
14 changes: 10 additions & 4 deletions SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
}
}

0 comments on commit d24d5dc

Please sign in to comment.