mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-26 20:11:47 +00:00
Avoid branch prediction slowdowns in R_PointOnSide
# Conflicts: # src/r_main.c
This commit is contained in:
parent
bcc8fc6438
commit
2f01c6fa16
1 changed files with 5 additions and 4 deletions
|
|
@ -218,7 +218,7 @@ void ChaseCam4_OnChange(void)
|
||||||
//
|
//
|
||||||
// killough 5/2/98: reformatted
|
// 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)
|
if (!node->dx)
|
||||||
return x <= node->x ? node->dy > 0 : node->dy < 0;
|
return x <= node->x ? node->dy > 0 : node->dy < 0;
|
||||||
|
|
@ -230,9 +230,10 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node)
|
||||||
y -= node->y;
|
y -= node->y;
|
||||||
|
|
||||||
// Try to quickly decide by looking at sign bits.
|
// Try to quickly decide by looking at sign bits.
|
||||||
if ((node->dy ^ node->dx ^ x ^ y) < 0)
|
// also use a mask to avoid branch prediction
|
||||||
return (node->dy ^ x) < 0; // (left is negative)
|
INT32 mask = (node->dy ^ node->dx ^ x ^ y) >> 31;
|
||||||
return FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x);
|
return (mask & ((node->dy ^ x) < 0)) | // (left is negative)
|
||||||
|
(~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// killough 5/2/98: reformatted
|
// killough 5/2/98: reformatted
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue