Type Overview

Magetypes provides generic SIMD vector types parameterized by a backend token. Each type is written as f32x8<T> where T is a token type that determines the platform implementation. A function generic over T: F32x8Backend works on any backend that supports 8-lane f32 operations.

Available Types

x86-64

TypeElementsWidthMin Token
f32x4<T>4 x f32128-bitX64V2Token
f32x8<T>8 x f32256-bitX64V3Token
f32x16<T>16 x f32512-bitX64V4Token*
f64x2<T>2 x f64128-bitX64V2Token
f64x4<T>4 x f64256-bitX64V3Token
f64x8<T>8 x f64512-bitX64V4Token*
i8x16<T>16 x i8128-bitX64V2Token
i8x32<T>32 x i8256-bitX64V3Token
i16x8<T>8 x i16128-bitX64V2Token
i16x16<T>16 x i16256-bitX64V3Token
i32x4<T>4 x i32128-bitX64V2Token
i32x8<T>8 x i32256-bitX64V3Token
i32x16<T>16 x i32512-bitX64V4Token*
i64x2<T>2 x i64128-bitX64V2Token
i64x4<T>4 x i64256-bitX64V3Token
u8x16<T>16 x u8128-bitX64V2Token
u8x32<T>32 x u8256-bitX64V3Token
u16x8<T>8 x u16128-bitX64V2Token
u16x16<T>16 x u16256-bitX64V3Token
u32x4<T>4 x u32128-bitX64V2Token
u32x8<T>8 x u32256-bitX64V3Token
u64x2<T>2 x u64128-bitX64V2Token
u64x4<T>4 x u64256-bitX64V3Token

*Requires the avx512 feature flag.

AArch64 (NEON)

TypeElementsWidthToken
f32x4<T>4 x f32128-bitNeonToken
f64x2<T>2 x f64128-bitNeonToken
i8x16<T>16 x i8128-bitNeonToken
i16x8<T>8 x i16128-bitNeonToken
i32x4<T>4 x i32128-bitNeonToken
i64x2<T>2 x i64128-bitNeonToken
u8x16<T>16 x u8128-bitNeonToken
u16x8<T>8 x u16128-bitNeonToken
u32x4<T>4 x u32128-bitNeonToken
u64x2<T>2 x u64128-bitNeonToken

NEON registers are 128-bit. Wider types (f32x8<T>, etc.) are available as polyfills using pairs of NEON operations.

WASM (SIMD128)

TypeElementsWidthToken
f32x4<T>4 x f32128-bitWasm128Token
f64x2<T>2 x f64128-bitWasm128Token
i8x16<T>16 x i8128-bitWasm128Token
i16x8<T>8 x i16128-bitWasm128Token
i32x4<T>4 x i32128-bitWasm128Token
i64x2<T>2 x i64128-bitWasm128Token
u8x16<T>16 x u8128-bitWasm128Token
u16x8<T>8 x u16128-bitWasm128Token
u32x4<T>4 x u32128-bitWasm128Token
u64x2<T>2 x u64128-bitWasm128Token

Wider types are available as polyfills, same as ARM.

Basic Usage

The correct pattern is a generic function bounded by the appropriate backend trait. The type parameter T is satisfied at the call site by whichever token the caller holds.

use archmage::{X64V3Token, SimdToken};
use magetypes::simd::{
    generic::f32x8,
    backends::F32x8Backend,
};

#[inline(always)]
fn example<T: F32x8Backend>(token: T) {
    // Construct from array
    let a = f32x8::<T>::from_array(token, [1.0; 8]);

    // Splat a single value
    let b = f32x8::<T>::splat(token, 2.0);

    // Natural operators
    let c = a + b;
    let d = c * c;

    // Extract result
    let result: [f32; 8] = d.to_array();
}

// Call site: summon the token, then call the generic function
if let Some(token) = X64V3Token::summon() {
    example(token);
}

Type Properties

All magetypes SIMD types are:

  • Copy — pass by value freely
  • Clone — explicit cloning works
  • Debug — print for debugging
  • Send + Sync — thread-safe
use magetypes::simd::{generic::f32x8, backends::F32x8Backend};

#[inline(always)]
fn copy_demo<T: F32x8Backend>(token: T) {
    let a = f32x8::<T>::splat(token, 1.0);
    let b = a;  // Copy, not move
    let c = a + b;  // Both still valid
}

Why no Pod/Zeroable? Implementing bytemuck traits would let users bypass token-gated construction (e.g., bytemuck::zeroed::<f32x8<T>>()), creating vectors without proving CPU support. Use the token-gated cast_slice and from_bytes methods instead.

Found an error or it needs a clarification? Open an issue on GitHub.
Substantiated corrections will be incorporated with attribution.