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

// Population count (number of set bits) in a u32.



pub const LAWS: &[AlgebraicLaw] = &[
    AlgebraicLaw::Bounded { lo: 0, hi: 32 },
    AlgebraicLaw::Complement {
        complement_op: "primitive.bitwise.not",
        universe: 32,
    },
];

/// Population count operation.
#[derive(Debug, Clone, Copy, Default)]
pub struct Popcount;

impl Popcount {
    /// Declarative operation specification.
    pub const SPEC: OpSpec = OpSpec::composition_inlinable(
        "primitive.bitwise.popcount",
        U32_INPUTS,
        U32_OUTPUTS,
        LAWS,
        Self::program,
    );

    /// Build the canonical IR program.
    ///
    /// # Examples
    ///
    /// ```
    /// use vyre::ir::Expr;
    /// use vyre::ops::primitive::popcount::Popcount;
    ///
    /// let _expr = Expr::popcount(Expr::u32(0b1011));
    /// let program = Popcount::program();
    /// assert!(!program.entry().is_empty());
    /// ```
    #[must_use]
    pub fn program() -> Program {
        primitive::unary_u32_program(Expr::popcount)
    }
}

// Backend-specific lowering tripwires for popcount.

// WGSL lowering marker for `primitive.bitwise.popcount`.
//
// Not a stub: this is a zero-overhead Category A marker. `Popcount::program`
// builds concrete IR through `core/src/ops/primitive/mod.rs::unary_u32_program`; `core/src/lower/wgsl/expr.rs::emit_unop` 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, countOneBits(_vyre_load_a(idx)));
// ```