Skip to main content

rite

Attribute Macro rite 

Source
#[rite]
Expand description

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

Unlike #[arcane], which creates a wrapper function, #[rite] simply adds #[target_feature] and #[inline] attributes. This allows the function to inline directly into calling #[arcane] functions without optimization barriers.

§When to Use

Use #[rite] for helper functions that are only called from within #[arcane] functions with matching or superset token types:

use archmage::{arcane, rite, X64V3Token};

#[arcane]
fn outer(token: X64V3Token, data: &[f32; 8]) -> f32 {
    // helper inlines directly - no wrapper overhead
    helper(token, data) * 2.0
}

#[rite]
fn helper(token: X64V3Token, data: &[f32; 8]) -> f32 {
    // Just has #[target_feature(enable = "avx2,fma,...")]
    // Called from #[arcane] context, so features are guaranteed
    let v = f32x8::from_array(token, *data);
    v.reduce_add()
}

§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.

§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