Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 1 | # 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 | ############################################################################## |
| 15 | # CPU optimizations and multiarch support |
| 16 | ############################################################################## |
| 17 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") |
| 18 | set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}") |
Damjan Marion | c261760 | 2018-08-27 11:40:58 +0200 | [diff] [blame] | 19 | set(VPP_LIB_DIR_NAME lib64) |
Damjan Marion | 33ed3e4 | 2018-08-27 15:59:30 +0200 | [diff] [blame] | 20 | check_c_compiler_flag("-march=core-avx2" compiler_flag_march_core_avx2) |
| 21 | if(compiler_flag_march_core_avx2) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 22 | list(APPEND MARCH_VARIANTS "avx2\;-march=core-avx2 -mtune=core-avx2") |
| 23 | endif() |
Damjan Marion | 33ed3e4 | 2018-08-27 15:59:30 +0200 | [diff] [blame] | 24 | check_c_compiler_flag("-march=skylake-avx512" compiler_flag_march_skylake_avx512) |
| 25 | if(compiler_flag_march_skylake_avx512) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 26 | list(APPEND MARCH_VARIANTS "avx512\;-march=skylake-avx512 -mtune=skylake-avx512") |
| 27 | endif() |
| 28 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
| 29 | set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}") |
Damjan Marion | c261760 | 2018-08-27 11:40:58 +0200 | [diff] [blame] | 30 | set(VPP_LIB_DIR_NAME lib64) |
| 31 | else() |
| 32 | set(VPP_LIB_DIR_NAME lib) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 33 | endif() |
| 34 | |
| 35 | macro(vpp_library_set_multiarch_sources lib) |
| 36 | foreach(V ${MARCH_VARIANTS}) |
| 37 | list(GET V 0 VARIANT) |
| 38 | list(GET V 1 VARIANT_FLAGS) |
| 39 | set(l ${lib}_${VARIANT}) |
| 40 | add_library(${l} OBJECT ${ARGN}) |
| 41 | set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 42 | target_compile_options(${l} PUBLIC "-DCLIB_MARCH_VARIANT=${VARIANT}") |
| 43 | separate_arguments(VARIANT_FLAGS) |
| 44 | target_compile_options(${l} PUBLIC ${VARIANT_FLAGS}) |
| 45 | target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>) |
| 46 | endforeach() |
| 47 | endmacro() |
| 48 | |