mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Merge branch 'improve-point-in-subsector-performance' into 'next'
Avoid branch prediction slowdowns in R_PointOnSide See merge request STJr/SRB2!2168
This commit is contained in:
commit
219dac16cb
1 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue