From 466274d7f6903bf0477d098723e6914b45001139 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 8 Nov 2016 16:46:15 +0100 Subject: [PATCH] Remove floats from the inner block loop --- src/r_poly_triangle.cpp | 52 +++++++++++++++++++++++++---------------- src/r_triangle.cpp | 39 +++++++++++++++++++------------ 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/r_poly_triangle.cpp b/src/r_poly_triangle.cpp index d77919677..1be35aa26 100644 --- a/src/r_poly_triangle.cpp +++ b/src/r_poly_triangle.cpp @@ -379,17 +379,20 @@ void ScreenPolyTriangleDrawer::draw(const ScreenPolyTriangleDrawerArgs *args, Dr { for (int iy = 0; iy < q; iy++) { - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } for (int ix = x; ix < x + q; ix++) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16; @@ -416,11 +419,14 @@ void ScreenPolyTriangleDrawer::draw(const ScreenPolyTriangleDrawerArgs *args, Dr int CX2 = CY2; int CX3 = CY3; - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - pos) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } for (int ix = x; ix < x + q; ix++) @@ -429,8 +435,8 @@ void ScreenPolyTriangleDrawer::draw(const ScreenPolyTriangleDrawerArgs *args, Dr if (CX1 > 0 && CX2 > 0 && CX3 > 0 && visible) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16; @@ -765,17 +771,20 @@ void ScreenPolyTriangleDrawer::draw32(const ScreenPolyTriangleDrawerArgs *args, { for (int iy = 0; iy < q; iy++) { - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - pos) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } for (int ix = x; ix < x + q; ix++) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16; @@ -809,11 +818,14 @@ void ScreenPolyTriangleDrawer::draw32(const ScreenPolyTriangleDrawerArgs *args, int CX2 = CY2; int CX3 = CY3; - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - pos) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } for (int ix = x; ix < x + q; ix++) @@ -822,8 +834,8 @@ void ScreenPolyTriangleDrawer::draw32(const ScreenPolyTriangleDrawerArgs *args, if (CX1 > 0 && CX2 > 0 && CX3 > 0 && visible) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16; diff --git a/src/r_triangle.cpp b/src/r_triangle.cpp index a95e6d0db..95e4e636e 100644 --- a/src/r_triangle.cpp +++ b/src/r_triangle.cpp @@ -402,17 +402,20 @@ void ScreenTriangleDrawer::draw(const ScreenTriangleDrawerArgs *args, DrawerThre { for (int iy = 0; iy < q; iy++) { - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - pos) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } for (int ix = x; ix < x + q; ix++) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16; @@ -439,11 +442,14 @@ void ScreenTriangleDrawer::draw(const ScreenTriangleDrawerArgs *args, DrawerThre int CX2 = CY2; int CX3 = CY3; - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - pos) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } for (int ix = x; ix < x + q; ix++) @@ -452,8 +458,8 @@ void ScreenTriangleDrawer::draw(const ScreenTriangleDrawerArgs *args, DrawerThre if (CX1 > 0 && CX2 > 0 && CX3 > 0 && visible) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16; @@ -808,19 +814,22 @@ void ScreenTriangleDrawer::draw32(const ScreenTriangleDrawerArgs *args, DrawerTh { for (int iy = 0; iy < q; iy++) { - float varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; + uint32_t varying[TriVertex::NumVarying], varyingStep[TriVertex::NumVarying]; for (int i = 0; i < TriVertex::NumVarying; i++) { - varying[i] = varyingTL[i] + varyingBL[i] * iy; - varyingStep[i] = (varyingTR[i] + varyingBR[i] * iy - varying[i]) * (1.0f / q); + float pos = varyingTL[i] + varyingBL[i] * iy; + float step = (varyingTR[i] + varyingBR[i] * iy - pos) * (1.0f / q); + + varying[i] = (uint32_t)((pos - floor(pos)) * 0x100000000LL); + varyingStep[i] = (uint32_t)(step * 0x100000000LL); } if (!thread->skipped_by_thread(y + iy)) { for (int ix = x; ix < x + q; ix++) { - uint32_t ufrac = (uint32_t)((varying[0] - floor(varying[0])) * 0x100000000LL); - uint32_t vfrac = (uint32_t)((varying[1] - floor(varying[1])) * 0x100000000LL); + uint32_t ufrac = varying[0]; + uint32_t vfrac = varying[1]; uint32_t upos = ((ufrac >> 16) * textureWidth) >> 16; uint32_t vpos = ((vfrac >> 16) * textureHeight) >> 16;