2023-02-08 18:12:00 +01:00
|
|
|
/* Simple Plugin API */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#ifndef SPA_CPU_H
|
|
|
|
|
#define SPA_CPU_H
|
2018-12-17 13:23:51 +01:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
#include <spa/utils/defs.h>
|
2019-05-20 16:11:23 +02:00
|
|
|
#include <spa/utils/hook.h>
|
|
|
|
|
|
2021-10-02 20:55:53 +03:00
|
|
|
/** \defgroup spa_cpu CPU
|
2021-10-04 00:00:41 +03:00
|
|
|
* Querying CPU properties
|
2021-05-21 14:03:07 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2021-10-02 20:55:53 +03:00
|
|
|
* \addtogroup spa_cpu
|
2021-05-21 14:03:07 +10:00
|
|
|
* \{
|
|
|
|
|
*/
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
/**
|
|
|
|
|
* The CPU features interface
|
|
|
|
|
*/
|
2019-12-19 13:15:10 +01:00
|
|
|
#define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
|
|
|
|
|
|
|
|
|
|
#define SPA_VERSION_CPU 0
|
2019-05-20 16:11:23 +02:00
|
|
|
struct spa_cpu { struct spa_interface iface; };
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-03-28 13:26:06 +01:00
|
|
|
/* x86 specific */
|
|
|
|
|
#define SPA_CPU_FLAG_MMX (1<<0) /**< standard MMX */
|
|
|
|
|
#define SPA_CPU_FLAG_MMXEXT (1<<1) /**< SSE integer or AMD MMX ext */
|
|
|
|
|
#define SPA_CPU_FLAG_3DNOW (1<<2) /**< AMD 3DNOW */
|
|
|
|
|
#define SPA_CPU_FLAG_SSE (1<<3) /**< SSE */
|
|
|
|
|
#define SPA_CPU_FLAG_SSE2 (1<<4) /**< SSE2 */
|
|
|
|
|
#define SPA_CPU_FLAG_3DNOWEXT (1<<5) /**< AMD 3DNowExt */
|
|
|
|
|
#define SPA_CPU_FLAG_SSE3 (1<<6) /**< Prescott SSE3 */
|
|
|
|
|
#define SPA_CPU_FLAG_SSSE3 (1<<7) /**< Conroe SSSE3 */
|
|
|
|
|
#define SPA_CPU_FLAG_SSE41 (1<<8) /**< Penryn SSE4.1 */
|
|
|
|
|
#define SPA_CPU_FLAG_SSE42 (1<<9) /**< Nehalem SSE4.2 */
|
|
|
|
|
#define SPA_CPU_FLAG_AESNI (1<<10) /**< Advanced Encryption Standard */
|
|
|
|
|
#define SPA_CPU_FLAG_AVX (1<<11) /**< AVX */
|
|
|
|
|
#define SPA_CPU_FLAG_XOP (1<<12) /**< Bulldozer XOP */
|
|
|
|
|
#define SPA_CPU_FLAG_FMA4 (1<<13) /**< Bulldozer FMA4 */
|
|
|
|
|
#define SPA_CPU_FLAG_CMOV (1<<14) /**< supports cmov */
|
|
|
|
|
#define SPA_CPU_FLAG_AVX2 (1<<15) /**< AVX2 */
|
|
|
|
|
#define SPA_CPU_FLAG_FMA3 (1<<16) /**< Haswell FMA3 */
|
|
|
|
|
#define SPA_CPU_FLAG_BMI1 (1<<17) /**< Bit Manipulation Instruction Set 1 */
|
|
|
|
|
#define SPA_CPU_FLAG_BMI2 (1<<18) /**< Bit Manipulation Instruction Set 2 */
|
|
|
|
|
#define SPA_CPU_FLAG_AVX512 (1<<19) /**< AVX-512 */
|
|
|
|
|
#define SPA_CPU_FLAG_SLOW_UNALIGNED (1<<20) /**< unaligned loads/stores are slow */
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-03-28 13:26:06 +01:00
|
|
|
/* PPC specific */
|
|
|
|
|
#define SPA_CPU_FLAG_ALTIVEC (1<<0) /**< standard */
|
|
|
|
|
#define SPA_CPU_FLAG_VSX (1<<1) /**< ISA 2.06 */
|
|
|
|
|
#define SPA_CPU_FLAG_POWER8 (1<<2) /**< ISA 2.07 */
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-03-28 13:26:06 +01:00
|
|
|
/* ARM specific */
|
|
|
|
|
#define SPA_CPU_FLAG_ARMV5TE (1 << 0)
|
|
|
|
|
#define SPA_CPU_FLAG_ARMV6 (1 << 1)
|
|
|
|
|
#define SPA_CPU_FLAG_ARMV6T2 (1 << 2)
|
|
|
|
|
#define SPA_CPU_FLAG_VFP (1 << 3)
|
|
|
|
|
#define SPA_CPU_FLAG_VFPV3 (1 << 4)
|
|
|
|
|
#define SPA_CPU_FLAG_NEON (1 << 5)
|
|
|
|
|
#define SPA_CPU_FLAG_ARMV8 (1 << 6)
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-01-07 15:02:18 +01:00
|
|
|
#define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
|
2021-04-16 16:39:35 +02:00
|
|
|
|
|
|
|
|
#define SPA_CPU_VM_NONE (0)
|
|
|
|
|
#define SPA_CPU_VM_OTHER (1 << 0)
|
|
|
|
|
#define SPA_CPU_VM_KVM (1 << 1)
|
|
|
|
|
#define SPA_CPU_VM_QEMU (1 << 2)
|
|
|
|
|
#define SPA_CPU_VM_BOCHS (1 << 3)
|
|
|
|
|
#define SPA_CPU_VM_XEN (1 << 4)
|
|
|
|
|
#define SPA_CPU_VM_UML (1 << 5)
|
|
|
|
|
#define SPA_CPU_VM_VMWARE (1 << 6)
|
|
|
|
|
#define SPA_CPU_VM_ORACLE (1 << 7)
|
|
|
|
|
#define SPA_CPU_VM_MICROSOFT (1 << 8)
|
|
|
|
|
#define SPA_CPU_VM_ZVM (1 << 9)
|
|
|
|
|
#define SPA_CPU_VM_PARALLELS (1 << 10)
|
|
|
|
|
#define SPA_CPU_VM_BHYVE (1 << 11)
|
|
|
|
|
#define SPA_CPU_VM_QNX (1 << 12)
|
|
|
|
|
#define SPA_CPU_VM_ACRN (1 << 13)
|
|
|
|
|
#define SPA_CPU_VM_POWERVM (1 << 14)
|
|
|
|
|
|
2024-03-15 11:55:18 +01:00
|
|
|
static inline const char *spa_cpu_vm_type_to_string(uint32_t vm_type)
|
|
|
|
|
{
|
|
|
|
|
switch(vm_type) {
|
|
|
|
|
case SPA_CPU_VM_NONE:
|
|
|
|
|
return NULL;
|
|
|
|
|
case SPA_CPU_VM_KVM:
|
|
|
|
|
return "kvm";
|
|
|
|
|
case SPA_CPU_VM_QEMU:
|
|
|
|
|
return "qemu";
|
|
|
|
|
case SPA_CPU_VM_BOCHS:
|
|
|
|
|
return "bochs";
|
|
|
|
|
case SPA_CPU_VM_XEN:
|
|
|
|
|
return "xen";
|
|
|
|
|
case SPA_CPU_VM_UML:
|
|
|
|
|
return "uml";
|
|
|
|
|
case SPA_CPU_VM_VMWARE:
|
|
|
|
|
return "vmware";
|
|
|
|
|
case SPA_CPU_VM_ORACLE:
|
|
|
|
|
return "oracle";
|
|
|
|
|
case SPA_CPU_VM_MICROSOFT:
|
|
|
|
|
return "microsoft";
|
|
|
|
|
case SPA_CPU_VM_ZVM:
|
|
|
|
|
return "zvm";
|
|
|
|
|
case SPA_CPU_VM_PARALLELS:
|
|
|
|
|
return "parallels";
|
|
|
|
|
case SPA_CPU_VM_BHYVE:
|
|
|
|
|
return "bhyve";
|
|
|
|
|
case SPA_CPU_VM_QNX:
|
|
|
|
|
return "qnx";
|
|
|
|
|
case SPA_CPU_VM_ACRN:
|
|
|
|
|
return "acrn";
|
|
|
|
|
case SPA_CPU_VM_POWERVM:
|
|
|
|
|
return "powervm";
|
|
|
|
|
case SPA_CPU_VM_OTHER:
|
|
|
|
|
return "other";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 13:23:51 +01:00
|
|
|
/**
|
2019-05-20 16:11:23 +02:00
|
|
|
* methods
|
2018-12-17 13:23:51 +01:00
|
|
|
*/
|
2019-05-20 16:11:23 +02:00
|
|
|
struct spa_cpu_methods {
|
|
|
|
|
/** the version of the methods. This can be used to expand this
|
2018-12-17 13:23:51 +01:00
|
|
|
structure in the future */
|
2021-10-11 14:54:48 +02:00
|
|
|
#define SPA_VERSION_CPU_METHODS 2
|
2018-12-17 13:23:51 +01:00
|
|
|
uint32_t version;
|
|
|
|
|
|
|
|
|
|
/** get CPU flags */
|
2019-05-20 16:11:23 +02:00
|
|
|
uint32_t (*get_flags) (void *object);
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-01-07 15:02:18 +01:00
|
|
|
/** force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags */
|
2019-05-20 16:11:23 +02:00
|
|
|
int (*force_flags) (void *object, uint32_t flags);
|
2019-01-07 15:02:18 +01:00
|
|
|
|
2018-12-17 13:23:51 +01:00
|
|
|
/** get number of CPU cores */
|
2019-05-20 16:11:23 +02:00
|
|
|
uint32_t (*get_count) (void *object);
|
2018-12-17 13:23:51 +01:00
|
|
|
|
|
|
|
|
/** get maximum required alignment of data */
|
2019-05-20 16:11:23 +02:00
|
|
|
uint32_t (*get_max_align) (void *object);
|
2021-04-16 16:39:35 +02:00
|
|
|
|
|
|
|
|
/* check if running in a VM. Since:1 */
|
|
|
|
|
uint32_t (*get_vm_type) (void *object);
|
2021-10-11 14:54:48 +02:00
|
|
|
|
|
|
|
|
/* denormals will be handled as zero, either with FTZ or DAZ.
|
|
|
|
|
* Since:2 */
|
|
|
|
|
int (*zero_denormals) (void *object, bool enable);
|
2018-12-17 13:23:51 +01:00
|
|
|
};
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
#define spa_cpu_method(o,method,version,...) \
|
|
|
|
|
({ \
|
|
|
|
|
int _res = -ENOTSUP; \
|
|
|
|
|
struct spa_cpu *_c = o; \
|
|
|
|
|
spa_interface_call_res(&_c->iface, \
|
|
|
|
|
struct spa_cpu_methods, _res, \
|
|
|
|
|
method, version, ##__VA_ARGS__); \
|
|
|
|
|
_res; \
|
|
|
|
|
})
|
|
|
|
|
#define spa_cpu_get_flags(c) spa_cpu_method(c, get_flags, 0)
|
|
|
|
|
#define spa_cpu_force_flags(c,f) spa_cpu_method(c, force_flags, 0, f)
|
|
|
|
|
#define spa_cpu_get_count(c) spa_cpu_method(c, get_count, 0)
|
|
|
|
|
#define spa_cpu_get_max_align(c) spa_cpu_method(c, get_max_align, 0)
|
2021-04-16 16:39:35 +02:00
|
|
|
#define spa_cpu_get_vm_type(c) spa_cpu_method(c, get_vm_type, 1)
|
2021-10-11 14:54:48 +02:00
|
|
|
#define spa_cpu_zero_denormals(c,e) spa_cpu_method(c, zero_denormals, 2, e)
|
2018-12-17 13:23:51 +01:00
|
|
|
|
2019-06-06 15:11:37 +02:00
|
|
|
/** keys can be given when initializing the cpu handle */
|
|
|
|
|
#define SPA_KEY_CPU_FORCE "cpu.force" /**< force cpu flags */
|
2021-04-16 16:41:20 +02:00
|
|
|
#define SPA_KEY_CPU_VM_TYPE "cpu.vm.type" /**< force a VM type */
|
2021-10-11 14:54:48 +02:00
|
|
|
#define SPA_KEY_CPU_ZERO_DENORMALS "cpu.zero.denormals" /**< zero denormals */
|
2019-06-06 15:11:37 +02:00
|
|
|
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \}
|
|
|
|
|
*/
|
|
|
|
|
|
2018-12-17 13:23:51 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
} /* extern "C" */
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#endif /* SPA_CPU_H */
|