rust-lang / project-safe-transmute

Project group working on the "safe transmute" feature

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`[T]::safe_align_to` and SIMD

programmerjake opened this issue · comments

Thought I'd mention that having a safe version of [T]::align_to would be quite handy for SIMD strip-mining loops.

Came up here: https://rust-lang.zulipchat.com/#narrow/stream/257879-project-portable-simd/topic/Meeting.202021-10-25/near/259023018

Example loop:

pub fn simd_sum(values: &[f32]) -> f32 {
    let (start, middle, end) = values.safe_align_to::<f32x4>();
    let mut retval = start.iter().sum();
    let mut sum = f32x4::from(0.0);
    for i in middle {
        sum += *i;
    }
    retval + sum.horizontal_sum() + end.iter().sum()
}