include/vecmat/cpu.h file

Compiled / runtime / selected ISA bits and vm_cpu_* probes.

Enums

enum (anonymous) { VM_CPU_SCALAR = 1u << 0, VM_CPU_BACKEND = 1u << 1, VM_CPU_AVX = 1u << 4, VM_CPU_AVX2 = 1u << 5, VM_CPU_AVX512F = 1u << 6, VM_CPU_FMA = 1u << 10, VM_CPU_F16C = 1u << 11, VM_CPU_AVX512BW = 1u << 12, VM_CPU_AVX512VL = 1u << 13, VM_CPU_AVX512BF16 = 1u << 14, VM_CPU_NEON = 1u << 16, VM_CPU_SVE = 1u << 17, VM_CPU_SVE2 = 1u << 18, VM_CPU_ARM_FP16 = 1u << 21, VM_CPU_ARM_BF16 = 1u << 22, VM_CPU_I8MM = 1u << 23 }

Typedefs

using vm_cpu_features_t = uint32_t
Bit mask of compiled or detected CPU ISA features.

Functions

auto vm_cpu_compiled_features(void) -> vm_cpu_features_t
ISA bits compiled into this library (VECMAT_ENABLE_*).
auto vm_cpu_runtime_features(void) -> vm_cpu_features_t
ISA bits detected on this CPU (runtime probe).
auto vm_cpu_selected_features(void) -> vm_cpu_features_t
ISA the picker bound: registered backend, else best compiled-and-runtime.
static auto vm_cpu_has(const vm_cpu_features_t need) -> int
Non-zero when this CPU has every bit in need (a bit or a level).
auto vm_cpu_name(vm_cpu_features_t features) -> const char*
Short name for a feature mask (avx2, neon, scalar, etc.).
void vm_cpu_init(void)
Probe once and bind dispatched _ptr names.
auto vm_cpu_note(void) -> const char*
Optional one-line note set by a registered module.
void vm_cpu_set_note(const char* note)
Attach a module note for banners.
auto vm_compiled_float_bits(void) -> unsigned
Float widths compiled into this library (32, 64, or 32|64).
static auto vm_abi_mismatch(void) -> int
Non-zero when this TU's VECMAT_FLOAT_BITS is missing from the linked lib.

Family masks

Every defined bit lies in exactly one family.

#define VM_CPU_GENERIC_MASK
#define VM_CPU_X86_MASK
#define VM_CPU_ARM_MASK
#define VM_CPU_RISCV_MASK

Dispatch levels

Feature bits a kernel file was compiled to need.

Bits are probed facts; a level is the set that must all be present before its code may run. Files built with -mfma use a level that includes VM_CPU_FMA, except AVX-512, where FMA is implied.

#define VM_LEVEL_AVX
#define VM_LEVEL_AVX2
#define VM_LEVEL_AVX512
#define VM_LEVEL_NEON
#define VM_LEVEL_SVE
#define VM_LEVEL_SVE2

Enum documentation

enum (anonymous)

Enumerators
VM_CPU_SCALAR

VM_CPU_BACKEND

VM_CPU_AVX

VM_CPU_AVX2

VM_CPU_AVX512F

VM_CPU_FMA

x86 FMA3 (vfmadd*) with usable YMM state.

Not a tier of its own: the AVX2 and AVX-512F tiers are built with -mfma. AVX2 is selected only when this bit is also present; AVX-512F implies it. Never returned by vm_cpu_selected_features().

VM_CPU_F16C

x86 F16C (FP16 conversion, vcvtph2ps / vcvtps2ph).

A feature, not a tier. Probed; the intel/fp16 vendor module uses it for an 8-wide convert + f32 FMA GEMM.

VM_CPU_AVX512BW

x86 AVX-512BW (byte/word integer).

A feature, not a tier. Vendor modules (intel/fp16, intel/bf16) compile kernels with -mavx512bw and emit BW instructions (masked 16-bit loads, etc.).

VM_CPU_AVX512VL

x86 AVX-512VL (vector length: 128/256-bit AVX-512 ops).

A feature, not a tier. Vendor modules compile with -mavx512vl for masked 256-bit sequences alongside AVX-512 FP16/BF16.

VM_CPU_AVX512BF16

x86 AVX-512 BF16 (CPUID.7.1:EAX[5]).

A feature, not a tier. Shared: Intel (Cooper Lake+) and AMD (Zen 4+) both report this bit. The intel/bf16 vendor module uses it for a BF16 GEMM.

VM_CPU_NEON

VM_CPU_SVE

VM_CPU_SVE2

VM_CPU_ARM_FP16

AArch64 vector FP16 (HWCAP_ASIMDHP).

A feature, not a tier. The arm/fp16 vendor module uses it for convert + FMLAL GEMM.

VM_CPU_ARM_BF16

AArch64 bfloat16 (HWCAP2_BF16).

A feature, not a tier. The arm/bf16 vendor module uses it for a BFDOT GEMM.

VM_CPU_I8MM

AArch64 integer 8-bit matrix multiply (HWCAP2_I8MM).

A feature, not a tier. Probed, no consumer yet.

Function documentation

vm_cpu_features_t vm_cpu_compiled_features(void)

ISA bits compiled into this library (VECMAT_ENABLE_*).

Returns Feature mask of enabled backends.

ISA bits compiled into this library (VECMAT_ENABLE_*).

vm_cpu_features_t vm_cpu_runtime_features(void)

ISA bits detected on this CPU (runtime probe).

Returns Feature mask of usable backends.

ISA bits detected on this CPU (runtime probe).

vm_cpu_features_t vm_cpu_selected_features(void)

ISA the picker bound: registered backend, else best compiled-and-runtime.

Returns Single selected feature bit (or scalar).

VECMAT_FORCE_ISA=scalar|avx|avx2|avx512f|neon|sve|sve2 overrides the compiled/runtime pick when that ISA is compiled in. A registered backend still wins. The override is read once, on the first probe.

ISA the picker bound: registered backend, else best compiled-and-runtime.

static int vm_cpu_has(const vm_cpu_features_t need)

Non-zero when this CPU has every bit in need (a bit or a level).

Reads the raw vm_cpu_runtime_features() mask, so VECMAT_FORCE_ISA and registered backends do not change it.

const char* vm_cpu_name(vm_cpu_features_t features)

Short name for a feature mask (avx2, neon, scalar, etc.).

Parameters
features Feature mask.
Returns Stable string such as avx2 or scalar.

Short name for a feature mask (avx2, neon, scalar, etc.).

void vm_cpu_init(void)

Probe once and bind dispatched _ptr names.

Thread-safe and idempotent (C11 atomics, double-checked locking). Call before reading vm_cpu_selected_features() if you care about the first-use race; kernels themselves call this on first use.

const char* vm_cpu_note(void)

Optional one-line note set by a registered module.

NULL until a module calls vm_cpu_set_note(). The pointer is not copied.

void vm_cpu_set_note(const char* note)

Attach a module note for banners.

Pass NULL to clear.