blob: ef0393684cb75efd6f990174e52b2917bd3463d2 [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##############################################################################
17if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
18 file(READ "/proc/cpuinfo" cpuinfo)
19 string(REPLACE "\n" ";" cpuinfo ${cpuinfo})
20 foreach(l ${cpuinfo})
21 string(REPLACE ":" ";" l ${l})
22 list(GET l 0 name)
23 list(GET l 1 value)
24 string(STRIP ${name} name)
25 string(STRIP ${value} value)
26 if(${name} STREQUAL "CPU implementer")
27 set(CPU_IMPLEMENTER ${value})
28 endif()
29 if(${name} STREQUAL "CPU part")
30 set(CPU_PART ${value})
31 endif()
32 endforeach()
Nitin Saxena66bff592018-09-06 13:45:41 +000033 # Implementer 0x43 - Cavium
34 # Part 0x0af - ThunderX2 is 64B, rest all are 128B
35 if (${CPU_IMPLEMENTER} STREQUAL "0x43" AND ${CPU_PART} STREQUAL "0x0af")
Damjan Marionedc43872018-09-02 11:16:00 +020036 set(VPP_LOG2_CACHE_LINE_SIZE 6)
Nitin Saxena66bff592018-09-06 13:45:41 +000037 else()
38 set(VPP_LOG2_CACHE_LINE_SIZE 7)
Damjan Marionedc43872018-09-02 11:16:00 +020039 endif()
40 math(EXPR VPP_CACHE_LINE_SIZE "1 << ${VPP_LOG2_CACHE_LINE_SIZE}")
41 message(STATUS "ARM AArch64 CPU implementer ${CPU_IMPLEMENTER} part ${CPU_PART} cacheline size ${VPP_CACHE_LINE_SIZE}")
42else()
43 set(VPP_LOG2_CACHE_LINE_SIZE 6)
44endif()
45
46set(VPP_LOG2_CACHE_LINE_SIZE ${VPP_LOG2_CACHE_LINE_SIZE}
47 CACHE STRING "Target CPU cache line size (power of 2)")
48
49##############################################################################
Damjan Mariond16004d2018-08-26 10:14:52 +020050# CPU optimizations and multiarch support
51##############################################################################
52if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
53 set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
Damjan Marionc2617602018-08-27 11:40:58 +020054 set(VPP_LIB_DIR_NAME lib64)
Damjan Marion33ed3e42018-08-27 15:59:30 +020055 check_c_compiler_flag("-march=core-avx2" compiler_flag_march_core_avx2)
56 if(compiler_flag_march_core_avx2)
Damjan Mariond16004d2018-08-26 10:14:52 +020057 list(APPEND MARCH_VARIANTS "avx2\;-march=core-avx2 -mtune=core-avx2")
58 endif()
Damjan Marion33ed3e42018-08-27 15:59:30 +020059 check_c_compiler_flag("-march=skylake-avx512" compiler_flag_march_skylake_avx512)
60 if(compiler_flag_march_skylake_avx512)
Damjan Mariond16004d2018-08-26 10:14:52 +020061 list(APPEND MARCH_VARIANTS "avx512\;-march=skylake-avx512 -mtune=skylake-avx512")
62 endif()
63elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
64 set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}")
Damjan Marionc2617602018-08-27 11:40:58 +020065 set(VPP_LIB_DIR_NAME lib64)
66else()
67 set(VPP_LIB_DIR_NAME lib)
Damjan Mariond16004d2018-08-26 10:14:52 +020068endif()
69
70macro(vpp_library_set_multiarch_sources lib)
71 foreach(V ${MARCH_VARIANTS})
72 list(GET V 0 VARIANT)
73 list(GET V 1 VARIANT_FLAGS)
74 set(l ${lib}_${VARIANT})
75 add_library(${l} OBJECT ${ARGN})
76 set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON)
77 target_compile_options(${l} PUBLIC "-DCLIB_MARCH_VARIANT=${VARIANT}")
78 separate_arguments(VARIANT_FLAGS)
79 target_compile_options(${l} PUBLIC ${VARIANT_FLAGS})
80 target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>)
81 endforeach()
82endmacro()
83