Magetypes
SIMD vector types with natural Rust operators
Process an image plane (exposure) or an audio buffer (gain), including a short
scalar tail. The vector type is generic over the token selected by #[magetypes];
incant! chooses the CPU tier once outside the loop. No manual per-tier wrappers
or raw pointers are needed.
Adapted from the zenfilters plane-scaling kernel; the complete production call chain and adaptation notes include pinned source links.
#![forbid(unsafe_code)]
use archmage::prelude::*;
#[magetypes(define(f32x8), v3, neon, wasm128, scalar)]
fn gain_impl(token: Token, plane: &mut [f32], gain: f32) {
let factor = f32x8::splat_t(token, gain);
let (chunks, tail) = f32x8::partition_slice_mut_t(token, plane);
for chunk in chunks {
(f32x8::load_t(token, chunk) * factor).store(chunk);
}
for value in tail {
*value *= gain;
}
}
pub fn apply_gain(plane: &mut [f32], gain: f32) {
incant!(gain_impl(plane, gain), [v3, neon, wasm128, scalar])
}
let mut data = [2.0; 11];
apply_gain(&mut data, 0.5);
assert_eq!(data, [1.0; 11]);Continue with the production patterns
- Type and const generics: pixel types, mode specialization, and turbofish dispatch.
- Reusable backend helpers: the complete zenblend SrcOver chain.
- Memory, bounds, and tails: array references and row/strip contracts.
- Direct intrinsic helpers: a feature-enabled entry and matched helper.
- ISA quirks and fixups: the numerical contract and its costs.
- Production coverage: which patterns the zen crates actually exercise.
Archmage provides tokens, feature contexts, and dispatch. Magetypes provides
vectors such as f32x4<T> and f32x8<T>. Generics and define(...) compose with
#[magetypes]; neither is a substitute for a feature-enabled entry. Inspect
optimized code and benchmark the complete loop before claiming zero overhead.