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 | ############################################################################## |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 15 | # Cache line size detection |
| 16 | ############################################################################## |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 17 | if(CMAKE_CROSSCOMPILING) |
| 18 | message(STATUS "Cross-compiling - cache line size detection disabled") |
| 19 | set(VPP_LOG2_CACHE_LINE_SIZE 6) |
Lijian.Zhang | 49c1bc8 | 2019-02-27 18:17:34 +0800 | [diff] [blame] | 20 | elseif(DEFINED VPP_LOG2_CACHE_LINE_SIZE) |
| 21 | # Cache line size assigned via cmake args |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 22 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 23 | file(READ "/proc/cpuinfo" cpuinfo) |
| 24 | string(REPLACE "\n" ";" cpuinfo ${cpuinfo}) |
| 25 | foreach(l ${cpuinfo}) |
| 26 | string(REPLACE ":" ";" l ${l}) |
| 27 | list(GET l 0 name) |
| 28 | list(GET l 1 value) |
| 29 | string(STRIP ${name} name) |
| 30 | string(STRIP ${value} value) |
| 31 | if(${name} STREQUAL "CPU implementer") |
| 32 | set(CPU_IMPLEMENTER ${value}) |
Marco Varlese | 0745036 | 2018-09-07 11:02:26 +0200 | [diff] [blame] | 33 | endif() |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 34 | if(${name} STREQUAL "CPU part") |
| 35 | set(CPU_PART ${value}) |
Marco Varlese | 0745036 | 2018-09-07 11:02:26 +0200 | [diff] [blame] | 36 | endif() |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 37 | endforeach() |
Nitin Saxena | 66bff59 | 2018-09-06 13:45:41 +0000 | [diff] [blame] | 38 | # Implementer 0x43 - Cavium |
| 39 | # Part 0x0af - ThunderX2 is 64B, rest all are 128B |
Marco Varlese | 0745036 | 2018-09-07 11:02:26 +0200 | [diff] [blame] | 40 | if (${CPU_IMPLEMENTER} STREQUAL "0x43") |
| 41 | if (${CPU_PART} STREQUAL "0x0af") |
| 42 | set(VPP_LOG2_CACHE_LINE_SIZE 6) |
| 43 | else() |
| 44 | set(VPP_LOG2_CACHE_LINE_SIZE 7) |
| 45 | endif() |
Nitin Saxena | 66bff59 | 2018-09-06 13:45:41 +0000 | [diff] [blame] | 46 | else() |
Marco Varlese | 0745036 | 2018-09-07 11:02:26 +0200 | [diff] [blame] | 47 | set(VPP_LOG2_CACHE_LINE_SIZE 6) |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 48 | endif() |
| 49 | math(EXPR VPP_CACHE_LINE_SIZE "1 << ${VPP_LOG2_CACHE_LINE_SIZE}") |
| 50 | message(STATUS "ARM AArch64 CPU implementer ${CPU_IMPLEMENTER} part ${CPU_PART} cacheline size ${VPP_CACHE_LINE_SIZE}") |
| 51 | else() |
| 52 | set(VPP_LOG2_CACHE_LINE_SIZE 6) |
| 53 | endif() |
| 54 | |
| 55 | set(VPP_LOG2_CACHE_LINE_SIZE ${VPP_LOG2_CACHE_LINE_SIZE} |
| 56 | CACHE STRING "Target CPU cache line size (power of 2)") |
| 57 | |
| 58 | ############################################################################## |
Damjan Marion | 6e39ff0 | 2020-04-29 15:15:45 +0200 | [diff] [blame] | 59 | # Gnu Assembler AVX-512 bug detection |
| 60 | # - see: https://sourceware.org/bugzilla/show_bug.cgi?id=23465 |
| 61 | ############################################################################## |
| 62 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") |
| 63 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 64 | set(pfx ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/gas_avx512_bug_test) |
| 65 | file(WRITE ${pfx}.s "vmovaps 0x40(,%rax), %zmm0\n") |
| 66 | execute_process(COMMAND ${CMAKE_C_COMPILER} -c ${pfx}.s -o ${pfx}.o) |
| 67 | execute_process(COMMAND objdump -s ${pfx}.o OUTPUT_VARIABLE _output) |
| 68 | if (NOT _output MATCHES "62f17c48 28040540 000000") |
| 69 | set(GNU_ASSEMBLER_AVX512_BUG 1) |
| 70 | endif() |
| 71 | endif() |
| 72 | endif() |
| 73 | |
| 74 | ############################################################################## |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 75 | # CPU optimizations and multiarch support |
| 76 | ############################################################################## |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 77 | macro(add_vpp_march_variant v) |
| 78 | cmake_parse_arguments(ARG |
| 79 | "OFF" |
| 80 | "N_PREFETCHES" |
| 81 | "FLAGS" |
| 82 | ${ARGN} |
| 83 | ) |
| 84 | |
| 85 | if(ARG_FLAGS) |
| 86 | set(flags_ok 1) |
| 87 | set(fs "") |
| 88 | foreach(f ${ARG_FLAGS}) |
| 89 | string(APPEND fs " ${f}") |
| 90 | string(REGEX REPLACE "[-=+]" "_" sfx ${f}) |
| 91 | if(NOT DEFINED compiler_flag${sfx}) |
| 92 | check_c_compiler_flag(${f} compiler_flag${sfx}) |
| 93 | endif() |
| 94 | if(NOT compiler_flag${sfx}) |
| 95 | unset(flags_ok) |
| 96 | endif() |
| 97 | endforeach() |
| 98 | if(ARG_N_PREFETCHES) |
| 99 | string(APPEND fs " -DCLIB_N_PREFETCHES=${ARG_N_PREFETCHES}") |
| 100 | endif() |
| 101 | if(flags_ok) |
| 102 | string(TOUPPER ${v} uv) |
| 103 | if(ARG_OFF) |
| 104 | option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." OFF) |
| 105 | else() |
| 106 | option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." ON) |
| 107 | endif() |
| 108 | if (VPP_MARCH_VARIANT_${uv}) |
| 109 | list(APPEND MARCH_VARIANTS "${v}\;${fs}") |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 110 | else() |
| 111 | list(APPEND MARCH_VARIANTS_DISABLED "${v}\;${fs}") |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 112 | endif() |
| 113 | endif() |
| 114 | endif() |
| 115 | endmacro() |
| 116 | |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 117 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 118 | set(VPP_DEFAULT_MARCH_FLAGS -march=corei7 -mtune=corei7-avx) |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 119 | |
| 120 | add_vpp_march_variant(hsw |
| 121 | FLAGS -march=haswell -mtune=haswell |
| 122 | ) |
| 123 | |
| 124 | add_vpp_march_variant(trm |
| 125 | FLAGS -march=tremont -mtune=tremont |
| 126 | OFF |
| 127 | ) |
| 128 | |
Damjan Marion | 6e39ff0 | 2020-04-29 15:15:45 +0200 | [diff] [blame] | 129 | if (GNU_ASSEMBLER_AVX512_BUG) |
| 130 | message(WARNING "AVX-512 multiarch variant(s) disabled due to GNU Assembler bug") |
| 131 | else() |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 132 | add_vpp_march_variant(skx |
| 133 | FLAGS -march=skylake-avx512 -mtune=skylake-avx512 -mprefer-vector-width=256 |
| 134 | ) |
| 135 | |
| 136 | add_vpp_march_variant(icl |
| 137 | FLAGS -march=icelake-client -mtune=icelake-client -mprefer-vector-width=512 |
| 138 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 139 | endif() |
| 140 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 141 | set(VPP_DEFAULT_MARCH_FLAGS -march=armv8-a+crc) |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 142 | |
| 143 | add_vpp_march_variant(qdf24xx |
| 144 | FLAGS -march=armv8-a+crc+crypto -mtune=qdf24xx |
| 145 | N_PREFETCHES 8 |
| 146 | OFF |
| 147 | ) |
| 148 | |
| 149 | add_vpp_march_variant(octeontx2 |
| 150 | FLAGS -march=armv8.2-a+crc+crypto+lse |
| 151 | N_PREFETCHES 8 |
| 152 | ) |
| 153 | |
| 154 | add_vpp_march_variant(thunderx2t99 |
| 155 | FLAGS -march=armv8.1-a+crc+crypto -mtune=thunderx2t99 |
| 156 | N_PREFETCHES 8 |
| 157 | ) |
| 158 | |
| 159 | add_vpp_march_variant(cortexa72 |
| 160 | FLAGS -march=armv8-a+crc+crypto -mtune=cortex-a72 |
| 161 | N_PREFETCHES 6 |
| 162 | ) |
| 163 | |
| 164 | add_vpp_march_variant(neoversen1 |
| 165 | FLAGS -march=armv8.2-a+crc+crypto -mtune=neoverse-n1 |
| 166 | N_PREFETCHES 6 |
| 167 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 168 | endif() |
| 169 | |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 170 | macro(vpp_library_set_multiarch_sources lib) |
| 171 | cmake_parse_arguments(ARG |
| 172 | "" |
| 173 | "" |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 174 | "SOURCES;DEPENDS;FORCE_ON" |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 175 | ${ARGN} |
| 176 | ) |
| 177 | |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 178 | set(VARIANTS "${MARCH_VARIANTS}") |
| 179 | |
| 180 | if(ARG_FORCE_ON) |
| 181 | foreach(F ${ARG_FORCE_ON}) |
| 182 | foreach(V ${MARCH_VARIANTS_DISABLED}) |
| 183 | list(GET V 0 VARIANT) |
| 184 | if (VARIANT STREQUAL F) |
| 185 | list(GET V 1 VARIANT_FLAGS) |
| 186 | list(APPEND VARIANTS "${VARIANT}\;${VARIANT_FLAGS}") |
| 187 | endif() |
| 188 | endforeach() |
| 189 | endforeach() |
| 190 | endif() |
| 191 | |
| 192 | foreach(V ${VARIANTS}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 193 | list(GET V 0 VARIANT) |
| 194 | list(GET V 1 VARIANT_FLAGS) |
| 195 | set(l ${lib}_${VARIANT}) |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 196 | add_library(${l} OBJECT ${ARG_SOURCES}) |
| 197 | if(ARG_DEPENDS) |
| 198 | add_dependencies(${l} ${ARG_DEPENDS}) |
Aloys Augustin | 2a65804 | 2020-10-13 15:43:00 +0200 | [diff] [blame] | 199 | endif() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 200 | set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 201 | target_compile_definitions(${l} PUBLIC CLIB_MARCH_VARIANT=${VARIANT}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 202 | separate_arguments(VARIANT_FLAGS) |
| 203 | target_compile_options(${l} PUBLIC ${VARIANT_FLAGS}) |
| 204 | target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>) |
| 205 | endforeach() |
| 206 | endmacro() |
| 207 | |