From 02e6463fae82d8bb31e9f3ceab994cb572a52a75 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 13 Mar 2024 08:35:09 +0100 Subject: [PATCH] Revert "P_PointOnDivlineSide stuff" This reverts commit 1fa738d46448bd716547aa1812e38ec0de2221d1. --- src/p_maputl.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index ed078e5e6..71938aab6 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 static INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *line) +PUREFUNC FUNCINLINE static ATTRINLINE INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *restrict line) { - fixed_t dx, dy, left, right; + fixed_t dx, dy; if (!line->dx) return (x <= line->x) ^ (line->dy <= 0); @@ -218,20 +218,14 @@ PUREFUNC static INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t dx = (x - line->x); dy = (y - line->y); - // 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; + // 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))); } + // // P_MakeDivline //