xref: /aosp_15_r20/external/libgav1/cmake/libgav1_cpu_detection.cmake (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1# Copyright 2019 The libgav1 Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15if(LIBGAV1_CMAKE_LIBGAV1_CPU_DETECTION_CMAKE_)
16  return()
17endif() # LIBGAV1_CMAKE_LIBGAV1_CPU_DETECTION_CMAKE_
18set(LIBGAV1_CMAKE_LIBGAV1_CPU_DETECTION_CMAKE_ 1)
19
20# Detect optimizations available for the current target CPU.
21macro(libgav1_optimization_detect)
22  if(LIBGAV1_ENABLE_OPTIMIZATIONS)
23    string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" cpu_lowercase)
24    if(cpu_lowercase MATCHES "^arm|^aarch64")
25      set(libgav1_have_neon ON)
26    elseif(cpu_lowercase MATCHES "^x86|amd64")
27      set(libgav1_have_avx2 ON)
28      set(libgav1_have_sse4 ON)
29    endif()
30  endif()
31
32  if(libgav1_have_avx2 AND LIBGAV1_ENABLE_AVX2)
33    list(APPEND libgav1_defines "LIBGAV1_ENABLE_AVX2=1")
34  else()
35    list(APPEND libgav1_defines "LIBGAV1_ENABLE_AVX2=0")
36    set(libgav1_have_avx2 OFF)
37  endif()
38
39  if(libgav1_have_neon AND LIBGAV1_ENABLE_NEON)
40    list(APPEND libgav1_defines "LIBGAV1_ENABLE_NEON=1")
41  else()
42    list(APPEND libgav1_defines "LIBGAV1_ENABLE_NEON=0")
43    set(libgav1_have_neon, OFF)
44  endif()
45
46  if(libgav1_have_sse4 AND LIBGAV1_ENABLE_SSE4_1)
47    list(APPEND libgav1_defines "LIBGAV1_ENABLE_SSE4_1=1")
48  else()
49    list(APPEND libgav1_defines "LIBGAV1_ENABLE_SSE4_1=0")
50    set(libgav1_have_sse4 OFF)
51  endif()
52endmacro()
53