vyre_reference/dual_impls/hash/fnv1a/
reference.rs1use crate::{dual_impls::common, workgroup::Memory};
2use vyre_primitives::HashFnv1a;
3
4const FNV_OFFSET: u32 = 0x811c_9dc5;
5const FNV_PRIME: u32 = 0x0100_0193;
6
7impl common::ReferenceEvaluator for HashFnv1a {
8 fn evaluate(&self, inputs: &[Memory]) -> Result<Memory, common::EvalError> {
9 let mut hash = FNV_OFFSET;
10 let input = common::one_input(inputs, "hash_fnv1a")?;
11 for byte in &input {
12 hash ^= u32::from(*byte);
13 hash = hash.wrapping_mul(FNV_PRIME);
14 }
15 Ok(Memory::from_bytes(hash.to_le_bytes().to_vec()))
16 }
17}