Skip to content
Snippets Groups Projects
Unverified Commit 12d59539 authored by Hanicef's avatar Hanicef
Browse files

Avoid branch prediction slowdowns in R_PointOnSide

parent a373d96d
No related branches found
No related tags found
2 merge requests!2355fix newer versions of mixerx,!2168Avoid branch prediction slowdowns in R_PointOnSide
......@@ -249,7 +249,7 @@ static void FlipCam2_OnChange(void)
//
// killough 5/2/98: reformatted
//
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node)
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *restrict node)
{
if (!node->dx)
return x <= node->x ? node->dy > 0 : node->dy < 0;
......@@ -261,9 +261,10 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node)
fixed_t dy = (y >> 1) - (node->y >> 1);
// Try to quickly decide by looking at sign bits.
if ((node->dy ^ node->dx ^ dx ^ dy) < 0)
return (node->dy ^ dx) < 0; // (left is negative)
return FixedMul(dy, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, dx);
// also use a mask to avoid branch prediction
INT32 mask = (node->dy ^ node->dx ^ dx ^ dy) >> 31;
return (mask & ((node->dy ^ dx) < 0)) | // (left is negative)
(~mask & (FixedMul(dy, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, dx)));
}
// killough 5/2/98: reformatted
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment