imazen / imazen/archmage

Adoptable techniques from the fearless_simd review (2026-09): swizzle_dyn, safe token materialization, formulation wins, docs batch

Open
#81 13 comments 0 reactions 1 assignee Claimed by @lilith View on GitHub
Dominant language
Rust
Stars
12
Forks
2
Avg merge
13h 55m
Merged PRs (30d)
28

Description

A model-driven review of linebender/fearless_simd (0.7.0, changelog 0.2.0→0.7.0, recent PRs/issues, and the related blog posts) against archmage/magetypes, looking for improvements worth adopting. fearless_simd is well-designed, fast-moving work and several of its recent changes carry lessons we can reuse — full report on the review box at `~/tmp/fearless-simd-review-2026-09-04.md`. Ranked adoptables:

1. **f32→i32 conversion contract** — split out as #80 (verified live divergence here).
2. **Safe token materialization**: their `assume_supported()` is a `#[target_feature(enable=…)] const fn` constructor — callable *safely* from matching feature contexts, `unsafe` elsewhere (their #293). This answers our open 'rite token forging' design question (CLAUDE.md Open Questions) with zero user-visible unsafe and no new safety model: the `#[target_feature]` context is the proof. Landing site: `xtask/src/token_gen.rs` → generated token impls.
3. **Dynamic byte swizzle family** (`swizzle_dyn` / `_precise` / `_within_blocks`, their #266/#276/#304/#322/#362): magetypes currently has no pshufb/tbl-class op at all — the workhorse for palette expansion, format shuffles, and byte transforms. Their two-tier out-of-range contract (relaxed vs zeroing) is a clean answer to the ISA divergence, and the AVX2 formulation they landed (control-derived blend mask) is documented with measurements. Landing site: new u8xN backend methods via xtask, with lane-order-pinned tests.
4. **Formulation wins worth an llvm-mca pass over our backends** (their #350/#291/#343/#344/#279): 8-bit multiplies via PMADDUBSW (we currently expose no 8-bit mul), a cheaper NEON bitmask than our per-lane `vgetq_lane` packing (`impls/arm_neon.rs:1429/1695`), polyfill `all_true(a,b)` as `reduce(and(a,b))` rather than two reductions (`impls/arm_neon.rs:1679`), plus interleave and AVX-512 byte-shift lowerings.
5. **Docs/table batch**: note the std `mul_add` subnormal fallback bug (compiler-builtins#1262) next to our fusion-contract docs; a '`round` ≠ Rust scalar `round`' warning; IEEE-vs-native min/max naming (`min_ieee`/`max_ieee`); never implement trunc/fract via int roundtrip (their #365: `a-(f32)(i32)a` breaks at ≥2³¹); and an `incant!`-adjacent gotcha note about `return`/`?` inside dispatched blocks.

Also worth knowing: their build-time lesson (derive shared-shape op impls from common generic code instead of per-backend×width emission; −25% metadata, meaningful for our 84-file generation), a `#[doc(hidden)]` macro-surface soundness-hardening audit prompt for archmage-macros (their #363), and one capability we lack by decision: 32-bit `target_arch = "x86"` support (our tokens stub out on i686 — worth re-confirming that's intentional given i686 is a primary CI target).

Things we deliberately should NOT copy (and why) are in the report — mostly places where our existing design (registry-driven tiers, token caching, uniform out-of-range shift contracts, no-silent-test-skips) already sits where their issue tracker is pointing.

Credit where due: the review leaned on their public issue discussions and Shnatsel's writeups, which document these techniques unusually well.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.