Skip to content

Commit 4b0ee65

Browse files
committed
outline-atomics
1 parent b5e0e80 commit 4b0ee65

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ if (${MAGNETRON_BUILD_BENCHMARKS})
6868
add_subdirectory(benchmark)
6969
endif()
7070

71+
message(STATUS "C Compiler: ${CMAKE_C_COMPILER}")
72+
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")
73+
get_target_property(MAIN_CFLAGS magnetron COMPILE_OPTIONS)
74+
message(STATUS "Compilation flags: ${MAIN_CFLAGS}")
75+
76+
message(STATUS "Configuring magnetron project for ${CMAKE_SYSTEM_PROCESSOR}... done")

cmake/allocator.cmake

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ option(MI_OVERRIDE "" OFF)
77
option(MI_OSX_INTERPOSE "" OFF)
88
option(MI_OSX_ZONE "" OFF)
99
option(MI_WIN_REDIRECT "" OFF)
10-
option(MI_NO_USE_CXX "" ON)
11-
option(MI_NO_OPT_ARCH "" ON)
10+
option(MI_OPT_ARCH "" OFF)
1211
add_subdirectory(extern/mimalloc)
1312
target_compile_definitions(magnetron PRIVATE MAGNETRON_USE_MIMALLOC)
1413
target_link_libraries(magnetron mimalloc-static)
14+
15+
if (${IS_ARM64})
16+
if (NOT WIN32)
17+
target_compile_options(mimalloc-static PRIVATE -moutline-atomics)
18+
endif()
19+
endif()
20+
21+
get_target_property(MAIN_CFLAGS mimalloc-static COMPILE_OPTIONS)
22+
message(STATUS "Compilation flags: ${MAIN_CFLAGS}")

cmake/compiler_config.cmake

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# (c) 2025 Mario "Neo" Sieg. <[email protected]>
22

3+
#[===[
4+
5+
-moutline-atomics
6+
Outline-atomics is a gcc compilation flag that adds runtime detection on if the cpu supports atomic instructions.
7+
Some older ARM CPU's such as the chip on the Raspberry PI 4 don't support atomic instructions. Using them will result in a SIGILL.
8+
When the outline-atomics flag is used, the compiler will generate code that checks if the CPU supports atomic instructions at runtime.
9+
CPUs that don't support atomic instructions will use the old load-exclusive/store-exclusive instructions.
10+
If a different compilation flag defined an architecture that unconditionally supports atomic instructions (e.g. -march=armv8.2), the outline-atomic flag will have no effect.
11+
]===]
12+
313
message("Configuring magnetron project for ${CMAKE_SYSTEM_PROCESSOR}...")
414
message("C compiler: ${CMAKE_C_COMPILER_ID}")
515

@@ -55,8 +65,11 @@ set(MAG_GCC_LINK_OPTIONS "")
5565
set(MAG_GCC_RELEASE_LINK_OPTIONS -flto=auto)
5666

5767
if (${IS_ARM64})
58-
set(MAG_CLANG_COMPILE_FLAGS ${MAG_CLANG_COMPILE_FLAGS} -march=armv8-a)
59-
set(MAG_GCC_COMPILE_FLAGS ${MAG_CLANG_COMPILE_FLAGS} -march=armv8-a)
68+
if (NOT WIN32)
69+
add_compile_options(-moutline-atomics)
70+
endif()
71+
set(MAG_CLANG_COMPILE_FLAGS ${MAG_CLANG_COMPILE_FLAGS} -march=armv8-a -moutline-atomics) # See beginning for file for info of -moutline-atomics
72+
set(MAG_GCC_COMPILE_FLAGS ${MAG_CLANG_COMPILE_FLAGS} -march=armv8-a -moutline-atomics)
6073
elseif (${IS_AMD64})
6174
set(MAG_CLANG_COMPILE_FLAGS ${MAG_CLANG_COMPILE_FLAGS} -msse -msse2)
6275
set(MAG_GCC_COMPILE_FLAGS ${MAG_CLANG_COMPILE_FLAGS} -msse -msse2)

0 commit comments

Comments
 (0)