cpu.cmake (5153B)
1 # 2 # Copyright (c) 2017, Alliance for Open Media. All rights reserved. 3 # 4 # This source code is subject to the terms of the BSD 2 Clause License and the 5 # Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was 6 # not distributed with this source code in the LICENSE file, you can obtain it 7 # at www.aomedia.org/license/software. If the Alliance for Open Media Patent 8 # License 1.0 was not distributed with this source code in the PATENTS file, you 9 # can obtain it at www.aomedia.org/license/patent. 10 # 11 12 if("${AOM_TARGET_CPU}" STREQUAL "arm64") 13 set(AOM_ARCH_ARM 1) 14 set(AOM_ARCH_AARCH64 1) 15 16 set(ARM64_FLAVORS "NEON;ARM_CRC32;NEON_DOTPROD;NEON_I8MM;SVE;SVE2") 17 set(AOM_ARM_CRC32_DEFAULT_FLAG "-march=armv8-a+crc") 18 set(AOM_NEON_DOTPROD_DEFAULT_FLAG "-march=armv8.2-a+dotprod") 19 set(AOM_NEON_I8MM_DEFAULT_FLAG "-march=armv8.2-a+dotprod+i8mm") 20 set(AOM_SVE_DEFAULT_FLAG "-march=armv8.2-a+dotprod+i8mm+sve") 21 set(AOM_SVE2_DEFAULT_FLAG "-march=armv9-a+i8mm+sve2") # SVE2 is a v9-only 22 # feature 23 24 # Check that the compiler flag to enable each flavor is supported by the 25 # compiler. This may not be the case for new architecture features on old 26 # compiler versions. 27 foreach(flavor ${ARM64_FLAVORS}) 28 if(ENABLE_${flavor} AND NOT DEFINED AOM_${flavor}_FLAG) 29 set(AOM_${flavor}_FLAG "${AOM_${flavor}_DEFAULT_FLAG}") 30 string(TOLOWER "${flavor}" flavor_lower) 31 32 # Do not use check_c_compiler_flag here since the regex used to match 33 # against stderr does not recognise the "invalid feature modifier" error 34 # produced by certain versions of GCC, leading to the feature being 35 # incorrectly marked as available. 36 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 37 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${AOM_${flavor}_FLAG}") 38 unset(FLAG_SUPPORTED) 39 aom_check_source_compiles("arm_feature_flag_${flavor_lower}_available" 40 "static void function(void) {}" FLAG_SUPPORTED) 41 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) 42 43 if(NOT ${FLAG_SUPPORTED}) 44 set(ENABLE_${flavor} 0) 45 endif() 46 endif() 47 endforeach() 48 49 # SVE and SVE2 require that the Neon-SVE bridge header is also available. 50 if(ENABLE_SVE OR ENABLE_SVE2) 51 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 52 set(OLD_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) 53 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${AOM_SVE_FLAG}") 54 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 55 aom_check_source_compiles("arm_neon_sve_bridge_available" " 56 #ifndef __ARM_NEON_SVE_BRIDGE 57 #error 1 58 #endif 59 #include <arm_sve.h> 60 #include <arm_neon_sve_bridge.h>" HAVE_SVE_HEADERS) 61 # Check whether the compiler can compile SVE functions that require 62 # backup/restore of SVE registers according to AAPCS. Clang for Windows used 63 # to fail this, see https://github.com/llvm/llvm-project/issues/80009. 64 aom_check_source_compiles("arm_sve_preserve" " 65 #include <arm_sve.h> 66 void other(void)\; 67 svfloat32_t func(svfloat32_t a) { 68 other()\; 69 return a\; 70 }" CAN_COMPILE_SVE) 71 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) 72 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${OLD_CMAKE_TRY_COMPILE_TARGET_TYPE}) 73 if(HAVE_SVE_HEADERS EQUAL 0 OR CAN_COMPILE_SVE EQUAL 0) 74 set(ENABLE_SVE 0) 75 set(ENABLE_SVE2 0) 76 endif() 77 endif() 78 79 foreach(flavor ${ARM64_FLAVORS}) 80 if(ENABLE_${flavor}) 81 set(HAVE_${flavor} 1) 82 else() 83 set(HAVE_${flavor} 0) 84 string(TOLOWER ${flavor} flavor) 85 set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-${flavor}) 86 endif() 87 endforeach() 88 89 elseif("${AOM_TARGET_CPU}" MATCHES "^arm") 90 set(AOM_ARCH_ARM 1) 91 92 if(ENABLE_NEON) 93 set(HAVE_NEON 1) 94 else() 95 set(HAVE_NEON 0) 96 set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-neon) 97 endif() 98 99 elseif("${AOM_TARGET_CPU}" MATCHES "ppc") 100 set(AOM_ARCH_PPC 1) 101 102 if(ENABLE_VSX) 103 set(HAVE_VSX 1) 104 else() 105 set(HAVE_VSX 0) 106 set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-vsx) 107 endif() 108 elseif("${AOM_TARGET_CPU}" MATCHES "^x86") 109 if("${AOM_TARGET_CPU}" STREQUAL "x86") 110 set(AOM_ARCH_X86 1) 111 # Disable avx512 112 set(HAVE_AVX512 0) 113 set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-avx512) 114 elseif("${AOM_TARGET_CPU}" STREQUAL "x86_64") 115 set(AOM_ARCH_X86_64 1) 116 endif() 117 118 set(X86_FLAVORS "MMX;SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;AVX;AVX2;AVX512") 119 foreach(flavor ${X86_FLAVORS}) 120 # Special handling of AVX512 on x86-32 above. 121 if("${flavor}" STREQUAL "AVX512" AND "${AOM_TARGET_CPU}" STREQUAL "x86") 122 continue() 123 endif() 124 if(ENABLE_${flavor} AND NOT disable_remaining_flavors) 125 set(HAVE_${flavor} 1) 126 else() 127 set(disable_remaining_flavors 1) 128 set(HAVE_${flavor} 0) 129 string(TOLOWER ${flavor} flavor) 130 set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-${flavor}) 131 endif() 132 endforeach() 133 elseif("${AOM_TARGET_CPU}" MATCHES "riscv") 134 set(AOM_ARCH_RISCV64 1) 135 136 if(ENABLE_RVV) 137 set(HAVE_RVV 1) 138 else() 139 set(HAVE_RVV 0) 140 set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-rvv) 141 endif() 142 endif()