Skip to content

Commit f234989

Browse files
authored
Add a benchmark for aarch64's __init_cpu_features_resolver() (#90)
1 parent 2a85cd9 commit f234989

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

SingleSource/Benchmarks/Misc/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(CheckSymbolExists)
2+
13
list(APPEND LDFLAGS -lm )
24
list(APPEND CFLAGS -Wno-implicit-int)
35
set(FP_TOLERANCE 0.001)
@@ -32,4 +34,11 @@ set(Source
3234
if(NOT ARCH STREQUAL "PowerPC" OR NOT TARGET_OS STREQUAL "Darwin")
3335
list(APPEND Source dt.c)
3436
endif()
37+
if(ARCH STREQUAL "AArch64")
38+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CheckHaveAArch64FMV.h "void __init_cpu_features_resolver(void);")
39+
check_symbol_exists(__init_cpu_features_resolver ${CMAKE_CURRENT_BINARY_DIR}/CheckHaveAArch64FMV.h HAVE_AARCH64_FMV)
40+
if(HAVE_AARCH64_FMV AND TARGET_OS STREQUAL "Darwin")
41+
list(APPEND Source aarch64-init-cpu-features.c)
42+
endif()
43+
endif()
3544
llvm_singlesource()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
3+
extern struct {
4+
unsigned long long features;
5+
} __aarch64_cpu_features;
6+
7+
void __init_cpu_features_resolver(void);
8+
9+
int main() {
10+
__init_cpu_features_resolver();
11+
const unsigned long long first = __aarch64_cpu_features.features;
12+
13+
// Manually reset it, so we can check that the result is consistent.
14+
__aarch64_cpu_features.features = 0;
15+
__init_cpu_features_resolver();
16+
17+
if (__aarch64_cpu_features.features != first) {
18+
printf("FAILED consistency test: 0x%llx != 0x%llx\n", first,
19+
__aarch64_cpu_features.features);
20+
return 1;
21+
}
22+
23+
// At 1,000,000 iterations, the reported exec_time doubles as a
24+
// per-iteration measurement in microseconds.
25+
for (int i = 0; i < 1000000; i++) {
26+
__aarch64_cpu_features.features = 0;
27+
__init_cpu_features_resolver();
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exit 0

SingleSource/UnitTests/AArch64/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
22
if(ARCH STREQUAL "AArch64")
33
set(Source )
44
# TODO: this test is currently only supported on Darwin platforms:
5-
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
5+
if (TARGET_OS MATCHES "Darwin")
66
list(APPEND Source acle-fmv-features.c)
77
endif()
8-
llvm_singlesource(PREFIX "aarch64-" Source)
8+
llvm_singlesource(PREFIX "aarch64-")
99
endif()
1010
endif()

0 commit comments

Comments
 (0)