]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | //! Implements vertical (lane-wise) floating-point `mul_add`. |
2 | ||
3 | macro_rules! impl_math_float_mul_add { | |
4 | ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { | |
5 | impl $id { | |
6 | /// Fused multiply add: `self * y + z` | |
7 | #[inline] | |
8 | pub fn mul_add(self, y: Self, z: Self) -> Self { | |
9 | use crate::codegen::math::float::mul_add::MulAdd; | |
10 | MulAdd::mul_add(self, y, z) | |
11 | } | |
12 | } | |
13 | ||
14 | test_if!{ | |
15 | $test_tt: | |
16 | paste::item! { | |
17 | pub mod [<$id _math_mul_add>] { | |
18 | use super::*; | |
19 | #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] | |
20 | fn mul_add() { | |
21 | let z = $id::splat(0 as $elem_ty); | |
22 | let o = $id::splat(1 as $elem_ty); | |
23 | let t = $id::splat(2 as $elem_ty); | |
24 | let t3 = $id::splat(3 as $elem_ty); | |
25 | let f = $id::splat(4 as $elem_ty); | |
26 | ||
27 | assert_eq!(z, z.mul_add(z, z)); | |
28 | assert_eq!(o, o.mul_add(o, z)); | |
29 | assert_eq!(o, o.mul_add(z, o)); | |
30 | assert_eq!(o, z.mul_add(o, o)); | |
31 | ||
32 | assert_eq!(t, o.mul_add(o, o)); | |
33 | assert_eq!(t, o.mul_add(t, z)); | |
34 | assert_eq!(t, t.mul_add(o, z)); | |
35 | ||
36 | assert_eq!(f, t.mul_add(t, z)); | |
37 | assert_eq!(f, t.mul_add(o, t)); | |
38 | assert_eq!(t3, t.mul_add(o, o)); | |
39 | } | |
40 | } | |
41 | } | |
42 | } | |
43 | }; | |
44 | } |