# HG changeset patch # User Link Mauve # Date 1768655998 -3600 # Node ID a29122662cde809f603b276273a84257a9694f9e # Parent d005f592744700cc6151c673777f3e62ba21ff5e 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. diff --git a/utils/src/math.rs b/utils/src/math.rs --- 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; + }); } }