1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Fallback implementation in case no explicit `sse` or `avx` support is available.
//! In this case we use the standard versions of all functions which and no approximations.
//! We do that since this way the API doesn't change (so much) depending on the selected features.
//! However at the same time finding an alternative approximation implementation without
//! explicit SIMD support would be too much effort and therefore we use the standard functions.
//! This way we can also be sure that we achieve the promised unertainty :).
//! The Rust compiler does a good job to remove the otherhead of this implementation.
//! So in benchmarks this implementation has the same speed as the the standard functions.

use super::fallback;
use super::{SimdApproximations, SimdGeneric};

macro_rules! simd_approx_impl {
    ($data_type:ident,
	 $regf:ident) => {
        impl SimdApproximations<$data_type> for fallback::$regf {
            fn ln_approx(self) -> Self {
                self.iter_over_vector(|x: $data_type| x.ln())
            }

            fn exp_approx(self) -> Self {
                self.iter_over_vector(|x: $data_type| x.exp())
            }

            fn sin_approx(self) -> Self {
                self.iter_over_vector(|x: $data_type| x.sin())
            }

            fn cos_approx(self) -> Self {
                self.iter_over_vector(|x: $data_type| x.cos())
            }

            fn sin_cos_approx(self, is_sin: bool) -> Self {
                if is_sin {
                    self.sin_approx()
                } else {
                    self.cos_approx()
                }
            }
        }
    };
}

simd_approx_impl!(f32, f32x4);
simd_approx_impl!(f64, f64x2);