From c13cb0b8d9eb6fe3161e2fb09383c0a652014179 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 04:15:28 +0200 Subject: [PATCH] Reapply "optimize R_PointOnSegSide" This reverts commit 5b3daac4c86362a283333897d64311b0f0caf88d. --- src/r_main.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/r_main.h b/src/r_main.h index 8b93ec755..1cc09a346 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -106,20 +106,8 @@ FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t fixed_t ldx = line->v2->x - lx; fixed_t ldy = line->v2->y - ly; - if (!ldx) - return x <= lx ? ldy > 0 : ldy < 0; - - if (!ldy) - return y <= ly ? ldx < 0 : ldx > 0; - - x -= lx; - 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))); + // heavily optimized version of R_PointOnSide, stolen from GZDoom. + return (INT64)(y - ly) * ldx + (INT64)(lx - x) * ldy > 0; } angle_t R_PointToAngle(fixed_t x, fixed_t y);