cpu.h (4521B)
1 /* 2 * Copyright © 2018-2022, VideoLAN and dav1d authors 3 * Copyright © 2018-2022, Two Orioles, LLC 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice, this 10 * list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef DAV1D_SRC_CPU_H 29 #define DAV1D_SRC_CPU_H 30 31 #include "config.h" 32 33 #include "common/attributes.h" 34 35 #include "dav1d/common.h" 36 #include "dav1d/dav1d.h" 37 38 #if ARCH_AARCH64 || ARCH_ARM 39 #include "src/arm/cpu.h" 40 #elif ARCH_LOONGARCH 41 #include "src/loongarch/cpu.h" 42 #elif ARCH_PPC64LE 43 #include "src/ppc/cpu.h" 44 #elif ARCH_RISCV 45 #include "src/riscv/cpu.h" 46 #elif ARCH_X86 47 #include "src/x86/cpu.h" 48 #endif 49 50 EXTERN unsigned dav1d_cpu_flags; 51 EXTERN unsigned dav1d_cpu_flags_mask; 52 53 void dav1d_init_cpu(void); 54 DAV1D_API void dav1d_set_cpu_flags_mask(unsigned mask); 55 int dav1d_num_logical_processors(Dav1dContext *c); 56 unsigned long dav1d_getauxval(unsigned long); 57 58 static ALWAYS_INLINE unsigned dav1d_get_default_cpu_flags(void) { 59 unsigned flags = 0; 60 61 #if ARCH_AARCH64 || ARCH_ARM 62 #if defined(__ARM_NEON) || defined(__APPLE__) || defined(_WIN32) || ARCH_AARCH64 63 flags |= DAV1D_ARM_CPU_FLAG_NEON; 64 #endif 65 #ifdef __ARM_FEATURE_DOTPROD 66 flags |= DAV1D_ARM_CPU_FLAG_DOTPROD; 67 #endif 68 #ifdef __ARM_FEATURE_MATMUL_INT8 69 flags |= DAV1D_ARM_CPU_FLAG_I8MM; 70 #endif 71 #if ARCH_AARCH64 72 #ifdef __ARM_FEATURE_SVE 73 flags |= DAV1D_ARM_CPU_FLAG_SVE; 74 #endif 75 #ifdef __ARM_FEATURE_SVE2 76 flags |= DAV1D_ARM_CPU_FLAG_SVE2; 77 #endif 78 #endif /* ARCH_AARCH64 */ 79 #elif ARCH_PPC64LE 80 #if defined(__VSX__) 81 flags |= DAV1D_PPC_CPU_FLAG_VSX; 82 #endif 83 #if defined(__POWER9_VECTOR__) 84 flags |= DAV1D_PPC_CPU_FLAG_PWR9; 85 #endif 86 #elif ARCH_RISCV 87 #if defined(__riscv_v) 88 flags |= DAV1D_RISCV_CPU_FLAG_V; 89 #endif 90 #elif ARCH_X86 91 #if defined(__AVX512F__) && defined(__AVX512CD__) && \ 92 defined(__AVX512BW__) && defined(__AVX512DQ__) && \ 93 defined(__AVX512VL__) && defined(__AVX512VNNI__) && \ 94 defined(__AVX512IFMA__) && defined(__AVX512VBMI__) && \ 95 defined(__AVX512VBMI2__) && defined(__AVX512VPOPCNTDQ__) && \ 96 defined(__AVX512BITALG__) && defined(__GFNI__) && \ 97 defined(__VAES__) && defined(__VPCLMULQDQ__) 98 flags |= DAV1D_X86_CPU_FLAG_AVX512ICL | 99 DAV1D_X86_CPU_FLAG_AVX2 | 100 DAV1D_X86_CPU_FLAG_SSE41 | 101 DAV1D_X86_CPU_FLAG_SSSE3 | 102 DAV1D_X86_CPU_FLAG_SSE2; 103 #elif defined(__AVX2__) 104 flags |= DAV1D_X86_CPU_FLAG_AVX2 | 105 DAV1D_X86_CPU_FLAG_SSE41 | 106 DAV1D_X86_CPU_FLAG_SSSE3 | 107 DAV1D_X86_CPU_FLAG_SSE2; 108 #elif defined(__SSE4_1__) || defined(__AVX__) 109 flags |= DAV1D_X86_CPU_FLAG_SSE41 | 110 DAV1D_X86_CPU_FLAG_SSSE3 | 111 DAV1D_X86_CPU_FLAG_SSE2; 112 #elif defined(__SSSE3__) 113 flags |= DAV1D_X86_CPU_FLAG_SSSE3 | 114 DAV1D_X86_CPU_FLAG_SSE2; 115 #elif ARCH_X86_64 || defined(__SSE2__) || \ 116 (defined(_M_IX86_FP) && _M_IX86_FP >= 2) 117 flags |= DAV1D_X86_CPU_FLAG_SSE2; 118 #endif 119 #endif 120 121 return flags; 122 } 123 124 static ALWAYS_INLINE unsigned dav1d_get_cpu_flags(void) { 125 unsigned flags = dav1d_cpu_flags & dav1d_cpu_flags_mask; 126 127 #if TRIM_DSP_FUNCTIONS 128 /* Since this function is inlined, unconditionally setting a flag here will 129 * enable dead code elimination in the calling function. */ 130 flags |= dav1d_get_default_cpu_flags(); 131 #endif 132 133 return flags; 134 } 135 136 #endif /* DAV1D_SRC_CPU_H */