From a57089c1a9f2205ac7b057eaa24db88e5d82ae03 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 12 Mar 2024 16:16:40 +0100 Subject: [PATCH] fix some oopsies --- src/p_maputl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index 51f6de4fa..b18e6aecf 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -148,11 +148,10 @@ PUREFUNC FUNCINLINE ATTRINLINE INT32 P_PointOnLineSide(fixed_t x, fixed_t y, con dx = (x - v1->x); dy = (y - v1->y); - // Try to quickly decide by looking at sign bits. - // also use a mask to avoid branch prediction - INT32 mask = (line->dy ^ line->dx ^ dx ^ dy) >> 31; - return (mask & ((line->dy ^ dx) < 0)) | // (left is negative) - (~mask & (FixedMul(dy, line->dx>>FRACBITS) >= FixedMul(line->dy>>FRACBITS, dx))); + left = FixedMul(line->dy>>FRACBITS, dx); + right = FixedMul(dy, line->dx>>FRACBITS); + + return right < left ? 0 : 1; } // @@ -178,7 +177,7 @@ PUREFUNC INT32 P_BoxOnLineSide(fixed_t *tmbox, const line_t *ld) case ST_VERTICAL: p1 = tmbox[BOXRIGHT] < ld->v1->x; p2 = tmbox[BOXLEFT] < ld->v1->x; - optCmp = ld->dx < 0; + optCmp = ld->dy < 0; p1 ^= optCmp; p2 ^= optCmp; break; @@ -224,7 +223,7 @@ PUREFUNC FUNCINLINE static ATTRINLINE INT32 P_PointOnDivlineSide(fixed_t x, fixe // also use a mask to avoid branch prediction INT32 mask = (line->dy ^ line->dx ^ dx ^ dy) >> 31; return (mask & ((line->dy ^ dx) < 0)) | // (left is negative) - (~mask & (FixedMul(dy, line->dx>>FRACBITS) >= FixedMul(line->dy>>FRACBITS, dx))); + (~mask & (FixedMul(dy>>8, line->dx>>8) >= FixedMul(line->dy>>8, dx>>8))); }