Magetypes
Experimental SIMD vector types with natural Rust operators
Magetypes provides SIMD vector types — f32x8, i32x4, u8x16, and friends — with natural Rust operators. Instead of writing raw intrinsics, you write a + b, v * v, x.reduce_add().
Status: Experimental. The API is usable and tested across x86-64, AArch64, and WASM, but it may change between minor versions. Pin your dependency version if stability matters.
Relationship to Archmage
Magetypes depends on archmage for capability tokens. You cannot construct a magetypes vector without first proving that the CPU supports the required features — this is what "token-gated construction" means.
The types are generic over a backend token T. Write one function, get a correct implementation on every architecture:
use magetypes::simd::{
generic::f32x8,
backends::F32x8Backend,
};
#[inline(always)]
fn dot_product<T: F32x8Backend>(token: T, a: &[f32; 8], b: &[f32; 8]) -> f32 {
let va = f32x8::<T>::load(token, a);
let vb = f32x8::<T>::load(token, b);
// Natural operators — no intrinsics, no unsafe
let product = va * vb;
product.reduce_add()
}
To call this from concrete code, summon a token and pass it in:
use archmage::{X64V3Token, SimdToken};
fn main() {
// Prove CPU supports AVX2+FMA — returns None on unsupported hardware
if let Some(token) = X64V3Token::summon() {
let a = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0f32];
let b = [2.0f32; 8];
let result = dot_product(token, &a, &b);
println!("dot: {}", result); // 72.0
}
}
Every constructor (from_array, splat, zero, load) takes a token as its first argument. If you have the vector, the CPU can run the operations on it.
Cross-Platform Polyfills
Types wider than the hardware's native register width work everywhere via polyfills. An f32x8 on AArch64 (which has 128-bit NEON registers) is implemented internally as two f32x4 operations. The API is identical — you pick the size that fits your algorithm, and magetypes handles the rest. See Polyfills for details.
What's Here
- Getting Started — Installation and your first types
- Types — Available types per platform, properties, feature flags
- Operations — Construction, arithmetic, reductions, bitwise
- Conversions — Float/int, width, bitcast, slice casting
- Math — Transcendentals, precision levels, approximations
- Memory — Load/store, gather/scatter, interleaved data, chunked processing
- Cross-Platform — Polyfill strategy, known behavioral differences
- Dispatch — Using magetypes with
incant!and#[magetypes]