| 1 | // Copyright 2020 Yevhenii Reizner |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | |
| 6 | // Right now, there are no visible benefits of using SIMD for f32x4. So we don't. |
| 7 | #[derive (Default, Clone, Copy, PartialEq, Debug)] |
| 8 | #[repr (C, align(16))] |
| 9 | pub struct f32x4(pub [f32; 4]); |
| 10 | |
| 11 | impl f32x4 { |
| 12 | pub fn max(self, rhs: Self) -> Self { |
| 13 | Self([ |
| 14 | self.0[0].max(rhs.0[0]), |
| 15 | self.0[1].max(rhs.0[1]), |
| 16 | self.0[2].max(rhs.0[2]), |
| 17 | self.0[3].max(rhs.0[3]), |
| 18 | ]) |
| 19 | } |
| 20 | |
| 21 | pub fn min(self, rhs: Self) -> Self { |
| 22 | Self([ |
| 23 | self.0[0].min(rhs.0[0]), |
| 24 | self.0[1].min(rhs.0[1]), |
| 25 | self.0[2].min(rhs.0[2]), |
| 26 | self.0[3].min(rhs.0[3]), |
| 27 | ]) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | impl core::ops::Add for f32x4 { |
| 32 | type Output = Self; |
| 33 | |
| 34 | fn add(self, rhs: Self) -> Self::Output { |
| 35 | Self([ |
| 36 | self.0[0] + rhs.0[0], |
| 37 | self.0[1] + rhs.0[1], |
| 38 | self.0[2] + rhs.0[2], |
| 39 | self.0[3] + rhs.0[3], |
| 40 | ]) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl core::ops::AddAssign for f32x4 { |
| 45 | fn add_assign(&mut self, rhs: f32x4) { |
| 46 | *self = *self + rhs; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | impl core::ops::Sub for f32x4 { |
| 51 | type Output = Self; |
| 52 | |
| 53 | fn sub(self, rhs: Self) -> Self::Output { |
| 54 | Self([ |
| 55 | self.0[0] - rhs.0[0], |
| 56 | self.0[1] - rhs.0[1], |
| 57 | self.0[2] - rhs.0[2], |
| 58 | self.0[3] - rhs.0[3], |
| 59 | ]) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl core::ops::Mul for f32x4 { |
| 64 | type Output = Self; |
| 65 | |
| 66 | fn mul(self, rhs: Self) -> Self::Output { |
| 67 | Self([ |
| 68 | self.0[0] * rhs.0[0], |
| 69 | self.0[1] * rhs.0[1], |
| 70 | self.0[2] * rhs.0[2], |
| 71 | self.0[3] * rhs.0[3], |
| 72 | ]) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl core::ops::MulAssign for f32x4 { |
| 77 | fn mul_assign(&mut self, rhs: f32x4) { |
| 78 | *self = *self * rhs; |
| 79 | } |
| 80 | } |
| 81 | |