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 | |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 14 | macro(set_log2_cacheline_size var n) |
| 15 | if(${n} EQUAL 128) |
| 16 | set(${var} 7) |
| 17 | elseif(${n} EQUAL 64) |
| 18 | set(${var} 6) |
| 19 | else() |
| 20 | message(FATAL_ERROR "Cacheline size ${n} not supported") |
| 21 | endif() |
| 22 | endmacro() |
| 23 | |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 24 | ############################################################################## |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 25 | # Cache line size |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 26 | ############################################################################## |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 27 | if(DEFINED VPP_CACHE_LINE_SIZE) |
Lijian.Zhang | 49c1bc8 | 2019-02-27 18:17:34 +0800 | [diff] [blame] | 28 | # Cache line size assigned via cmake args |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 29 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 30 | set(VPP_CACHE_LINE_SIZE 128) |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 31 | else() |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 32 | set(VPP_CACHE_LINE_SIZE 64) |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 33 | endif() |
| 34 | |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 35 | set(VPP_CACHE_LINE_SIZE ${VPP_CACHE_LINE_SIZE} |
| 36 | CACHE STRING "Target CPU cache line size") |
| 37 | |
| 38 | set_log2_cacheline_size(VPP_LOG2_CACHE_LINE_SIZE ${VPP_CACHE_LINE_SIZE}) |
Damjan Marion | edc4387 | 2018-09-02 11:16:00 +0200 | [diff] [blame] | 39 | |
| 40 | ############################################################################## |
Damjan Marion | 6e39ff0 | 2020-04-29 15:15:45 +0200 | [diff] [blame] | 41 | # Gnu Assembler AVX-512 bug detection |
| 42 | # - see: https://sourceware.org/bugzilla/show_bug.cgi?id=23465 |
| 43 | ############################################################################## |
| 44 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") |
| 45 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 46 | set(pfx ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/gas_avx512_bug_test) |
| 47 | file(WRITE ${pfx}.s "vmovaps 0x40(,%rax), %zmm0\n") |
| 48 | execute_process(COMMAND ${CMAKE_C_COMPILER} -c ${pfx}.s -o ${pfx}.o) |
| 49 | execute_process(COMMAND objdump -s ${pfx}.o OUTPUT_VARIABLE _output) |
| 50 | if (NOT _output MATCHES "62f17c48 28040540 000000") |
| 51 | set(GNU_ASSEMBLER_AVX512_BUG 1) |
| 52 | endif() |
| 53 | endif() |
| 54 | endif() |
| 55 | |
| 56 | ############################################################################## |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 57 | # CPU optimizations and multiarch support |
| 58 | ############################################################################## |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 59 | |
| 60 | option(VPP_BUILD_NATIVE_ONLY "Build only for native CPU." OFF) |
| 61 | |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 62 | macro(add_vpp_march_variant v) |
| 63 | cmake_parse_arguments(ARG |
| 64 | "OFF" |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 65 | "N_PREFETCHES;CACHE_PREFETCH_BYTES" |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 66 | "FLAGS" |
| 67 | ${ARGN} |
| 68 | ) |
| 69 | |
| 70 | if(ARG_FLAGS) |
| 71 | set(flags_ok 1) |
| 72 | set(fs "") |
| 73 | foreach(f ${ARG_FLAGS}) |
| 74 | string(APPEND fs " ${f}") |
| 75 | string(REGEX REPLACE "[-=+]" "_" sfx ${f}) |
| 76 | if(NOT DEFINED compiler_flag${sfx}) |
| 77 | check_c_compiler_flag(${f} compiler_flag${sfx}) |
| 78 | endif() |
| 79 | if(NOT compiler_flag${sfx}) |
| 80 | unset(flags_ok) |
| 81 | endif() |
| 82 | endforeach() |
| 83 | if(ARG_N_PREFETCHES) |
| 84 | string(APPEND fs " -DCLIB_N_PREFETCHES=${ARG_N_PREFETCHES}") |
| 85 | endif() |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 86 | if(ARG_CACHE_PREFETCH_BYTES) |
| 87 | set_log2_cacheline_size(log2 ${ARG_CACHE_PREFETCH_BYTES}) |
| 88 | string(APPEND fs " -DCLIB_LOG2_CACHE_PREFETCH_BYTES=${log2}") |
| 89 | endif() |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 90 | if(flags_ok) |
| 91 | string(TOUPPER ${v} uv) |
| 92 | if(ARG_OFF) |
| 93 | option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." OFF) |
| 94 | else() |
| 95 | option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." ON) |
| 96 | endif() |
| 97 | if (VPP_MARCH_VARIANT_${uv}) |
| 98 | list(APPEND MARCH_VARIANTS "${v}\;${fs}") |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 99 | list(APPEND MARCH_VARIANTS_NAMES "${v}") |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 100 | else() |
| 101 | list(APPEND MARCH_VARIANTS_DISABLED "${v}\;${fs}") |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 102 | endif() |
| 103 | endif() |
| 104 | endif() |
| 105 | endmacro() |
| 106 | |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 107 | if(VPP_BUILD_NATIVE_ONLY) |
Damjan Marion | f0fc65a | 2023-08-31 17:00:16 +0200 | [diff] [blame] | 108 | set(VPP_BUILD_NATIVE_ARCH "native" CACHE STRING "native CPU -march= value.") |
| 109 | set(VPP_DEFAULT_MARCH_FLAGS -march=${VPP_BUILD_NATIVE_ARCH}) |
| 110 | if(VPP_BUILD_NATIVE_ONLY) |
| 111 | check_c_compiler_flag(${VPP_DEFAULT_MARCH_FLAGS} compiler_flag_march) |
| 112 | if(NOT compiler_flag_march) |
| 113 | message(FATAL_ERROR "Native-only build with ${VPP_DEFAULT_MARCH_FLAGS} is not supported by compiler") |
| 114 | endif() |
| 115 | endif() |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 116 | set(MARCH_VARIANTS_NAMES "native-only") |
| 117 | elseif(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 | 1552228 | 2023-03-14 13:34:59 +0100 | [diff] [blame] | 129 | add_vpp_march_variant(adl |
| 130 | FLAGS -march=alderlake -mtune=alderlake -mprefer-vector-width=256 |
| 131 | OFF |
| 132 | ) |
| 133 | |
Damjan Marion | 98f7f0a | 2023-04-17 09:38:11 +0000 | [diff] [blame] | 134 | add_vpp_march_variant(scalar |
| 135 | FLAGS -march=core2 -mno-mmx -mno-sse |
| 136 | OFF |
| 137 | ) |
| 138 | |
Sivaprasad Tummala | 206592b | 2023-04-17 05:05:15 -0700 | [diff] [blame] | 139 | add_vpp_march_variant(znver3 |
| 140 | FLAGS -march=znver3 -mtune=znver3 -mprefer-vector-width=256 |
| 141 | OFF |
| 142 | ) |
| 143 | |
Damjan Marion | 6e39ff0 | 2020-04-29 15:15:45 +0200 | [diff] [blame] | 144 | if (GNU_ASSEMBLER_AVX512_BUG) |
| 145 | message(WARNING "AVX-512 multiarch variant(s) disabled due to GNU Assembler bug") |
| 146 | else() |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 147 | add_vpp_march_variant(skx |
| 148 | FLAGS -march=skylake-avx512 -mtune=skylake-avx512 -mprefer-vector-width=256 |
| 149 | ) |
| 150 | |
| 151 | add_vpp_march_variant(icl |
| 152 | FLAGS -march=icelake-client -mtune=icelake-client -mprefer-vector-width=512 |
| 153 | ) |
Damjan Marion | 1552228 | 2023-03-14 13:34:59 +0100 | [diff] [blame] | 154 | |
| 155 | add_vpp_march_variant(spr |
| 156 | FLAGS -march=sapphirerapids -mtune=sapphirerapids -mprefer-vector-width=512 |
| 157 | OFF |
| 158 | ) |
Sivaprasad Tummala | 206592b | 2023-04-17 05:05:15 -0700 | [diff] [blame] | 159 | |
| 160 | add_vpp_march_variant(znver4 |
| 161 | FLAGS -march=znver4 -mtune=znver4 -mprefer-vector-width=512 |
| 162 | OFF |
| 163 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 164 | endif() |
| 165 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 166 | set(VPP_DEFAULT_MARCH_FLAGS -march=armv8-a+crc) |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 167 | |
| 168 | add_vpp_march_variant(qdf24xx |
| 169 | FLAGS -march=armv8-a+crc+crypto -mtune=qdf24xx |
| 170 | N_PREFETCHES 8 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 171 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 172 | OFF |
| 173 | ) |
| 174 | |
| 175 | add_vpp_march_variant(octeontx2 |
| 176 | FLAGS -march=armv8.2-a+crc+crypto+lse |
| 177 | N_PREFETCHES 8 |
| 178 | ) |
| 179 | |
| 180 | add_vpp_march_variant(thunderx2t99 |
| 181 | FLAGS -march=armv8.1-a+crc+crypto -mtune=thunderx2t99 |
| 182 | N_PREFETCHES 8 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 183 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 184 | ) |
| 185 | |
| 186 | add_vpp_march_variant(cortexa72 |
| 187 | FLAGS -march=armv8-a+crc+crypto -mtune=cortex-a72 |
| 188 | N_PREFETCHES 6 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 189 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 190 | ) |
| 191 | |
| 192 | add_vpp_march_variant(neoversen1 |
| 193 | FLAGS -march=armv8.2-a+crc+crypto -mtune=neoverse-n1 |
| 194 | N_PREFETCHES 6 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 195 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 196 | ) |
Damjan Marion | 7bf8f5e | 2023-09-12 15:08:58 +0200 | [diff] [blame^] | 197 | |
| 198 | add_vpp_march_variant(neoversen2 |
| 199 | FLAGS -march=armv8.6-a+crc+crypto+sve2 -mtune=neoverse-n2 |
| 200 | N_PREFETCHES 8 |
| 201 | CACHE_PREFETCH_BYTES 64 |
| 202 | OFF |
| 203 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 204 | endif() |
| 205 | |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 206 | macro(vpp_library_set_multiarch_sources lib) |
| 207 | cmake_parse_arguments(ARG |
| 208 | "" |
| 209 | "" |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 210 | "SOURCES;DEPENDS;FORCE_ON" |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 211 | ${ARGN} |
| 212 | ) |
| 213 | |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 214 | set(VARIANTS "${MARCH_VARIANTS}") |
| 215 | |
| 216 | if(ARG_FORCE_ON) |
| 217 | foreach(F ${ARG_FORCE_ON}) |
| 218 | foreach(V ${MARCH_VARIANTS_DISABLED}) |
| 219 | list(GET V 0 VARIANT) |
| 220 | if (VARIANT STREQUAL F) |
| 221 | list(GET V 1 VARIANT_FLAGS) |
| 222 | list(APPEND VARIANTS "${VARIANT}\;${VARIANT_FLAGS}") |
| 223 | endif() |
| 224 | endforeach() |
| 225 | endforeach() |
| 226 | endif() |
| 227 | |
| 228 | foreach(V ${VARIANTS}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 229 | list(GET V 0 VARIANT) |
| 230 | list(GET V 1 VARIANT_FLAGS) |
| 231 | set(l ${lib}_${VARIANT}) |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 232 | add_library(${l} OBJECT ${ARG_SOURCES}) |
| 233 | if(ARG_DEPENDS) |
| 234 | add_dependencies(${l} ${ARG_DEPENDS}) |
Aloys Augustin | 2a65804 | 2020-10-13 15:43:00 +0200 | [diff] [blame] | 235 | endif() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 236 | set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 237 | target_compile_definitions(${l} PUBLIC CLIB_MARCH_VARIANT=${VARIANT}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 238 | separate_arguments(VARIANT_FLAGS) |
| 239 | target_compile_options(${l} PUBLIC ${VARIANT_FLAGS}) |
| 240 | target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>) |
| 241 | endforeach() |
| 242 | endmacro() |
| 243 | |