Mercurial > touhou
changeset 791:a29122662cde
utils: Simplify translate_2d and align Mat4 to 16 bytes
This lowers the amount of instructions from 61 to 32 on PowerPC with AltiVec,
and from 25 to 14 on amd64 with AVX2.
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Sat, 17 Jan 2026 14:19:58 +0100 |
| parents | d005f5927447 |
| children | 11bc22bad1bf |
| files | utils/src/math.rs |
| diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/utils/src/math.rs +++ b/utils/src/math.rs @@ -3,6 +3,7 @@ use const_for::const_for; /// A 4×4 f32 matrix type. +#[repr(align(16))] pub struct Mat4 { inner: [[f32; 4]; 4] } @@ -109,9 +110,13 @@ } /// Translate the matrix by a 2D offset. - pub const fn translate_2d(&mut self, x: f32, y: f32) { - let offset = [x, y, 0.]; - self.translate(offset); + pub const fn translate_2d(&mut self, mut x: f32, mut y: f32) { + x *= self.inner[3][0]; + y *= self.inner[3][1]; + const_for!(i in 0..4 => { + self.inner[0][i] += x; + self.inner[1][i] += y; + }); } }
