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 "avx2") 42 if(MSVC) 43 set(${intrinsics_VARIABLE} "/arch:AVX2") 44 else() 45 set(${intrinsics_VARIABLE} "-mavx2") 46 endif() 47 elseif(intrinsics_SUFFIX MATCHES "sse4") 48 if(NOT MSVC) 49 set(${intrinsics_VARIABLE} "-msse4.1") 50 endif() 51 else() 52 message(FATAL_ERROR "libgav1_get_intrinsics_flag_for_suffix: Unknown " 53 "instrinics suffix: ${intrinsics_SUFFIX}") 54 endif() 55 56 if(LIBGAV1_VERBOSE GREATER 1) 57 message("libgav1_get_intrinsics_flag_for_suffix: " 58 "suffix:${intrinsics_SUFFIX} flag:${${intrinsics_VARIABLE}}") 59 endif() 60endmacro() 61 62# Processes source files specified by SOURCES and adds intrinsics flags as 63# necessary: libgav1_process_intrinsics_sources(SOURCES <sources>) 64# 65# Detects requirement for intrinsics flags using source file name suffix. 66# Currently supports AVX2 and SSE4.1. 67macro(libgav1_process_intrinsics_sources) 68 unset(arg_TARGET) 69 unset(arg_SOURCES) 70 unset(optional_args) 71 set(single_value_args TARGET) 72 set(multi_value_args SOURCES) 73 cmake_parse_arguments(arg "${optional_args}" "${single_value_args}" 74 "${multi_value_args}" ${ARGN}) 75 if(NOT (arg_TARGET AND arg_SOURCES)) 76 message(FATAL_ERROR "libgav1_process_intrinsics_sources: TARGET and " 77 "SOURCES required.") 78 endif() 79 80 if(LIBGAV1_ENABLE_AVX2 AND libgav1_have_avx2) 81 unset(avx2_sources) 82 list(APPEND avx2_sources ${arg_SOURCES}) 83 84 list(FILTER avx2_sources INCLUDE REGEX 85 "${libgav1_avx2_source_file_suffix}$") 86 87 if(avx2_sources) 88 unset(avx2_flags) 89 libgav1_get_intrinsics_flag_for_suffix(SUFFIX 90 ${libgav1_avx2_source_file_suffix} 91 VARIABLE avx2_flags) 92 if(avx2_flags) 93 libgav1_set_compiler_flags_for_sources(SOURCES ${avx2_sources} FLAGS 94 ${avx2_flags}) 95 endif() 96 endif() 97 endif() 98 99 if(LIBGAV1_ENABLE_SSE4_1 AND libgav1_have_sse4) 100 unset(sse4_sources) 101 list(APPEND sse4_sources ${arg_SOURCES}) 102 103 list(FILTER sse4_sources INCLUDE REGEX 104 "${libgav1_sse4_source_file_suffix}$") 105 106 if(sse4_sources) 107 unset(sse4_flags) 108 libgav1_get_intrinsics_flag_for_suffix(SUFFIX 109 ${libgav1_sse4_source_file_suffix} 110 VARIABLE sse4_flags) 111 if(sse4_flags) 112 libgav1_set_compiler_flags_for_sources(SOURCES ${sse4_sources} FLAGS 113 ${sse4_flags}) 114 endif() 115 endif() 116 endif() 117 118 if(LIBGAV1_ENABLE_NEON AND libgav1_have_neon) 119 unset(neon_sources) 120 list(APPEND neon_sources ${arg_SOURCES}) 121 list(FILTER neon_sources INCLUDE REGEX 122 "${libgav1_neon_source_file_suffix}$") 123 124 if(neon_sources AND LIBGAV1_NEON_INTRINSICS_FLAG) 125 unset(neon_flags) 126 libgav1_get_intrinsics_flag_for_suffix(SUFFIX 127 ${libgav1_neon_source_file_suffix} 128 VARIABLE neon_flags) 129 if(neon_flags) 130 libgav1_set_compiler_flags_for_sources(SOURCES ${neon_sources} FLAGS 131 ${neon_flags}) 132 endif() 133 endif() 134 endif() 135endmacro() 136