/// Complex number #[repr(align(16))] #[derive(Copy, Clone)] struct Complex {     real: f64,     imag: f64, }  /// Returns the number of iterations it

Beyond multi-core parallelism: faster Mandelbrot with SIMD

submited by
Style Pass
2024-10-01 00:30:02

/// Complex number #[repr(align(16))] #[derive(Copy, Clone)] struct Complex { real: f64, imag: f64, } /// Returns the number of iterations it takes for the /// Mandelbrot sequence to diverge at this point, or /// `ITER_LIMIT` if it doesn't diverge. fn get_count(start: Complex) -> u32 { let mut current = start.clone(); for iteration in 0..ITER_LIMIT { let rr = current.real * current.real; let ii = current.imag * current.imag; if rr + ii > THRESHOLD { return iteration; } let ri = current.real * current.imag; current.real = start.real + (rr - ii); current.imag = start.imag + (ri + ri); } // Rust has an implicit return for expressions // without a semi-colon at the end of a function: ITER_LIMIT }

/// Complex number #[repr(align(16))] #[derive(Copy, Clone)] struct Complex { real: f64, imag: f64, } /// Returns the number of iterations it takes for the /// Mandelbrot sequence to diverge at this point, or /// `ITER_LIMIT` if it doesn't diverge. fn get_count(start: Complex) -> u32 { let mut current = start.clone(); for iteration in 0..ITER_LIMIT { let rr = current.real * current.real; let ii = current.imag * current.imag; if rr + ii > THRESHOLD { return iteration; } let ri = current.real * current.imag; current.real = start.real + (rr - ii); current.imag = start.imag + (ri + ri); } // Rust has an implicit return for expressions // without a semi-colon at the end of a function: ITER_LIMIT }

Leave a Comment