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.sha1`.

/// Shared WGSL helpers and SHA-1 compression primitives.
pub const WGSL: &str = concat!(
    include_str!("wgsl_shaders/words.wgsl"),
    "\n",
    include_str!("wgsl_shaders/sha1.wgsl"),
);

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

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

pub const OUTPUTS: &[DataType] = &[const { DataType::U32 }; 5];

/// Compute SHA-1 and return five big-endian digest words.
#[must_use]
pub fn sha1(input: &[u8]) -> [u32; 5] {
    crate::ops::hash::reference::sha1::sha1_words(input)
}

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

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