use crate::{Convention, DataType, OpSignature, OpSpec};
pub const VYRE_OP_METADATA: vyre_spec::OpMetadata = vyre_spec::OpMetadata {
id: "primitive.pattern.byte_len",
layer: vyre_spec::Layer::L2,
category: vyre_spec::MetadataCategory::A,
version: 1,
description: "byte buffer length as u32",
signature: "(Bytes) -> U32",
strictness: "strict",
archetype_signature: "(Bytes) -> U32",
};
pub const GOLDEN: &[vyre_spec::GoldenSample] = &[vyre_spec::GoldenSample {
op_id: "primitive.pattern.byte_len",
input: b"abc",
expected: &[0x03, 0x00, 0x00, 0x00],
reason: "three input bytes encode length 3 as little-endian u32",
}];
pub const KAT: &[vyre_spec::KatVector] = &[vyre_spec::KatVector {
input: b"abc",
expected: &[0x03, 0x00, 0x00, 0x00],
source: "Rust slice len reference semantics",
}];
pub const ADVERSARIAL: &[vyre_spec::AdversarialInput] = &[vyre_spec::AdversarialInput {
input: &[0u8; 1024],
reason: "large buffer length exercises u32 length encoding",
}];
fn cpu_fn(input: &[u8]) -> Vec<u8> {
(input.len() as u32).to_le_bytes().to_vec()
}
fn wgsl_fn() -> String {
r"
fn vyre_op(index: u32, input_len: u32) -> u32 {
_ = index;
return input_len;
}
"
.to_string()
}
#[inline]
pub fn vyre_op() -> OpSpec {
let id = "primitive.pattern.byte_len";
OpSpec::builder(id)
.signature(OpSignature {
inputs: vec![DataType::Bytes],
output: DataType::U32,
})
.cpu_fn(cpu_fn)
.wgsl_fn(wgsl_fn)
.category(crate::Category::A {
composition_of: vec![id],
})
.laws(vec![crate::spec::law::AlgebraicLaw::Bounded {
lo: 0,
hi: u32::MAX,
}])
.overflow_contract(crate::spec::types::OverflowContract::Unchecked)
.strictness(crate::spec::types::Strictness::Strict)
.version(1)
.alt_wgsl_fns(vec![("category_a_handwritten", wgsl_fn)])
.convention(Convention::V1)
.workgroup_size(Some(256))
.boundary_values(vec![crate::spec::types::BoundaryValue {
label: "empty",
inputs: vec![0],
}])
.equivalence_classes(vec![crate::spec::types::EquivalenceClass::specific(
"empty input",
vec![0],
)])
.expect("Fix: checked-in conform spec must satisfy the typestate builder")
}
#[cfg(test)]
mod proptests {
#[test]
fn coverage_artifacts_are_registered() {
assert!(!super::KAT.is_empty());
assert!(!super::ADVERSARIAL.is_empty());
}
}