From 6b4e81e1ec607b6985c8b5a2328cb25cfd70a93f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 13 Mar 2024 06:00:37 +0100 Subject: [PATCH] P_PointOnDivlineSide stuff --- src/p_maputl.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index 8d9709185..3fe49bdf8 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -205,9 +205,9 @@ PUREFUNC INT32 P_BoxOnLineSide(fixed_t *tmbox, const line_t *ld) // P_PointOnDivlineSide // Returns 0 or 1. // -PUREFUNC FUNCINLINE static ATTRINLINE INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *restrict line) +PUREFUNC FUNCINLINE static ATTRINLINE INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *line) { - fixed_t dx, dy; + fixed_t dx, dy, left, right; if (!line->dx) return (x <= line->x) ^ (line->dy <= 0); @@ -218,13 +218,19 @@ PUREFUNC FUNCINLINE static ATTRINLINE INT32 P_PointOnDivlineSide(fixed_t x, fixe dx = (x - line->x); dy = (y - line->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>>8, line->dx>>8) >= FixedMul(line->dy>>8, dx>>8))); -} + // try to quickly decide by looking at sign bits + if ((line->dy ^ line->dx ^ dx ^ dy) & 0x80000000) + { + if ((line->dy ^ dx) & 0x80000000) + return 1; // left is negative + return 0; + } + left = FixedMul(line->dy>>8, dx>>8); + right = FixedMul(dy>>8, line->dx>>8); + + return right >= left; +} // // P_MakeDivline