[Mesa-dev] use of likey() / unlikely() macros

Brian Paul brianp at vmware.com
Thu Jan 17 08:37:25 PST 2013


In compiler.h we define the likely(), unlikely() macros which wrap 
GCC's __builtin_expect().  But we only use them in a handful of places.

It seems to me that an obvious place to possibly use these would be 
for GL error testing.  For example, in glDrawArrays():

    if (unlikely(count <= 0)) {
       _mesa_error();
    }

Plus, in some of the glBegin/End per-vertex calls such as 
glVertexAttrib3fARB() where we error test the index parameter.

I guess the key question is how much might we gain from this.  I don't 
really have a good feel for the value at this level.  In a tight inner 
loop, sure, but the GL error checking is pretty high-level code.

I haven't found much on the web about performance gains from 
__builtin_expect().  Anyone?

-Brian



More information about the mesa-dev mailing list