From 5296f5c79c0137aad7bf9fccdd5a75a864b0d55a Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Sat, 5 Nov 2022 20:28:24 +0000 Subject: [PATCH] Optimise perspective divide assuming W is always positive --- GL/platforms/sh4.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/GL/platforms/sh4.c b/GL/platforms/sh4.c index 156adf3..33a5f8f 100644 --- a/GL/platforms/sh4.c +++ b/GL/platforms/sh4.c @@ -47,11 +47,12 @@ void SceneListBegin(GPUList list) { pvr_list_begin(list); } +__attribute__((optimize("O3", "fast-math"))) GL_FORCE_INLINE float _glFastInvert(float x) { - const float sgn = (x > 0) - (x < 0); - return sgn * (1.f / __builtin_sqrtf(x * x)); + return (1.f / __builtin_sqrtf(x * x)); } +__attribute__((optimize("O3", "fast-math"))) GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex, const float h) { const float f = _glFastInvert(vertex->w); @@ -69,11 +70,8 @@ GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex, const float h) { we add 1.0 to the Z to bring it into range. We add a little extra to avoid a divide by zero. */ - if(unlikely(vertex->w == 1.0f)) { - vertex->xyz[2] = _glFastInvert(1.0001f + vertex->xyz[2]); - } else { - vertex->xyz[2] = f; - } + + vertex->xyz[2] = (vertex->w == 1.0f) ? _glFastInvert(1.0001f + vertex->xyz[2]) : f; } static uint32_t *d; // SQ target