archmage 0.9.13

Safely invoke your intrinsic power, using the tokens granted to you by the CPU. Cast primitive magics faster than any mage alive.
Documentation
//! Test: Value intrinsics are SAFE inside #[arcane] (Rust 1.85+)
//!
//! Key insight: Inside #[target_feature], value-based intrinsics are safe.
//! Memory ops are safe too when using import_intrinsics (reference-based).

#![cfg(target_arch = "x86_64")]

use archmage::intrinsics::x86_64::__m256;
use archmage::{Desktop64, SimdToken, arcane};

// Value intrinsics - ALL SAFE inside #[arcane], no unsafe needed!
#[arcane(import_intrinsics)]
fn test_value_intrinsics(_token: Desktop64, a: __m256, b: __m256) -> __m256 {
    let sum = _mm256_add_ps(a, b);
    let prod = _mm256_mul_ps(sum, sum);
    let blended = _mm256_blend_ps::<0b10101010>(prod, sum);
    _mm256_sqrt_ps(blended)
}

// Reference-based load via import_intrinsics - safe, no qualification needed!
#[arcane(import_intrinsics)]
fn test_safe_load(_token: Desktop64, data: &[f32; 8]) -> __m256 {
    _mm256_loadu_ps(data)
}

#[test]
fn test_value_ops_are_safe() {
    if let Some(token) = Desktop64::summon() {
        let a = unsafe { std::arch::x86_64::_mm256_set1_ps(2.0) };
        let b = unsafe { std::arch::x86_64::_mm256_set1_ps(3.0) };
        let _ = test_value_intrinsics(token, a, b);
    }
}

#[test]
fn test_safe_simd_load() {
    if let Some(token) = Desktop64::summon() {
        let data = [1.0f32; 8];
        let _ = test_safe_load(token, &data);
    }
}