| #![feature(portable_simd)] |
| |
| macro_rules! unary_test { |
| { $scalar:tt, $($func:tt),+ } => { |
| test_helpers::test_lanes! { |
| $( |
| fn $func<const LANES: usize>() { |
| test_helpers::test_unary_elementwise( |
| &core_simd::simd::Simd::<$scalar, LANES>::$func, |
| &$scalar::$func, |
| &|_| true, |
| ) |
| } |
| )* |
| } |
| } |
| } |
| |
| macro_rules! unary_approx_test { |
| { $scalar:tt, $($func:tt),+ } => { |
| test_helpers::test_lanes! { |
| $( |
| fn $func<const LANES: usize>() { |
| test_helpers::test_unary_elementwise_approx( |
| &core_simd::simd::Simd::<$scalar, LANES>::$func, |
| &$scalar::$func, |
| &|_| true, |
| 16, |
| ) |
| } |
| )* |
| } |
| } |
| } |
| |
| macro_rules! ternary_test { |
| { $scalar:tt, $($func:tt),+ } => { |
| test_helpers::test_lanes! { |
| $( |
| fn $func<const LANES: usize>() { |
| test_helpers::test_ternary_elementwise( |
| &core_simd::simd::Simd::<$scalar, LANES>::$func, |
| &$scalar::$func, |
| &|_, _, _| true, |
| ) |
| } |
| )* |
| } |
| } |
| } |
| |
| macro_rules! impl_tests { |
| { $scalar:tt } => { |
| mod $scalar { |
| use std_float::StdFloat; |
| |
| unary_test! { $scalar, sqrt, ceil, floor, round, trunc, round_ties_even } |
| ternary_test! { $scalar, mul_add } |
| |
| // https://github.com/rust-lang/miri/issues/3555 |
| unary_approx_test! { $scalar, sin, cos, exp, exp2, ln, log2, log10 } |
| |
| // The implementation of log is a.ln() / b.ln(), so there are 2 inexact operations, |
| // hence a larger ulps is needed. |
| test_helpers::test_lanes! { |
| fn log<const LANES: usize>() { |
| test_helpers::test_binary_elementwise_approx( |
| &core_simd::simd::Simd::<$scalar, LANES>::log, |
| &$scalar::log, |
| &|_, _| true, |
| 32, |
| ) |
| } |
| } |
| |
| test_helpers::test_lanes! { |
| fn fract<const LANES: usize>() { |
| test_helpers::test_unary_elementwise_flush_subnormals( |
| &core_simd::simd::Simd::<$scalar, LANES>::fract, |
| &$scalar::fract, |
| &|_| true, |
| ) |
| } |
| } |
| } |
| } |
| } |
| |
| impl_tests! { f32 } |
| impl_tests! { f64 } |