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