diff options
| author | Jack O'Connor <[email protected]> | 2024-08-18 11:16:13 -0700 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2024-08-18 11:32:23 -0700 |
| commit | 5c4c351a1a0729f8e7a88e6895379bb952ed1a07 (patch) | |
| tree | ae23751fbf5eaeaf394efd810fc578286022c722 /src | |
| parent | 4386d7f0baae5cf77e319f12256bd7c91fedc1ef (diff) | |
make xof_many fall back to compress_xof instead of portable code
Diffstat (limited to 'src')
| -rw-r--r-- | src/platform.rs | 13 | ||||
| -rw-r--r-- | src/portable.rs | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/platform.rs b/src/platform.rs index 590a77c..cd8ef63 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -282,7 +282,7 @@ impl Platform { cv: &CVWords, block: &[u8; BLOCK_LEN], block_len: u8, - counter: u64, + mut counter: u64, flags: u8, out: &mut [u8], ) { @@ -299,7 +299,16 @@ impl Platform { Platform::AVX512 => unsafe { crate::avx512::xof_many(cv, block, block_len, counter, flags, out) }, - _ => crate::portable::xof_many(cv, block, block_len, counter, flags, out), + _ => { + // For platforms without an optimized xof_many, fall back to a loop over + // compress_xof. This is still faster than portable code. + for out_block in out.chunks_exact_mut(BLOCK_LEN) { + // TODO: Use array_chunks_mut here once that's stable. + let out_array: &mut [u8; BLOCK_LEN] = out_block.try_into().unwrap(); + *out_array = self.compress_xof(cv, block, block_len, counter, flags); + counter += 1; + } + } } } diff --git a/src/portable.rs b/src/portable.rs index 4181f27..35b5f5d 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -177,6 +177,10 @@ pub fn hash_many<const N: usize>( } } +// This function is test-only. When platform::xof_many() doesn't have an optimized implementation, +// it loops over platform::compress_xof() instead of falling back to this, so it still benefits +// from compress optimizations. +#[cfg(test)] pub fn xof_many( cv: &CVWords, block: &[u8; BLOCK_LEN], |
