From 16db0ba29000ed85f507b0fa1f9686ef789cabe0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Oct 2024 00:19:18 +0200 Subject: [PATCH] do this instead --- src/r_main.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/r_main.h b/src/r_main.h index ef0a8c3bc..8b93ec755 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -116,9 +116,10 @@ FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y -= ly; // Try to quickly decide by looking at sign bits. - if ((ldy ^ ldx ^ x ^ y) < 0) - return (ldy ^ x) < 0; // (left is negative) - return FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x); + // 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))); } angle_t R_PointToAngle(fixed_t x, fixed_t y);