FFmpeg
cpu.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/cpu.h"
20 #include "libavutil/cpu_internal.h"
21 #include "config.h"
22 
23 #if (defined(__linux__) || defined(__ANDROID__)) && HAVE_GETAUXVAL
24 #include <stdint.h>
25 #include <sys/auxv.h>
26 
27 #define HWCAP_AARCH64_ASIMDDP (1 << 20)
28 #define HWCAP2_AARCH64_I8MM (1 << 13)
29 
30 static int detect_flags(void)
31 {
32  int flags = 0;
33 
34  unsigned long hwcap = getauxval(AT_HWCAP);
35  unsigned long hwcap2 = getauxval(AT_HWCAP2);
36 
37  if (hwcap & HWCAP_AARCH64_ASIMDDP)
39  if (hwcap2 & HWCAP2_AARCH64_I8MM)
41 
42  return flags;
43 }
44 
45 #elif defined(__APPLE__) && HAVE_SYSCTLBYNAME
46 #include <sys/sysctl.h>
47 
48 static int detect_flags(void)
49 {
50  uint32_t value = 0;
51  size_t size;
52  int flags = 0;
53 
54  size = sizeof(value);
55  if (!sysctlbyname("hw.optional.arm.FEAT_DotProd", &value, &size, NULL, 0)) {
56  if (value)
58  }
59  size = sizeof(value);
60  if (!sysctlbyname("hw.optional.arm.FEAT_I8MM", &value, &size, NULL, 0)) {
61  if (value)
63  }
64  return flags;
65 }
66 
67 #elif defined(__OpenBSD__)
68 #include <machine/armreg.h>
69 #include <machine/cpu.h>
70 #include <sys/types.h>
71 #include <sys/sysctl.h>
72 
73 static int detect_flags(void)
74 {
75  int flags = 0;
76 
77 #ifdef CPU_ID_AA64ISAR0
78  int mib[2];
79  uint64_t isar0;
80  uint64_t isar1;
81  size_t len;
82 
83  mib[0] = CTL_MACHDEP;
84  mib[1] = CPU_ID_AA64ISAR0;
85  len = sizeof(isar0);
86  if (sysctl(mib, 2, &isar0, &len, NULL, 0) != -1) {
87  if (ID_AA64ISAR0_DP(isar0) >= ID_AA64ISAR0_DP_IMPL)
89  }
90 
91  mib[0] = CTL_MACHDEP;
92  mib[1] = CPU_ID_AA64ISAR1;
93  len = sizeof(isar1);
94  if (sysctl(mib, 2, &isar1, &len, NULL, 0) != -1) {
95 #ifdef ID_AA64ISAR1_I8MM_IMPL
96  if (ID_AA64ISAR1_I8MM(isar1) >= ID_AA64ISAR1_I8MM_IMPL)
98 #endif
99  }
100 #endif
101 
102  return flags;
103 }
104 
105 #elif defined(_WIN32)
106 #include <windows.h>
107 
108 static int detect_flags(void)
109 {
110  int flags = 0;
111 #ifdef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE
112  if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE))
114 #endif
115  return flags;
116 }
117 #else
118 
119 static int detect_flags(void)
120 {
121  return 0;
122 }
123 
124 #endif
125 
127 {
128  int flags = AV_CPU_FLAG_ARMV8 * HAVE_ARMV8 |
129  AV_CPU_FLAG_NEON * HAVE_NEON;
130 
131 #ifdef __ARM_FEATURE_DOTPROD
133 #endif
134 #ifdef __ARM_FEATURE_MATMUL_INT8
136 #endif
137 
138  flags |= detect_flags();
139 
140  return flags;
141 }
142 
144 {
145  int flags = av_get_cpu_flags();
146 
147  if (flags & AV_CPU_FLAG_NEON)
148  return 16;
149 
150  return 8;
151 }
AV_CPU_FLAG_DOTPROD
#define AV_CPU_FLAG_DOTPROD
Definition: cpu.h:72
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
cpu_internal.h
ff_get_cpu_max_align_aarch64
size_t ff_get_cpu_max_align_aarch64(void)
Definition: cpu.c:143
NULL
#define NULL
Definition: coverity.c:32
ff_get_cpu_flags_aarch64
int ff_get_cpu_flags_aarch64(void)
Definition: cpu.c:126
detect_flags
static int detect_flags(void)
Definition: cpu.c:119
AV_CPU_FLAG_I8MM
#define AV_CPU_FLAG_I8MM
Definition: cpu.h:73
cpu.h
AV_CPU_FLAG_NEON
#define AV_CPU_FLAG_NEON
Definition: cpu.h:69
size
int size
Definition: twinvq_data.h:10344
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_CPU_FLAG_ARMV8
#define AV_CPU_FLAG_ARMV8
Definition: cpu.h:70
len
int len
Definition: vorbis_enc_data.h:426
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482