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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::{
    mem::MaybeUninit,
    ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
};

use crate::{common::*, macros::*};

cfg_if::cfg_if! {
    if #[cfg(sse)] {
        mod sse;
        pub use sse::Vec4f;
    } else if #[cfg(neon)] {
        mod neon;
        pub use neon::Vec4f;
    } else {
        compile_error!("Currently SSE or NEON is required for Vec4f");
        mod fallback;
        pub use fallback::Vec4f;
    }
}

/// Base trait for [`Vec4f`]: a SIMD vector with four elements of type [`f32`].
pub trait Vec4fBase: SIMDBase<4> + SIMDFloat {
    /// Initializes elements of returned vector with given values.
    ///
    /// # Example
    /// ```
    /// # use vrl::prelude::*;
    /// assert_eq!(
    ///     Vec4f::new(1.0, 2.0, 3.0, 4.0),
    ///     [1.0, 2.0, 3.0, 4.0].into()
    /// );
    /// ```
    fn new(v0: f32, v1: f32, v2: f32, v3: f32) -> Self;
}

vec_impl_generic_traits!(Vec4f, f32, 4);
vec_impl_partial_load!(Vec4f, f32, 4);
vec_impl_partial_store!(Vec4f, f32, 4);

impl SIMDVector<4> for Vec4f {}

#[cfg(test)]
mod tests {
    use crate::prelude::*;

    #[test]
    #[inline(never)] // in order to find the function in disassembled binary
    fn it_works() {
        let a = Vec4f::broadcast(1.0);
        assert_eq!(<[f32; 4]>::from(a), [1.0; 4]);
        assert_eq!(a, [1.0; 4].into());

        let b = 2.0 * a;
        assert_ne!(a, b);

        let mut c = b / 2.0;
        assert_eq!(a, c);

        c += Vec4f::from(&[1.0, 0.0, 2.0, 0.0]);
        let d = -c;

        const EXPECTED_D: [f32; 4] = [-2.0, -1.0, -3.0, -1.0];
        assert_eq!(d, EXPECTED_D.into());
        assert_eq!(<[f32; 4]>::from(d), EXPECTED_D);
    }
}