Skip to content

[FMV][AArch64] Run the aarch64-init-cpu-features test on Linux. #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}