vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
// Unsigned remainder, zero returns 0.

use crate::ir::{Expr, Program};
use crate::ops::primitive;
use crate::ops::{AlgebraicLaw, OpSpec, U32_OUTPUTS, U32_U32_INPUTS};


pub const LAWS: &[AlgebraicLaw] = &[
    AlgebraicLaw::SelfInverse { result: 0 },
    AlgebraicLaw::LeftAbsorbing { element: 0 },
];

/// Unsigned remainder, zero returns 0 operation.
#[derive(Debug, Clone, Copy, Default)]
pub struct Mod;

impl Mod {
    /// Declarative operation specification.
    ///
    /// Laws are declared as explicit `AlgebraicLaw` values on `SPEC`.
    pub const SPEC: OpSpec = OpSpec::composition_inlinable(
        "primitive.math.mod",
        U32_U32_INPUTS,
        U32_OUTPUTS,
        LAWS,
        Self::program,
    );

    /// Build the canonical IR program.
    ///
    /// # Examples
    ///
    /// ```
    /// use vyre::ir::Expr;
    /// use vyre::ops::primitive::mod_op::Mod;
    ///
    /// let _expr = Expr::rem(Expr::u32(9), Expr::u32(4));
    /// let program = Mod::program();
    /// assert!(!program.entry().is_empty());
    /// ```
    #[must_use]
    pub fn program() -> Program {
        primitive::binary_u32_program(Expr::rem)
    }
}

// Backend-specific lowering tripwires for `primitive.math.mod`.

// WGSL lowering marker for `primitive.math.mod`.
//
// Not a stub: this is a zero-overhead Category A marker. `Mod::program`
// builds concrete IR through `core/src/ops/primitive/mod.rs::binary_u32_program`; `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_safe_mod_u32(_vyre_load_a(idx), _vyre_load_b(idx)));
// ```