+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
c · 209 lines · 5.8 KB · SPDX: MIT
main
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4  
5 #ifndef SPA_CPU_H
6 #define SPA_CPU_H
7  
8 #include <stdarg.h>
9 #include <errno.h>
10  
11 #include <spa/utils/defs.h>
12 #include <spa/utils/hook.h>
13  
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17  
18 #ifndef SPA_API_CPU
19 #ifdef SPA_API_IMPL
20 #define SPA_API_CPU SPA_API_IMPL
21 #else
22 #define SPA_API_CPU static inline
23 #endif
24 #endif
25  
26 /** \defgroup spa_cpu CPU
27 * Querying CPU properties
28 */
29  
30 /**
31 * \addtogroup spa_cpu
32 * \{
33 */
34  
35 /**
36 * The CPU features interface
37 */
38 #define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
39  
40 #define SPA_VERSION_CPU 0
41 struct spa_cpu { struct spa_interface iface; };
42  
43 /* x86 specific */
44 #define SPA_CPU_FLAG_MMX (1<<0) /**< standard MMX */
45 #define SPA_CPU_FLAG_MMXEXT (1<<1) /**< SSE integer or AMD MMX ext */
46 #define SPA_CPU_FLAG_3DNOW (1<<2) /**< AMD 3DNOW */
47 #define SPA_CPU_FLAG_SSE (1<<3) /**< SSE */
48 #define SPA_CPU_FLAG_SSE2 (1<<4) /**< SSE2 */
49 #define SPA_CPU_FLAG_3DNOWEXT (1<<5) /**< AMD 3DNowExt */
50 #define SPA_CPU_FLAG_SSE3 (1<<6) /**< Prescott SSE3 */
51 #define SPA_CPU_FLAG_SSSE3 (1<<7) /**< Conroe SSSE3 */
52 #define SPA_CPU_FLAG_SSE41 (1<<8) /**< Penryn SSE4.1 */
53 #define SPA_CPU_FLAG_SSE42 (1<<9) /**< Nehalem SSE4.2 */
54 #define SPA_CPU_FLAG_AESNI (1<<10) /**< Advanced Encryption Standard */
55 #define SPA_CPU_FLAG_AVX (1<<11) /**< AVX */
56 #define SPA_CPU_FLAG_XOP (1<<12) /**< Bulldozer XOP */
57 #define SPA_CPU_FLAG_FMA4 (1<<13) /**< Bulldozer FMA4 */
58 #define SPA_CPU_FLAG_CMOV (1<<14) /**< supports cmov */
59 #define SPA_CPU_FLAG_AVX2 (1<<15) /**< AVX2 */
60 #define SPA_CPU_FLAG_FMA3 (1<<16) /**< Haswell FMA3 */
61 #define SPA_CPU_FLAG_BMI1 (1<<17) /**< Bit Manipulation Instruction Set 1 */
62 #define SPA_CPU_FLAG_BMI2 (1<<18) /**< Bit Manipulation Instruction Set 2 */
63 #define SPA_CPU_FLAG_AVX512 (1<<19) /**< AVX-512 */
64 #define SPA_CPU_FLAG_SLOW_UNALIGNED (1<<20) /**< unaligned loads/stores are slow */
65  
66 /* PPC specific */
67 #define SPA_CPU_FLAG_ALTIVEC (1<<0) /**< standard */
68 #define SPA_CPU_FLAG_VSX (1<<1) /**< ISA 2.06 */
69 #define SPA_CPU_FLAG_POWER8 (1<<2) /**< ISA 2.07 */
70  
71 /* ARM specific */
72 #define SPA_CPU_FLAG_ARMV5TE (1 << 0)
73 #define SPA_CPU_FLAG_ARMV6 (1 << 1)
74 #define SPA_CPU_FLAG_ARMV6T2 (1 << 2)
75 #define SPA_CPU_FLAG_VFP (1 << 3)
76 #define SPA_CPU_FLAG_VFPV3 (1 << 4)
77 #define SPA_CPU_FLAG_NEON (1 << 5)
78 #define SPA_CPU_FLAG_ARMV8 (1 << 6)
79  
80 /* RISCV specific */
81 #define SPA_CPU_FLAG_RISCV_V (1 << 0)
82  
83 #define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
84  
85 #define SPA_CPU_VM_NONE (0)
86 #define SPA_CPU_VM_OTHER (1 << 0)
87 #define SPA_CPU_VM_KVM (1 << 1)
88 #define SPA_CPU_VM_QEMU (1 << 2)
89 #define SPA_CPU_VM_BOCHS (1 << 3)
90 #define SPA_CPU_VM_XEN (1 << 4)
91 #define SPA_CPU_VM_UML (1 << 5)
92 #define SPA_CPU_VM_VMWARE (1 << 6)
93 #define SPA_CPU_VM_ORACLE (1 << 7)
94 #define SPA_CPU_VM_MICROSOFT (1 << 8)
95 #define SPA_CPU_VM_ZVM (1 << 9)
96 #define SPA_CPU_VM_PARALLELS (1 << 10)
97 #define SPA_CPU_VM_BHYVE (1 << 11)
98 #define SPA_CPU_VM_QNX (1 << 12)
99 #define SPA_CPU_VM_ACRN (1 << 13)
100 #define SPA_CPU_VM_POWERVM (1 << 14)
101  
102 SPA_API_CPU const char *spa_cpu_vm_type_to_string(uint32_t vm_type)
103 {
104 switch(vm_type) {
105 case SPA_CPU_VM_NONE:
106 return NULL;
107 case SPA_CPU_VM_KVM:
108 return "kvm";
109 case SPA_CPU_VM_QEMU:
110 return "qemu";
111 case SPA_CPU_VM_BOCHS:
112 return "bochs";
113 case SPA_CPU_VM_XEN:
114 return "xen";
115 case SPA_CPU_VM_UML:
116 return "uml";
117 case SPA_CPU_VM_VMWARE:
118 return "vmware";
119 case SPA_CPU_VM_ORACLE:
120 return "oracle";
121 case SPA_CPU_VM_MICROSOFT:
122 return "microsoft";
123 case SPA_CPU_VM_ZVM:
124 return "zvm";
125 case SPA_CPU_VM_PARALLELS:
126 return "parallels";
127 case SPA_CPU_VM_BHYVE:
128 return "bhyve";
129 case SPA_CPU_VM_QNX:
130 return "qnx";
131 case SPA_CPU_VM_ACRN:
132 return "acrn";
133 case SPA_CPU_VM_POWERVM:
134 return "powervm";
135 case SPA_CPU_VM_OTHER:
136 return "other";
137 default:
138 return "unknown";
139 }
140 }
141  
142 /**
143 * methods
144 */
145 struct spa_cpu_methods {
146 /** the version of the methods. This can be used to expand this
147 structure in the future */
148 #define SPA_VERSION_CPU_METHODS 2
149 uint32_t version;
150  
151 /** get CPU flags */
152 uint32_t (*get_flags) (void *object);
153  
154 /** force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags */
155 int (*force_flags) (void *object, uint32_t flags);
156  
157 /** get number of CPU cores */
158 uint32_t (*get_count) (void *object);
159  
160 /** get maximum required alignment of data */
161 uint32_t (*get_max_align) (void *object);
162  
163 /* check if running in a VM. Since:1 */
164 uint32_t (*get_vm_type) (void *object);
165  
166 /* denormals will be handled as zero, either with FTZ or DAZ.
167 * Since:2 */
168 int (*zero_denormals) (void *object, bool enable);
169 };
170  
171 SPA_API_CPU uint32_t spa_cpu_get_flags(struct spa_cpu *c)
172 {
173 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_flags, 0);
174 }
175 SPA_API_CPU int spa_cpu_force_flags(struct spa_cpu *c, uint32_t flags)
176 {
177 return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, force_flags, 0, flags);
178 }
179 SPA_API_CPU uint32_t spa_cpu_get_count(struct spa_cpu *c)
180 {
181 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_count, 0);
182 }
183 SPA_API_CPU uint32_t spa_cpu_get_max_align(struct spa_cpu *c)
184 {
185 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_max_align, 0);
186 }
187 SPA_API_CPU uint32_t spa_cpu_get_vm_type(struct spa_cpu *c)
188 {
189 return spa_api_method_r(uint32_t, 0, spa_cpu, &c->iface, get_vm_type, 1);
190 }
191 SPA_API_CPU int spa_cpu_zero_denormals(struct spa_cpu *c, bool enable)
192 {
193 return spa_api_method_r(int, -ENOTSUP, spa_cpu, &c->iface, zero_denormals, 2, enable);
194 }
195  
196 /** keys can be given when initializing the cpu handle */
197 #define SPA_KEY_CPU_FORCE "cpu.force" /**< force cpu flags */
198 #define SPA_KEY_CPU_VM_TYPE "cpu.vm.type" /**< force a VM type */
199 #define SPA_KEY_CPU_ZERO_DENORMALS "cpu.zero.denormals" /**< zero denormals */
200  
201 /**
202 * \}
203 */
204  
205 #ifdef __cplusplus
206 } /* extern "C" */
207 #endif
208  
209 #endif /* SPA_CPU_H */