vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ir::{Expr, Program};
use crate::ops::primitive;
use crate::ops::{AlgebraicLaw, OpSpec, F32_F32_INPUTS, F32_OUTPUTS};

// Element-wise subtraction of two f32 buffers.


// `SelfInverse { result: 0 }` fails on `NaN - NaN = NaN` and
// `Inf - Inf = NaN` — neither returns `0.0`. `RightIdentity { element:
// 0 }` holds for all finite and infinite inputs, and holds bit-exactly
// for the NaN payload (`NaN - 0 = NaN` preserves the payload).
// Per audit `primitive-laws-kimi-AUDIT`.
pub const LAWS: &[AlgebraicLaw] =
    &[AlgebraicLaw::RightIdentity { element: 0.0f32.to_bits() }];

/// f32 element-wise subtraction operation.
#[derive(Debug, Clone, Copy, Default)]
pub struct F32Sub;

impl F32Sub {
    /// Declarative operation specification.
    pub const SPEC: OpSpec = OpSpec::composition_inlinable(
        "primitive.float.f32_sub",
        F32_F32_INPUTS,
        F32_OUTPUTS,
        LAWS,
        Self::program,
    );

    /// Build the canonical IR program.
    ///
    /// # Examples
    ///
    /// ```
    /// use vyre::ir::Expr;
    /// use vyre::ops::primitive::float::f32_sub::F32Sub;
    ///
    /// let program = F32Sub::program();
    /// assert!(!program.entry().is_empty());
    /// ```
    #[must_use]
    pub fn program() -> Program {
        primitive::binary_f32_program(Expr::sub)
    }
}

// WGSL lowering marker for `primitive.float.f32_sub`.
//
// Not a stub: this is a zero-overhead Category A marker. `F32Sub::program`
// builds concrete IR through `core/src/ops/primitive/binary_f32_program.rs`;
// `core/src/lower/wgsl/expr.rs::emit_binop` emits WGSL.
// `core/tests/conformance.rs::conformance_all_primitives` verifies
// lowered GPU bytes are bit-exact against the conform CPU reference.
//
// ```wgsl
// _vyre_store_out(idx, (_vyre_load_a(idx) - _vyre_load_b(idx)));
// ```