From c5b9c3d36de4a72701dcd76e2256e95f3448fffb Mon Sep 17 00:00:00 2001 From: Jaklyy <102590697+Jaklyy@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:38:12 -0400 Subject: [PATCH] optimization attempt --- src/GPU3D_Soft.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index 4aa5e77f..9e1e2c13 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -87,13 +87,16 @@ private: if (z0 < z1) { // remainder is unused for this path - this->zquo = ((z1 - z0) >> 1) / xdiff; + this->zquo = ((z1 - z0) >> 1) / xdiff << 1; + this->zcounter = z0; } else { // should optimize down to one divide instruction - this->zquo = ((z0 - z1) >> 1) / xdiff; - this->zrem = ((z0 - z1) >> 1) % xdiff; + this->zquo = ((z0 - z1) >> 1) / xdiff << 1; + s32 rem = ((z0 - z1) >> 1) % xdiff << 1; + s32 idk = zquo * xdiff; + this->zcounter = z1 + idk + rem; } } @@ -154,7 +157,7 @@ private: constexpr s32 Interpolate(s32 y0, s32 y1) const { - if (xdiff == 0 || y0 == y1) return y0; + if (x == 0 || y0 == y1) return y0; if (!linear) { @@ -174,9 +177,9 @@ private: } } - constexpr s32 InterpolateZ(s32 z0, s32 z1) const + constexpr s32 InterpolateZ(s32 z0, s32 z1) { - if (xdiff == 0 || z0 == z1) return z0; + if (x == 0 || z0 == z1) return z0; if (wbuffer) { @@ -204,9 +207,15 @@ private: { // these algorithms are weiiird but i can't argue with the results if (z0 < z1) - return z0 + ((zquo * x) << 1); + { + zcounter += zquo; + return zcounter; + } else - return z1 + ((zquo * (xdiff-x) + zrem) << 1); + { + zcounter -= zquo; + return zcounter; + } } } } @@ -218,7 +227,8 @@ private: bool linear; bool wbuffer; - s32 zquo, zrem; + s32 zquo; + s32 zcounter; s32 w0n, w0d, w1d; u32 yfactor;