try to rectify some branch mispredictions
adds "LIKELY" and "UNLIKELY" macros those can be used to tell the compiler which path is more likely to happen
This commit is contained in:
1 parent
418d265f51
commit
f48ce0d94a
4 files changed
+31
-17
No files matched your search
@@ -547,6 +547,19 @@ UINT32 quickncasehash (const char *p, size_t n)
|
||||
#define DBL_EPSILON 2.2204460492503131e-16l
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#ifndef LIKELY
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#endif
|
||||
|
||||
#ifndef UNLIKELY
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#endif
|
||||
#else
|
||||
#define LIKELY(x) (x)
|
||||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
// An assert-type mechanism.
|
||||
#ifdef PARANOIA
|
||||
#define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__))
|
||||
|
||||
@@ -331,8 +331,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
|
||||
gltex->mipmap.format = textureformat;
|
||||
|
||||
// hack the Legacy skies..
|
||||
if (strncmp(texture->name, "SKY", 3) == 0 &&
|
||||
(texture->name[4] == 0 || texture->name[5] == 0))
|
||||
if (UNLIKELY(strncmp(texture->name, "SKY", 3) == 0 &&
|
||||
(texture->name[4] == 0 || texture->name[5] == 0)))
|
||||
{
|
||||
skyspecial = true;
|
||||
gltex->mipmap.flags &= ~TF_CHROMAKEYED; // don't use the chromakey for sky
|
||||
@@ -349,7 +349,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
|
||||
blocksize = (blockwidth * blockheight);
|
||||
block = MakeBlock(&gltex->mipmap);
|
||||
|
||||
if (skyspecial) // Hurdler: not efficient, but better than holes in the sky (and it's done only at level loading)
|
||||
if (UNLIKELY(skyspecial)) // Hurdler: not efficient, but better than holes in the sky (and it's done only at level loading)
|
||||
{
|
||||
INT32 j;
|
||||
RGBA_t col;
|
||||
@@ -994,11 +994,11 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap)
|
||||
|
||||
// search for the mipmap
|
||||
// skip the first (no colormap translated)
|
||||
for (glMipmap = glPatch->mipmap; glMipmap->nextcolormap;)
|
||||
for (glMipmap = glPatch->mipmap; LIKELY(glMipmap->nextcolormap);)
|
||||
{
|
||||
glMipmap = glMipmap->nextcolormap;
|
||||
|
||||
if (glMipmap->colormap == colormap)
|
||||
if (UNLIKELY(glMipmap->colormap == colormap))
|
||||
{
|
||||
HWR_LoadMappedPatch(glMipmap, glPatch);
|
||||
return;
|
||||
|
||||
+12
-11
@@ -1281,7 +1281,7 @@ static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf)
|
||||
|
||||
pSurf->PolyColor.s.alpha = 0xFF;
|
||||
|
||||
if (!gl_curline->polyseg)
|
||||
if (LIKELY(!gl_curline->polyseg))
|
||||
{
|
||||
// set alpha for transparent walls
|
||||
switch (gl_linedef->special)
|
||||
@@ -1362,7 +1362,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
|
||||
|
||||
const boolean noencore = (gl_linedef->flags & ML_TFERLINE);
|
||||
|
||||
if (gl_curline->pv1)
|
||||
if (LIKELY(gl_curline->pv1))
|
||||
{
|
||||
vs.x = ((polyvertex_t *)gl_curline->pv1)->x;
|
||||
vs.y = ((polyvertex_t *)gl_curline->pv1)->y;
|
||||
@@ -1377,7 +1377,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
|
||||
v1y = gl_curline->v1->y;
|
||||
}
|
||||
|
||||
if (gl_curline->pv2)
|
||||
if (LIKELY(gl_curline->pv2))
|
||||
{
|
||||
ve.x = ((polyvertex_t *)gl_curline->pv2)->x;
|
||||
ve.y = ((polyvertex_t *)gl_curline->pv2)->y;
|
||||
@@ -2232,7 +2232,7 @@ static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector)
|
||||
{
|
||||
fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t
|
||||
|
||||
if (gl_curline->pv1)
|
||||
if (LIKELY(gl_curline->pv1))
|
||||
{
|
||||
v1x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->x);
|
||||
v1y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->y);
|
||||
@@ -2242,7 +2242,8 @@ static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector)
|
||||
v1x = gl_curline->v1->x;
|
||||
v1y = gl_curline->v1->y;
|
||||
}
|
||||
if (gl_curline->pv2)
|
||||
|
||||
if (LIKELY(gl_curline->pv2))
|
||||
{
|
||||
v2x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->x);
|
||||
v2y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->y);
|
||||
@@ -2373,7 +2374,7 @@ static void HWR_AddLine(seg_t *line)
|
||||
|
||||
gl_curline = line;
|
||||
|
||||
if (gl_curline->pv1)
|
||||
if (LIKELY(gl_curline->pv1))
|
||||
{
|
||||
v1x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->x);
|
||||
v1y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->y);
|
||||
@@ -2384,7 +2385,7 @@ static void HWR_AddLine(seg_t *line)
|
||||
v1y = gl_curline->v1->y;
|
||||
}
|
||||
|
||||
if (gl_curline->pv2)
|
||||
if (LIKELY(gl_curline->pv2))
|
||||
{
|
||||
v2x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->x);
|
||||
v2y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->y);
|
||||
@@ -2411,7 +2412,7 @@ static void HWR_AddLine(seg_t *line)
|
||||
|
||||
gl_backsector = line->backsector;
|
||||
|
||||
if (!cv_glportals.value || !gl_maphasportals)
|
||||
if (!cv_glportals.value || LIKELY(!gl_maphasportals))
|
||||
goto doaddline;
|
||||
|
||||
// do extra checks on the seg when rendering portals:
|
||||
@@ -2472,7 +2473,7 @@ doaddline:
|
||||
return;
|
||||
}
|
||||
|
||||
if (gl_portal_state != GLPORTAL_SEARCH && !dont_draw)// no need to do this during the portal check
|
||||
if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check
|
||||
HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D
|
||||
|
||||
return;
|
||||
@@ -2960,7 +2961,7 @@ static void HWR_Subsector(size_t num)
|
||||
|
||||
sector_t *controlSec = §ors[rover->secnum];
|
||||
|
||||
if (controlSec->moved != true)
|
||||
if (!controlSec->moved)
|
||||
continue;
|
||||
|
||||
anyMoved = true;
|
||||
@@ -3191,7 +3192,7 @@ doaddline:
|
||||
|
||||
while (count--)
|
||||
{
|
||||
if (!line->polyseg) // ignore segs that belong to polyobjects
|
||||
if (LIKELY(!line->polyseg)) // ignore segs that belong to polyobjects
|
||||
HWR_AddLine(line);
|
||||
line++;
|
||||
}
|
||||
|
||||
+1
-1
@@ -2894,7 +2894,7 @@ void R_ClipSprites(void)
|
||||
/* Check if thing may be drawn from our current view. */
|
||||
boolean R_ThingVisible (mobj_t *thing)
|
||||
{
|
||||
if (thing->sprite == SPR_NULL || (thing->flags2 & MF2_DONTDRAW))
|
||||
if (UNLIKELY(thing->sprite == SPR_NULL) || UNLIKELY((thing->flags2 & MF2_DONTDRAW)))
|
||||
return false;
|
||||
|
||||
if (splitscreen)
|
||||
|
||||
Reference in new issue
Block a user