vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation


//! WGSL lowering source for `buffer.memchr`.

/// Dispatchable WGSL kernel for first-byte search.
pub const WGSL: &str = concat!(
    include_str!("../wgsl_byte_primitives/bytes.wgsl"),
    "\n",
    include_str!("wgsl/memchr.wgsl"),
);

/// Return the first index of `needle_byte & 0xff`, or [`NOT_FOUND`].
#[must_use]
pub fn memchr(haystack: &[u8], needle_byte: u32) -> u32 {
    let needle = (needle_byte & 0xff) as u8;
    haystack
        .iter()
        .position(|&byte| byte == needle)
        .and_then(|index| u32::try_from(index).ok())
        .unwrap_or(NOT_FOUND)
}

/// Sentinel returned when the needle is absent.
pub const NOT_FOUND: u32 = u32::MAX;