Skip to content

Commit 922a26c

Browse files
Shnatselvstroebel
authored andcommitted
Add safe wrappers for AVX loads/stores
1 parent 5d4d6e0 commit 922a26c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/avx2/fdct.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,21 @@ unsafe fn fdct_avx2_internal(data: &mut [i16; 64]) {
466466
_mm256_storeu_si256(out_data.add(2), ymm6);
467467
_mm256_storeu_si256(out_data.add(3), ymm7);
468468
}
469+
470+
/// Safe wrapper for an unaligned AVX load
471+
#[target_feature(enable = "avx2")]
472+
#[inline]
473+
fn avx_load(input: &[i16; 16]) -> __m256i {
474+
assert!(core::mem::size_of::<[i16; 16]>() == core::mem::size_of::<__m256i>());
475+
// SAFETY: we've checked sizes above. The load is unaligned, so no alignment requirements.
476+
unsafe { _mm256_loadu_si256(input.as_ptr() as *const __m256i) }
477+
}
478+
479+
/// Safe wrapper for an unaligned AVX store
480+
#[target_feature(enable = "avx2")]
481+
#[inline]
482+
fn avx_store(input: __m256i, output: &mut [i16; 16]) {
483+
assert!(core::mem::size_of::<[i16; 16]>() == core::mem::size_of::<__m256i>());
484+
// SAFETY: we've checked sizes above. The load is unaligned, so no alignment requirements.
485+
unsafe { _mm256_storeu_si256(output.as_mut_ptr() as *mut __m256i, input) }
486+
}

0 commit comments

Comments
 (0)