SIMD instructions for folded iterator

⚓ Rust    📅 2026-01-18    👤 surdeus    👁️ 6      

surdeus

Hi all,

I wrote the below test code below to do an empirical statistics test (it approximates the propability you can form a triangle by breaking a line in two random locations).

I cannot get the main loop formed by the folded iter to produce SIMD instructions. Is there something inherent to the fold closure that would prevent that?

use rand::random_iter;

pub fn main() {
    let iterations:usize = 1000000000;

    let triangles = random_iter::<u32>()
    .zip(random_iter::<u32>())
    .take(iterations)
    .fold(0, |acc, (br1,br2)| acc + ((br1.abs_diff(br2) < 0x80000000) as u32));

    println!("{:#10}", triangles);
    println!("----------");
    println!("{:?}", iterations);
}

3 posts - 3 participants

Read full topic

🏷️ Rust_feed