vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ir::DataType;
use crate::ops::Backend;
use crate::ops::{IntrinsicDescriptor, OpSpec};

// WGSL lowering source for `hash.siphash13`.

/// Concrete SipHash-1-3 WGSL kernel.
pub const WGSL: &str = include_str!("wgsl/siphash13.wgsl");

pub const INPUTS: &[DataType] = &[DataType::Bytes, DataType::U64];

pub const LAWS: &[crate::ops::AlgebraicLaw] = &[];

pub const OUTPUTS: &[DataType] = &[DataType::U64];

/// Compute SipHash-1-3 with a 64-bit key expanded into the key schedule.
#[must_use]
pub fn siphash13(msg: &[u8], key: u64) -> u64 {
    crate::ops::hash::reference::siphash::siphash13(msg, key)
}

/// Declarative operation specification for `hash.siphash13`.
pub const SPEC: OpSpec = OpSpec::intrinsic(
    "hash.siphash13",
    INPUTS,
    OUTPUTS,
    LAWS,
    wgsl_only,
    IntrinsicDescriptor::new(
        "hash.siphash13.wgsl",
        "wgsl-siphash13",
        crate::ops::hash::cpu_refs::siphash13,
    ),
);

pub fn wgsl_only(backend: &Backend) -> bool {
    matches!(backend, Backend::Wgsl)
}