vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ir::{BufferDecl, DataType, Expr, Node, Program};
use crate::ops::{AlgebraicLaw, OpSpec, U32_U32_INPUTS};

// Unsigned less-than, returns 1 when a < b.



pub const BOOL_OUTPUTS: &[DataType] = &[DataType::Bool];

pub const LAWS: &[AlgebraicLaw] = &[
    AlgebraicLaw::SelfInverse { result: 0 },
    AlgebraicLaw::Bounded { lo: 0, hi: 1 },
    AlgebraicLaw::Trichotomy {
        less_op: "primitive.compare.lt",
        equal_op: "primitive.compare.eq",
        greater_op: "primitive.compare.gt",
    },
];

/// Unsigned less-than operation.
#[derive(Debug, Clone, Copy, Default)]
pub struct Lt;

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

    /// Build the canonical IR program.
    ///
    /// # Examples
    ///
    /// ```
    /// use vyre::ir::Expr;
    /// use vyre::ops::primitive::compare::lt::Lt;
    ///
    /// let _expr = Expr::lt(Expr::u32(3), Expr::u32(4));
    /// let program = Lt::program();
    /// assert!(!program.entry().is_empty());
    /// ```
    #[must_use]
    pub fn program() -> Program {
        let idx = Expr::var("idx");
        Program::new(
            vec![
                BufferDecl::read("a", 0, DataType::U32),
                BufferDecl::read("b", 1, DataType::U32),
                BufferDecl::output("out", 2, DataType::Bool),
            ],
            [64, 1, 1],
            vec![
                Node::let_bind("idx", Expr::gid_x()),
                Node::if_then(
                    Expr::lt(idx.clone(), Expr::buf_len("out")),
                    vec![Node::store(
                        "out",
                        idx.clone(),
                        Expr::lt(Expr::load("a", idx.clone()), Expr::load("b", idx)),
                    )],
                ),
            ],
        )
    }
}

// Backend-specific lowering tripwires for `primitive.compare.lt`.

// WGSL lowering marker for `primitive.compare.lt`.
//
// Not a stub: this is a zero-overhead Category A marker. `Lt::program`
// builds concrete IR through `core/src/ops/primitive/compare/lt/kernel.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, select(0u, 1u, (_vyre_load_a(idx) < _vyre_load_b(idx))));
// ```