From 2ffb37e8ecaf9870f7628669c35310f32d2d3f9b Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Sep 2024 18:43:24 +0200 Subject: [PATCH] Revert "Reapply "optimize pointon functions"" This reverts commit 47dad991b9537d9c0060e8f3065c5d96e14c1898. --- src/p_maputl.c | 29 +++++++++++++++++++++-------- src/r_main.c | 7 +++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index 63430f35f..fc7ea89ec 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -136,16 +136,21 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte // FUNCINLINE ATTRINLINE PUREFUNC INT32 P_PointOnLineSide(fixed_t x, fixed_t y, const line_t *line) { + fixed_t dx, dy, left, right; + if (!line->dx) return x <= line->v1->x ? line->dy > 0 : line->dy < 0; if (!line->dy) return y <= line->v1->y ? line->dx < 0 : line->dx > 0; - x -= line->v1->x; - y -= line->v1->y; + dx = (x - line->v1->x); + dy = (y - line->v1->y); - return FixedMul(y, line->dx>>FRACBITS) > FixedMul(line->dy>>FRACBITS, x); + left = FixedMul(line->dy>>FRACBITS, dx); + right = FixedMul(dy, line->dx>>FRACBITS); + + return right < left ? 0 : 1; } // @@ -205,20 +210,28 @@ PUREFUNC INT32 P_BoxOnLineSide(fixed_t *tmbox, const line_t *ld) // FUNCINLINE static ATTRINLINE PUREFUNC INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *line) { + fixed_t dx, dy, left, right; + if (!line->dx) return x <= line->x ? line->dy > 0 : line->dy < 0; if (!line->dy) return y <= line->y ? line->dx < 0 : line->dx > 0; - x -= line->x; - y -= line->y; + dx = (x - line->x); + dy = (y - line->y); - INT32 mask = ((line->dy ^ line->dx ^ x ^ y) & 0x80000000); - return (mask & ((line->dy ^ x) & 0x80000000)) | - (~mask & (FixedMul(y>>8, line->dx>>8) > FixedMul(line->dy>>8, x>>8))); + // try to quickly decide by looking at sign bits + if ((line->dy ^ line->dx ^ dx ^ dy) & 0x80000000) + return ((line->dy ^ dx) & 0x80000000) ? 1 : 0; + + left = FixedMul(line->dy>>8, dx>>8); + right = FixedMul(dy>>8, line->dx>>8); + + return right < left ? 0 : 1; } + // // P_MakeDivline // diff --git a/src/r_main.c b/src/r_main.c index 8599030ca..dee8ad4fb 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -400,10 +400,9 @@ FUNCINLINE ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, cons y -= ly; // Try to quickly decide by looking at sign bits. - // also use a mask to avoid branch prediction - INT32 mask = (ldy ^ ldx ^ x ^ y) >> 31; - return (mask & ((ldy ^ x) < 0)) | // (left is negative) - (~mask & (FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x))); + if ((ldy ^ ldx ^ x ^ y) < 0) + return (ldy ^ x) < 0; // (left is negative) + return FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x); } //