PipeWire: spa/support/cpu.h Source File

PipeWire 1.2.3

Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
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#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <stdarg.h>
13
14#include <spa/utils/defs.h>
15#include <spa/utils/hook.h>
16
29#define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
30
31#define SPA_VERSION_CPU 0
32struct spa_cpu { struct spa_interface iface; };
33
34/* x86 specific */
35#define SPA_CPU_FLAG_MMX (1<<0)
36#define SPA_CPU_FLAG_MMXEXT (1<<1)
37#define SPA_CPU_FLAG_3DNOW (1<<2)
38#define SPA_CPU_FLAG_SSE (1<<3)
39#define SPA_CPU_FLAG_SSE2 (1<<4)
40#define SPA_CPU_FLAG_3DNOWEXT (1<<5)
41#define SPA_CPU_FLAG_SSE3 (1<<6)
42#define SPA_CPU_FLAG_SSSE3 (1<<7)
43#define SPA_CPU_FLAG_SSE41 (1<<8)
44#define SPA_CPU_FLAG_SSE42 (1<<9)
45#define SPA_CPU_FLAG_AESNI (1<<10)
46#define SPA_CPU_FLAG_AVX (1<<11)
47#define SPA_CPU_FLAG_XOP (1<<12)
48#define SPA_CPU_FLAG_FMA4 (1<<13)
49#define SPA_CPU_FLAG_CMOV (1<<14)
50#define SPA_CPU_FLAG_AVX2 (1<<15)
51#define SPA_CPU_FLAG_FMA3 (1<<16)
52#define SPA_CPU_FLAG_BMI1 (1<<17)
53#define SPA_CPU_FLAG_BMI2 (1<<18)
54#define SPA_CPU_FLAG_AVX512 (1<<19)
55#define SPA_CPU_FLAG_SLOW_UNALIGNED (1<<20)
57/* PPC specific */
58#define SPA_CPU_FLAG_ALTIVEC (1<<0)
59#define SPA_CPU_FLAG_VSX (1<<1)
60#define SPA_CPU_FLAG_POWER8 (1<<2)
62/* ARM specific */
63#define SPA_CPU_FLAG_ARMV5TE (1 << 0)
64#define SPA_CPU_FLAG_ARMV6 (1 << 1)
65#define SPA_CPU_FLAG_ARMV6T2 (1 << 2)
66#define SPA_CPU_FLAG_VFP (1 << 3)
67#define SPA_CPU_FLAG_VFPV3 (1 << 4)
68#define SPA_CPU_FLAG_NEON (1 << 5)
69#define SPA_CPU_FLAG_ARMV8 (1 << 6)
70
71#define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
72
73#define SPA_CPU_VM_NONE (0)
74#define SPA_CPU_VM_OTHER (1 << 0)
75#define SPA_CPU_VM_KVM (1 << 1)
76#define SPA_CPU_VM_QEMU (1 << 2)
77#define SPA_CPU_VM_BOCHS (1 << 3)
78#define SPA_CPU_VM_XEN (1 << 4)
79#define SPA_CPU_VM_UML (1 << 5)
80#define SPA_CPU_VM_VMWARE (1 << 6)
81#define SPA_CPU_VM_ORACLE (1 << 7)
82#define SPA_CPU_VM_MICROSOFT (1 << 8)
83#define SPA_CPU_VM_ZVM (1 << 9)
84#define SPA_CPU_VM_PARALLELS (1 << 10)
85#define SPA_CPU_VM_BHYVE (1 << 11)
86#define SPA_CPU_VM_QNX (1 << 12)
87#define SPA_CPU_VM_ACRN (1 << 13)
88#define SPA_CPU_VM_POWERVM (1 << 14)
89
90static inline const char *spa_cpu_vm_type_to_string(uint32_t vm_type)
91{
92 switch(vm_type) {
93 case SPA_CPU_VM_NONE:
94 return NULL;
95 case SPA_CPU_VM_KVM:
96 return "kvm";
97 case SPA_CPU_VM_QEMU:
98 return "qemu";
99 case SPA_CPU_VM_BOCHS:
100 return "bochs";
101 case SPA_CPU_VM_XEN:
102 return "xen";
103 case SPA_CPU_VM_UML:
104 return "uml";
105 case SPA_CPU_VM_VMWARE:
106 return "vmware";
107 case SPA_CPU_VM_ORACLE:
108 return "oracle";
109 case SPA_CPU_VM_MICROSOFT:
110 return "microsoft";
111 case SPA_CPU_VM_ZVM:
112 return "zvm";
113 case SPA_CPU_VM_PARALLELS:
114 return "parallels";
115 case SPA_CPU_VM_BHYVE:
116 return "bhyve";
117 case SPA_CPU_VM_QNX:
118 return "qnx";
119 case SPA_CPU_VM_ACRN:
120 return "acrn";
121 case SPA_CPU_VM_POWERVM:
122 return "powervm";
123 case SPA_CPU_VM_OTHER:
124 return "other";
125 default:
126 return "unknown";
127 }
128}
129
133 struct spa_cpu_methods {
136#define SPA_VERSION_CPU_METHODS 2
137 uint32_t version;
138
140 uint32_t (*get_flags) (void *object);
141
143 int (*force_flags) (void *object, uint32_t flags);
144
146 uint32_t (*get_count) (void *object);
147
149 uint32_t (*get_max_align) (void *object);
150
151 /* check if running in a VM. Since:1 */
152 uint32_t (*get_vm_type) (void *object);
153
154 /* denormals will be handled as zero, either with FTZ or DAZ.
155 * Since:2 */
156 int (*zero_denormals) (void *object, bool enable);
157};
158
159#define spa_cpu_method(o,method,version,...) \
160({ \
161 int _res = -ENOTSUP; \
162 struct spa_cpu *_c = o; \
163 spa_interface_call_res(&_c->iface, \
164 struct spa_cpu_methods, _res, \
165 method, version, ##__VA_ARGS__); \
166 _res; \
167})
168#define spa_cpu_get_flags(c) spa_cpu_method(c, get_flags, 0)
169#define spa_cpu_force_flags(c,f) spa_cpu_method(c, force_flags, 0, f)
170#define spa_cpu_get_count(c) spa_cpu_method(c, get_count, 0)
171#define spa_cpu_get_max_align(c) spa_cpu_method(c, get_max_align, 0)
172#define spa_cpu_get_vm_type(c) spa_cpu_method(c, get_vm_type, 1)
173#define spa_cpu_zero_denormals(c,e) spa_cpu_method(c, zero_denormals, 2, e)
174
176#define SPA_KEY_CPU_FORCE "cpu.force"
177#define SPA_KEY_CPU_VM_TYPE "cpu.vm.type"
178#define SPA_KEY_CPU_ZERO_DENORMALS "cpu.zero.denormals"
184#ifdef __cplusplus
185} /* extern "C" */
186#endif
187
188#endif /* SPA_CPU_H */
defs.h
spa/utils/defs.h
SPA_CPU_VM_POWERVM
#define SPA_CPU_VM_POWERVM
Definition cpu.h:143
SPA_CPU_VM_OTHER
#define SPA_CPU_VM_OTHER
Definition cpu.h:115
SPA_CPU_VM_PARALLELS
#define SPA_CPU_VM_PARALLELS
Definition cpu.h:135
SPA_CPU_VM_QNX
#define SPA_CPU_VM_QNX
Definition cpu.h:139
SPA_CPU_VM_VMWARE
#define SPA_CPU_VM_VMWARE
Definition cpu.h:127
SPA_CPU_VM_ORACLE
#define SPA_CPU_VM_ORACLE
Definition cpu.h:129
SPA_CPU_VM_MICROSOFT
#define SPA_CPU_VM_MICROSOFT
Definition cpu.h:131
SPA_CPU_VM_XEN
#define SPA_CPU_VM_XEN
Definition cpu.h:123
SPA_CPU_VM_KVM
#define SPA_CPU_VM_KVM
Definition cpu.h:117
SPA_CPU_VM_ZVM
#define SPA_CPU_VM_ZVM
Definition cpu.h:133
SPA_CPU_VM_BHYVE
#define SPA_CPU_VM_BHYVE
Definition cpu.h:137
SPA_CPU_VM_UML
#define SPA_CPU_VM_UML
Definition cpu.h:125
SPA_CPU_VM_BOCHS
#define SPA_CPU_VM_BOCHS
Definition cpu.h:121
spa_cpu_vm_type_to_string
static const char * spa_cpu_vm_type_to_string(uint32_t vm_type)
Definition cpu.h:145
SPA_CPU_VM_NONE
#define SPA_CPU_VM_NONE
Definition cpu.h:113
SPA_CPU_VM_QEMU
#define SPA_CPU_VM_QEMU
Definition cpu.h:119
SPA_CPU_VM_ACRN
#define SPA_CPU_VM_ACRN
Definition cpu.h:141
hook.h
spa/utils/hook.h
spa_cpu_methods
methods
Definition cpu.h:188
spa_cpu_methods::get_max_align
uint32_t(* get_max_align)(void *object)
get maximum required alignment of data
Definition cpu.h:205
spa_cpu_methods::force_flags
int(* force_flags)(void *object, uint32_t flags)
force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags
Definition cpu.h:199
spa_cpu_methods::get_count
uint32_t(* get_count)(void *object)
get number of CPU cores
Definition cpu.h:202
spa_cpu_methods::get_flags
uint32_t(* get_flags)(void *object)
get CPU flags
Definition cpu.h:196
spa_cpu_methods::zero_denormals
int(* zero_denormals)(void *object, bool enable)
Definition cpu.h:212
spa_cpu_methods::get_vm_type
uint32_t(* get_vm_type)(void *object)
Definition cpu.h:208
spa_cpu_methods::version
uint32_t version
Definition cpu.h:193
spa_cpu
Definition cpu.h:39
spa_cpu::iface
struct spa_interface iface
Definition cpu.h:39
spa_interface
Definition hook.h:138