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, U32_OUTPUTS, U32_U32_INPUTS};

// Saturating subtraction of two u32 values.



pub const LAWS: &[AlgebraicLaw] = &[
    AlgebraicLaw::RightIdentity { element: 0 },
    AlgebraicLaw::Bounded {
        lo: 0,
        hi: u32::MAX,
    },
];

/// Saturating u32 subtraction operation.
#[derive(Debug, Clone, Copy, Default)]
pub struct SubSat;

impl SubSat {
    /// Declarative operation specification.
    pub const SPEC: OpSpec = OpSpec::composition_inlinable(
        "primitive.math.sub_sat",
        U32_U32_INPUTS,
        U32_OUTPUTS,
        LAWS,
        Self::program,
    );

    /// Build the canonical IR program.
    #[must_use]
    pub fn program() -> Program {
        primitive::binary_u32_program(|a, b| {
            Expr::select(
                Expr::lt(a.clone(), b.clone()),
                Expr::u32(0),
                Expr::sub(a, b),
            )
        })
    }
}

// Backend-specific lowering tripwires for saturating subtraction.

// WGSL lowering marker for `primitive.math.sub_sat`.
//
// Not a stub: this is a zero-overhead Category A marker. `SubSat::program`
// builds concrete IR through `core/src/ops/primitive/math/sub_sat/kernel.rs`; `core/src/lower/wgsl/expr.rs` 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, select((a - b), 0u, (a < b)));
// ```