File tree Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,8 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
12
12
add_compile_options (-fcolor-diagnostics )
13
13
endif ()
14
14
15
- # Assume skylake for some easy performance wins
16
- if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
17
- add_compile_options (-march=skylake -mtune=skylake )
18
- endif ()
15
+ # Optimise for CPU
16
+ include (cmake/OptimiseCPU.cmake )
19
17
20
18
# Top-level CMake config
21
19
set (CMAKE_CXX_FLAGS "-Wall" )
Original file line number Diff line number Diff line change
1
+ set (CPU_VENDOR )
2
+ set (CPU_FAMILY )
3
+ set (CPU_MODEL )
4
+ set (CPU_PROPS )
5
+
6
+ file (READ "/proc/cpuinfo" _cpuinfo )
7
+ string (REGEX REPLACE ".*vendor_id[ \t ]*:[ \t ]+([a-zA-Z0-9_-]+).*" "\\ 1"
8
+ CPU_VENDOR "${_cpuinfo} " )
9
+ string (REGEX REPLACE ".*cpu family[ \t ]*:[ \t ]+([a-zA-Z0-9_-]+).*" "\\ 1"
10
+ CPU_FAMILY "${_cpuinfo} " )
11
+ string (REGEX REPLACE ".*model[ \t ]*:[ \t ]+([a-zA-Z0-9_-]+).*" "\\ 1"
12
+ CPU_MODEL "${_cpuinfo} " )
13
+ string (REGEX REPLACE ".*flags[ \t ]*:[ \t ]+([^\n ]+).*" "\\ 1"
14
+ CPU_PROPS "${_cpuinfo} " )
15
+
16
+ message ("Found CPU: Vendor = ${CPU_VENDOR} Family = ${CPU_FAMILY} Model = ${CPU_MODEL} Props = ${CPU_PROPS} " )
17
+
18
+ # See this file for an example of extending this list:
19
+ # https://github.com/VcDevel/Vc/blob/1.4/cmake/OptimizeForArchitecture.cmake
20
+ # See the LLVM source for list of supported arch, e.g. this test:
21
+ # https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/x86-march.c
22
+
23
+ set (CPU_COMPILE_FLAGS )
24
+ if (CPU_VENDOR STREQUAL "GenuineIntel" )
25
+ if (CPU_FAMILY EQUAL 6 )
26
+ if (CPU_MODEL EQUAL 78 OR CPU_MODEL EQUAL 94 )
27
+ # Skylake
28
+ set (CPU_COMPILE_FLAGS -march=skylake -mtune=skylake )
29
+ elseif (CPU_MODEL EQUAL 58 OR CPU_MODEL EQUAL 62 )
30
+ # Ivy bridge
31
+ set (CPU_COMPILE_FLAGS -march=ivybridge -mtune=ivybridge )
32
+ endif ()
33
+ endif ()
34
+ endif ()
35
+
36
+ if (CPU_COMPILE_FLAGS )
37
+ message ("Setting following CPU-specific compile flags: ${CPU_COMPILE_FLAGS} " )
38
+ add_compile_options (${CPU_COMPILE_FLAGS} )
39
+ else ()
40
+ message ("Could not provide any CPU-specific compile flags" )
41
+ endif ()
You can’t perform that action at this time.
0 commit comments