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 | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 59 | macro(add_vpp_march_variant v) |
| 60 | cmake_parse_arguments(ARG |
| 61 | "OFF" |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 62 | "N_PREFETCHES;CACHE_PREFETCH_BYTES" |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 63 | "FLAGS" |
| 64 | ${ARGN} |
| 65 | ) |
| 66 | |
| 67 | if(ARG_FLAGS) |
| 68 | set(flags_ok 1) |
| 69 | set(fs "") |
| 70 | foreach(f ${ARG_FLAGS}) |
| 71 | string(APPEND fs " ${f}") |
| 72 | string(REGEX REPLACE "[-=+]" "_" sfx ${f}) |
| 73 | if(NOT DEFINED compiler_flag${sfx}) |
| 74 | check_c_compiler_flag(${f} compiler_flag${sfx}) |
| 75 | endif() |
| 76 | if(NOT compiler_flag${sfx}) |
| 77 | unset(flags_ok) |
| 78 | endif() |
| 79 | endforeach() |
| 80 | if(ARG_N_PREFETCHES) |
| 81 | string(APPEND fs " -DCLIB_N_PREFETCHES=${ARG_N_PREFETCHES}") |
| 82 | endif() |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 83 | if(ARG_CACHE_PREFETCH_BYTES) |
| 84 | set_log2_cacheline_size(log2 ${ARG_CACHE_PREFETCH_BYTES}) |
| 85 | string(APPEND fs " -DCLIB_LOG2_CACHE_PREFETCH_BYTES=${log2}") |
| 86 | endif() |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 87 | if(flags_ok) |
| 88 | string(TOUPPER ${v} uv) |
| 89 | if(ARG_OFF) |
| 90 | option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." OFF) |
| 91 | else() |
| 92 | option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." ON) |
| 93 | endif() |
| 94 | if (VPP_MARCH_VARIANT_${uv}) |
| 95 | list(APPEND MARCH_VARIANTS "${v}\;${fs}") |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 96 | else() |
| 97 | list(APPEND MARCH_VARIANTS_DISABLED "${v}\;${fs}") |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 98 | endif() |
| 99 | endif() |
| 100 | endif() |
| 101 | endmacro() |
| 102 | |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 103 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 104 | set(VPP_DEFAULT_MARCH_FLAGS -march=corei7 -mtune=corei7-avx) |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 105 | |
| 106 | add_vpp_march_variant(hsw |
| 107 | FLAGS -march=haswell -mtune=haswell |
| 108 | ) |
| 109 | |
| 110 | add_vpp_march_variant(trm |
| 111 | FLAGS -march=tremont -mtune=tremont |
| 112 | OFF |
| 113 | ) |
| 114 | |
Damjan Marion | 6e39ff0 | 2020-04-29 15:15:45 +0200 | [diff] [blame] | 115 | if (GNU_ASSEMBLER_AVX512_BUG) |
| 116 | message(WARNING "AVX-512 multiarch variant(s) disabled due to GNU Assembler bug") |
| 117 | else() |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 118 | add_vpp_march_variant(skx |
| 119 | FLAGS -march=skylake-avx512 -mtune=skylake-avx512 -mprefer-vector-width=256 |
| 120 | ) |
| 121 | |
| 122 | add_vpp_march_variant(icl |
| 123 | FLAGS -march=icelake-client -mtune=icelake-client -mprefer-vector-width=512 |
| 124 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 125 | endif() |
| 126 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 127 | set(VPP_DEFAULT_MARCH_FLAGS -march=armv8-a+crc) |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 128 | |
| 129 | add_vpp_march_variant(qdf24xx |
| 130 | FLAGS -march=armv8-a+crc+crypto -mtune=qdf24xx |
| 131 | N_PREFETCHES 8 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 132 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 133 | OFF |
| 134 | ) |
| 135 | |
| 136 | add_vpp_march_variant(octeontx2 |
| 137 | FLAGS -march=armv8.2-a+crc+crypto+lse |
| 138 | N_PREFETCHES 8 |
| 139 | ) |
| 140 | |
| 141 | add_vpp_march_variant(thunderx2t99 |
| 142 | FLAGS -march=armv8.1-a+crc+crypto -mtune=thunderx2t99 |
| 143 | N_PREFETCHES 8 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 144 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 145 | ) |
| 146 | |
| 147 | add_vpp_march_variant(cortexa72 |
| 148 | FLAGS -march=armv8-a+crc+crypto -mtune=cortex-a72 |
| 149 | N_PREFETCHES 6 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 150 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 151 | ) |
| 152 | |
| 153 | add_vpp_march_variant(neoversen1 |
| 154 | FLAGS -march=armv8.2-a+crc+crypto -mtune=neoverse-n1 |
| 155 | N_PREFETCHES 6 |
Damjan Marion | 24d65a1 | 2021-07-14 18:18:08 +0200 | [diff] [blame] | 156 | CACHE_PREFETCH_BYTES 64 |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 157 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 158 | endif() |
| 159 | |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 160 | macro(vpp_library_set_multiarch_sources lib) |
| 161 | cmake_parse_arguments(ARG |
| 162 | "" |
| 163 | "" |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 164 | "SOURCES;DEPENDS;FORCE_ON" |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 165 | ${ARGN} |
| 166 | ) |
| 167 | |
Damjan Marion | 312fb4d | 2021-05-06 20:48:34 +0200 | [diff] [blame] | 168 | set(VARIANTS "${MARCH_VARIANTS}") |
| 169 | |
| 170 | if(ARG_FORCE_ON) |
| 171 | foreach(F ${ARG_FORCE_ON}) |
| 172 | foreach(V ${MARCH_VARIANTS_DISABLED}) |
| 173 | list(GET V 0 VARIANT) |
| 174 | if (VARIANT STREQUAL F) |
| 175 | list(GET V 1 VARIANT_FLAGS) |
| 176 | list(APPEND VARIANTS "${VARIANT}\;${VARIANT_FLAGS}") |
| 177 | endif() |
| 178 | endforeach() |
| 179 | endforeach() |
| 180 | endif() |
| 181 | |
| 182 | foreach(V ${VARIANTS}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 183 | list(GET V 0 VARIANT) |
| 184 | list(GET V 1 VARIANT_FLAGS) |
| 185 | set(l ${lib}_${VARIANT}) |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 186 | add_library(${l} OBJECT ${ARG_SOURCES}) |
| 187 | if(ARG_DEPENDS) |
| 188 | add_dependencies(${l} ${ARG_DEPENDS}) |
Aloys Augustin | 2a65804 | 2020-10-13 15:43:00 +0200 | [diff] [blame] | 189 | endif() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 190 | set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 191 | target_compile_definitions(${l} PUBLIC CLIB_MARCH_VARIANT=${VARIANT}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 192 | separate_arguments(VARIANT_FLAGS) |
| 193 | target_compile_options(${l} PUBLIC ${VARIANT_FLAGS}) |
| 194 | target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>) |
| 195 | endforeach() |
| 196 | endmacro() |
| 197 | |