Skip to content

Add a benchmark for aarch64's __init_cpu_features_resolver() #90

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 2 commits into from
Feb 12, 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
9 changes: 9 additions & 0 deletions SingleSource/Benchmarks/Misc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(CheckSymbolExists)

list(APPEND LDFLAGS -lm )
list(APPEND CFLAGS -Wno-implicit-int)
set(FP_TOLERANCE 0.001)
Expand Down Expand Up @@ -32,4 +34,11 @@ set(Source
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)
endif()
endif()
llvm_singlesource()
29 changes: 29 additions & 0 deletions SingleSource/Benchmarks/Misc/aarch64-init-cpu-features.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

extern struct {
unsigned long long features;
} __aarch64_cpu_features;

void __init_cpu_features_resolver(void);

int main() {
__init_cpu_features_resolver();
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();

if (__aarch64_cpu_features.features != first) {
printf("FAILED consistency test: 0x%llx != 0x%llx\n", first,
__aarch64_cpu_features.features);
return 1;
}

// At 1,000,000 iterations, the reported exec_time doubles as a
// per-iteration measurement in microseconds.
for (int i = 0; i < 1000000; i++) {
__aarch64_cpu_features.features = 0;
__init_cpu_features_resolver();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0
4 changes: 2 additions & 2 deletions SingleSource/UnitTests/AArch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(ARCH STREQUAL "AArch64")
set(Source )
# TODO: this test is currently only supported on Darwin platforms:
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (TARGET_OS MATCHES "Darwin")
list(APPEND Source acle-fmv-features.c)
endif()
llvm_singlesource(PREFIX "aarch64-" Source)
llvm_singlesource(PREFIX "aarch64-")
endif()
endif()