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_INTRINSICS_CMAKE_)
16  return()
17endif() # LIBGAV1_CMAKE_LIBGAV1_INTRINSICS_CMAKE_
18set(LIBGAV1_CMAKE_LIBGAV1_INTRINSICS_CMAKE_ 1)
19
20# Returns the compiler flag for the SIMD intrinsics suffix specified by the
21# SUFFIX argument via the variable specified by the VARIABLE argument:
22# libgav1_get_intrinsics_flag_for_suffix(SUFFIX <suffix> VARIABLE <var name>)
23macro(libgav1_get_intrinsics_flag_for_suffix)
24  unset(intrinsics_SUFFIX)
25  unset(intrinsics_VARIABLE)
26  unset(optional_args)
27  unset(multi_value_args)
28  set(single_value_args SUFFIX VARIABLE)
29  cmake_parse_arguments(intrinsics "${optional_args}" "${single_value_args}"
30                        "${multi_value_args}" ${ARGN})
31
32  if(NOT (intrinsics_SUFFIX AND intrinsics_VARIABLE))
33    message(FATAL_ERROR "libgav1_get_intrinsics_flag_for_suffix: SUFFIX and "
34                        "VARIABLE required.")
35  endif()
36
37  if(intrinsics_SUFFIX MATCHES "neon")
38    if(NOT MSVC)
39      set(${intrinsics_VARIABLE} "${LIBGAV1_NEON_INTRINSICS_FLAG}")
40    endif()
41  elseif(intrinsics_SUFFIX MATCHES "sse4")
42    if(NOT MSVC)
43      set(${intrinsics_VARIABLE} "-msse4.1")
44    endif()
45  else()
46    message(FATAL_ERROR "libgav1_get_intrinsics_flag_for_suffix: Unknown "
47                        "instrinics suffix: ${intrinsics_SUFFIX}")
48  endif()
49
50  if(LIBGAV1_VERBOSE GREATER 1)
51    message("libgav1_get_intrinsics_flag_for_suffix: "
52            "suffix:${intrinsics_SUFFIX} flag:${${intrinsics_VARIABLE}}")
53  endif()
54endmacro()
55
56# Processes source files specified by SOURCES and adds intrinsics flags as
57# necessary: libgav1_process_intrinsics_sources(SOURCES <sources>)
58#
59# Detects requirement for intrinsics flags using source file name suffix.
60# Currently supports only SSE4.1.
61macro(libgav1_process_intrinsics_sources)
62  unset(arg_TARGET)
63  unset(arg_SOURCES)
64  unset(optional_args)
65  set(single_value_args TARGET)
66  set(multi_value_args SOURCES)
67  cmake_parse_arguments(arg "${optional_args}" "${single_value_args}"
68                        "${multi_value_args}" ${ARGN})
69  if(NOT (arg_TARGET AND arg_SOURCES))
70    message(FATAL_ERROR "libgav1_process_intrinsics_sources: TARGET and "
71                        "SOURCES required.")
72  endif()
73
74  if(LIBGAV1_ENABLE_SSE4_1 AND libgav1_have_sse4)
75    unset(sse4_sources)
76    list(APPEND sse4_sources ${arg_SOURCES})
77
78    list(FILTER sse4_sources INCLUDE REGEX
79         "${libgav1_sse4_source_file_suffix}$")
80
81    if(sse4_sources)
82      unset(sse4_flags)
83      libgav1_get_intrinsics_flag_for_suffix(SUFFIX
84                                             ${libgav1_sse4_source_file_suffix}
85                                             VARIABLE sse4_flags)
86      if(sse4_flags)
87        libgav1_set_compiler_flags_for_sources(SOURCES ${sse4_sources} FLAGS
88                                               ${sse4_flags})
89      endif()
90    endif()
91  endif()
92
93  if(LIBGAV1_ENABLE_NEON AND libgav1_have_neon)
94    unset(neon_sources)
95    list(APPEND neon_sources ${arg_SOURCES})
96    list(FILTER neon_sources INCLUDE REGEX
97         "${libgav1_neon_source_file_suffix}$")
98
99    if(neon_sources AND LIBGAV1_NEON_INTRINSICS_FLAG)
100      unset(neon_flags)
101      libgav1_get_intrinsics_flag_for_suffix(SUFFIX
102                                             ${libgav1_neon_source_file_suffix}
103                                             VARIABLE neon_flags)
104      if(neon_flags)
105        libgav1_set_compiler_flags_for_sources(SOURCES ${neon_sources} FLAGS
106                                               ${neon_flags})
107      endif()
108    endif()
109  endif()
110endmacro()
111