blob: b2af1aa09263004a2ecf84d5a98a44837b1cc83f [file] [log] [blame]
Damjan Mariond16004d2018-08-26 10:14:52 +02001# Copyright (c) 2018 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14##############################################################################
Damjan Marionedc43872018-09-02 11:16:00 +020015# Cache line size detection
16##############################################################################
Damjan Mariondd395292019-01-15 00:36:03 +010017if(CMAKE_CROSSCOMPILING)
18 message(STATUS "Cross-compiling - cache line size detection disabled")
19 set(VPP_LOG2_CACHE_LINE_SIZE 6)
20elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
Damjan Marionedc43872018-09-02 11:16:00 +020021 file(READ "/proc/cpuinfo" cpuinfo)
22 string(REPLACE "\n" ";" cpuinfo ${cpuinfo})
23 foreach(l ${cpuinfo})
24 string(REPLACE ":" ";" l ${l})
25 list(GET l 0 name)
26 list(GET l 1 value)
27 string(STRIP ${name} name)
28 string(STRIP ${value} value)
29 if(${name} STREQUAL "CPU implementer")
30 set(CPU_IMPLEMENTER ${value})
Marco Varlese07450362018-09-07 11:02:26 +020031 endif()
Damjan Marionedc43872018-09-02 11:16:00 +020032 if(${name} STREQUAL "CPU part")
33 set(CPU_PART ${value})
Marco Varlese07450362018-09-07 11:02:26 +020034 endif()
Damjan Marionedc43872018-09-02 11:16:00 +020035 endforeach()
Nitin Saxena66bff592018-09-06 13:45:41 +000036 # Implementer 0x43 - Cavium
37 # Part 0x0af - ThunderX2 is 64B, rest all are 128B
Marco Varlese07450362018-09-07 11:02:26 +020038 if (${CPU_IMPLEMENTER} STREQUAL "0x43")
39 if (${CPU_PART} STREQUAL "0x0af")
40 set(VPP_LOG2_CACHE_LINE_SIZE 6)
41 else()
42 set(VPP_LOG2_CACHE_LINE_SIZE 7)
43 endif()
Nitin Saxena66bff592018-09-06 13:45:41 +000044 else()
Marco Varlese07450362018-09-07 11:02:26 +020045 set(VPP_LOG2_CACHE_LINE_SIZE 6)
Damjan Marionedc43872018-09-02 11:16:00 +020046 endif()
47 math(EXPR VPP_CACHE_LINE_SIZE "1 << ${VPP_LOG2_CACHE_LINE_SIZE}")
48 message(STATUS "ARM AArch64 CPU implementer ${CPU_IMPLEMENTER} part ${CPU_PART} cacheline size ${VPP_CACHE_LINE_SIZE}")
49else()
50 set(VPP_LOG2_CACHE_LINE_SIZE 6)
51endif()
52
53set(VPP_LOG2_CACHE_LINE_SIZE ${VPP_LOG2_CACHE_LINE_SIZE}
54 CACHE STRING "Target CPU cache line size (power of 2)")
55
56##############################################################################
Damjan Mariond16004d2018-08-26 10:14:52 +020057# CPU optimizations and multiarch support
58##############################################################################
59if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
60 set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
Damjan Marion33ed3e42018-08-27 15:59:30 +020061 check_c_compiler_flag("-march=core-avx2" compiler_flag_march_core_avx2)
62 if(compiler_flag_march_core_avx2)
Damjan Mariond16004d2018-08-26 10:14:52 +020063 list(APPEND MARCH_VARIANTS "avx2\;-march=core-avx2 -mtune=core-avx2")
64 endif()
Damjan Marion33ed3e42018-08-27 15:59:30 +020065 check_c_compiler_flag("-march=skylake-avx512" compiler_flag_march_skylake_avx512)
66 if(compiler_flag_march_skylake_avx512)
Damjan Mariond16004d2018-08-26 10:14:52 +020067 list(APPEND MARCH_VARIANTS "avx512\;-march=skylake-avx512 -mtune=skylake-avx512")
68 endif()
69elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
70 set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}")
Lijian Zhang2e237212018-09-10 17:13:56 +080071 check_c_compiler_flag("-march=armv8-a+crc+crypto -mtune=qdf24xx" compiler_flag_march_core_qdf24xx)
72 if(compiler_flag_march_core_qdf24xx)
73 list(APPEND MARCH_VARIANTS "qdf24xx\;-march=armv8-a+crc+crypto -DCLIB_N_PREFETCHES=8")
74 endif()
75 check_c_compiler_flag("-march=armv8.1-a+crc+crypto -mtune=thunderx2t99" compiler_flag_march_thunderx2t99)
76 if(compiler_flag_march_thunderx2t99)
77 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 7.3)
78 list(APPEND MARCH_VARIANTS "thunderx2t99\;-march=armv8.1-a+crc+crypto -mtune=thunderx2t99 -DCLIB_N_PREFETCHES=8")
79 else()
80 list(APPEND MARCH_VARIANTS "thunderx2t99\;-march=armv8.1-a+crc+crypto -DCLIB_N_PREFETCHES=8")
81 endif()
82 endif()
83 check_c_compiler_flag("-march=armv8-a+crc+crypto -mtune=cortex-a72" compiler_flag_march_cortexa72)
84 if(compiler_flag_march_cortexa72)
85 list(APPEND MARCH_VARIANTS "cortexa72\;-march=armv8-a+crc+crypto -mtune=cortex-a72 -DCLIB_N_PREFETCHES=6")
86 endif()
Damjan Mariond16004d2018-08-26 10:14:52 +020087endif()
88
89macro(vpp_library_set_multiarch_sources lib)
90 foreach(V ${MARCH_VARIANTS})
91 list(GET V 0 VARIANT)
92 list(GET V 1 VARIANT_FLAGS)
93 set(l ${lib}_${VARIANT})
94 add_library(${l} OBJECT ${ARGN})
95 set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON)
96 target_compile_options(${l} PUBLIC "-DCLIB_MARCH_VARIANT=${VARIANT}")
97 separate_arguments(VARIANT_FLAGS)
98 target_compile_options(${l} PUBLIC ${VARIANT_FLAGS})
99 target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>)
100 endforeach()
101endmacro()
102