Skip to main content

rite

Attribute Macro rite 

Source
#[rite]
Expand description

Annotate inner SIMD helpers called from #[arcane] functions.

Unlike #[arcane], which creates an inner #[target_feature] function behind a safe boundary, #[rite] adds #[target_feature] and #[inline] directly. LLVM inlines it into any caller with matching features — no boundary crossing.

§Three Modes

Token-based: Reads the token type from the function signature.

#[rite]
fn helper(_: X64V3Token, v: __m256) -> __m256 { _mm256_add_ps(v, v) }

Tier-based: Specify the tier name directly, no token parameter needed.

#[rite(v3)]
fn helper(v: __m256) -> __m256 { _mm256_add_ps(v, v) }

Both produce identical code. The token form can be easier to remember if you already have the token in scope.

Multi-tier: Specify multiple tiers to generate suffixed variants.

#[rite(v3, v4)]
fn process(data: &[f32; 4]) -> f32 { data.iter().sum() }
// Generates: process_v3() and process_v4()

Each variant gets its own #[target_feature] and #[cfg(target_arch)]. Since Rust 1.85, calling these from a matching #[arcane] or #[rite] context is safe — no unsafe needed when the caller has matching or superset features.

§Safety

#[rite] functions can only be safely called from contexts where the required CPU features are enabled:

  • From within #[arcane] functions with matching/superset tokens
  • From within other #[rite] functions with matching/superset tokens
  • From code compiled with -Ctarget-cpu that enables the features

Calling from other contexts requires unsafe and the caller must ensure the CPU supports the required features.

§Cross-Architecture Behavior

Like #[arcane], defaults to cfg-out (no function on wrong arch). Use #[rite(stub)] to generate an unreachable stub instead.

§Options

OptionEffect
tier name(s)v3, neon, etc. One = single function; multiple = suffixed variants
stubGenerate unreachable!() stub on wrong architecture
import_intrinsicsAuto-import archmage::intrinsics::{arch}::* (includes safe memory ops)
import_magetypesAuto-import magetypes::simd::{ns}::* and magetypes::simd::backends::*

See #[arcane] docs for the full namespace mapping table.

§Comparison with #[arcane]

Aspect#[arcane]#[rite]
Creates wrapperYesNo
Entry pointYesNo
Inlines into callerNo (barrier)Yes
Safe to call anywhereYes (with token)Only from feature-enabled context
Multi-tier variantsNoYes (#[rite(v3, v4, neon)])
stub paramYesYes
import_intrinsicsYesYes
import_magetypesYesYes