[Mesa-dev] [PATCH excerpt] mesa: Wrap unlikely() around conditions leading to _mesa_error().

Kenneth Graunke kenneth at whitecape.org
Mon Mar 2 14:48:03 PST 2015


Generated by the following Coccinelle semantic patch:

@@
expression E;
@@
if (
-E
+unlikely(E)
 )
{ ... _mesa_error(...) ... }

Improves performance in OglBatch7 (a CPU-bound microbenchmark) on
an i7 4750HQ (Haswell) by 1.08546% +/- 0.519734% (n=292).

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---

Here is an excerpt of the patch with some example hunks - the full
patch is available in the 'unlikely' branch of my tree:

http://cgit.freedesktop.org/~kwg/mesa/commit/?h=unlikely&id=88022120dc0bbe839e96baf42611b36c45faa77f

 src/gallium/state_trackers/glx/xlib/glx_usefont.c |   4 +-
 src/mesa/drivers/common/meta.c                    |   2 +-
 src/mesa/drivers/common/meta_tex_subimage.c       |  10 +-
 src/mesa/drivers/dri/i915/i915_vtbl.c             |   2 +-
 src/mesa/drivers/dri/i915/intel_fbo.c             |   4 +-
 src/mesa/drivers/dri/i915/intel_pixel_bitmap.c    |   6 +-
 src/mesa/drivers/dri/i915/intel_screen.c          |   2 +-
 src/mesa/drivers/dri/i915/intel_tex_image.c       |   3 +-
 src/mesa/drivers/dri/i915/intel_tex_subimage.c    |   7 +-
 src/mesa/drivers/dri/i965/intel_fbo.c             |   8 +-
 src/mesa/drivers/dri/i965/intel_pixel_bitmap.c    |   6 +-
 src/mesa/drivers/dri/i965/intel_screen.c          |   2 +-
 src/mesa/drivers/dri/i965/intel_tex_image.c       |  11 +-
 src/mesa/drivers/dri/radeon/radeon_screen.c       |   2 +-
 src/mesa/drivers/osmesa/osmesa.c                  |   2 +-
 src/mesa/drivers/x11/xfonts.c                     |   4 +-
 src/mesa/drivers/x11/xm_dd.c                      |   6 +-
 src/mesa/main/accum.c                             |  18 +-
 src/mesa/main/api_validate.c                      |  52 ++--
 src/mesa/main/arbprogram.c                        |  33 ++-
 src/mesa/main/arrayobj.c                          |  10 +-
 src/mesa/main/atifragshader.c                     |  97 +++----
 src/mesa/main/attrib.c                            |  30 +-
 src/mesa/main/blend.c                             |  34 +--
 src/mesa/main/blit.c                              |  55 ++--
 src/mesa/main/bufferobj.c                         | 249 ++++++++---------
 src/mesa/main/buffers.c                           |  33 +--
 src/mesa/main/clear.c                             |  20 +-
 src/mesa/main/clip.c                              |   4 +-
 src/mesa/main/condrender.c                        |  10 +-
 src/mesa/main/context.c                           |  16 +-
 src/mesa/main/copyimage.c                         |  46 ++--
 src/mesa/main/depth.c                             |   2 +-
 src/mesa/main/dlist.c                             |  32 +--
 src/mesa/main/drawpix.c                           |   8 +-
 src/mesa/main/drawtex.c                           |   4 +-
 src/mesa/main/enable.c                            |   8 +-
 src/mesa/main/errors.c                            |  15 +-
 src/mesa/main/es1_conversion.c                    |  16 +-
 src/mesa/main/eval.c                              |  44 +--
 src/mesa/main/fbobject.c                          | 105 ++++---
 src/mesa/main/feedback.c                          |  16 +-
 src/mesa/main/ffvertex_prog.c                     |   2 +-
 src/mesa/main/fog.c                               |   8 +-
 src/mesa/main/formatquery.c                       |   7 +-
 src/mesa/main/genmipmap.c                         |  11 +-
 src/mesa/main/get.c                               |  10 +-
 src/mesa/main/getstring.c                         |   4 +-
 src/mesa/main/hint.c                              |   2 +-
 src/mesa/main/light.c                             |  24 +-
 src/mesa/main/lines.c                             |   7 +-
 src/mesa/main/matrix.c                            |  16 +-
 src/mesa/main/mipmap.c                            |  10 +-
 src/mesa/main/multisample.c                       |   8 +-
 src/mesa/main/objectlabel.c                       |  14 +-
 src/mesa/main/pack.c                              |  14 +-
 src/mesa/main/pbo.c                               |  20 +-
 src/mesa/main/performance_monitor.c               |  74 ++---
 src/mesa/main/pipelineobj.c                       |  34 +--
 src/mesa/main/pixel.c                             |  34 +--
 src/mesa/main/pixelstore.c                        |  11 +-
 src/mesa/main/points.c                            |  14 +-
 src/mesa/main/polygon.c                           |  12 +-
 src/mesa/main/queryobj.c                          |  50 ++--
 src/mesa/main/readpix.c                           |  47 ++--
 src/mesa/main/samplerobj.c                        |  32 +--
 src/mesa/main/scissor.c                           |  10 +-
 src/mesa/main/shaderapi.c                         |  43 ++-
 src/mesa/main/shaderimage.c                       |  24 +-
 src/mesa/main/shaderobj.c                         |   8 +-
 src/mesa/main/stencil.c                           |  28 +-
 src/mesa/main/syncobj.c                           |  18 +-
 src/mesa/main/texcompress_fxt1.c                  |   2 +-
 src/mesa/main/texenv.c                            |  15 +-
 src/mesa/main/texgen.c                            |  37 ++-
 src/mesa/main/texgetimage.c                       |  48 ++--
 src/mesa/main/teximage.c                          | 322 +++++++++-------------
 src/mesa/main/texobj.c                            |  52 ++--
 src/mesa/main/texparam.c                          |  43 ++-
 src/mesa/main/texstate.c                          |   4 +-
 src/mesa/main/texstorage.c                        |  36 ++-
 src/mesa/main/texstore.c                          |   8 +-
 src/mesa/main/textureview.c                       |  35 ++-
 src/mesa/main/transformfeedback.c                 |  74 +++--
 src/mesa/main/uniforms.c                          |  34 +--
 src/mesa/main/varray.c                            | 117 ++++----
 src/mesa/main/vdpau.c                             |  61 ++--
 src/mesa/main/viewport.c                          |  20 +-
 src/mesa/program/arbprogparse.c                   |   3 +-
 src/mesa/program/program_parse.y                  |   4 +-
 src/mesa/program/programopt.c                     |   6 +-
 src/mesa/state_tracker/st_atom_pixeltransfer.c    |   2 +-
 src/mesa/state_tracker/st_cb_drawpixels.c         |   2 +-
 src/mesa/state_tracker/st_cb_fbo.c                |   2 +-
 src/mesa/state_tracker/st_cb_texture.c            |   6 +-
 src/mesa/state_tracker/st_draw.c                  |   2 +-
 src/mesa/state_tracker/st_gen_mipmap.c            |   2 +-
 src/mesa/state_tracker/st_vdpau.c                 |  16 +-
 src/mesa/swrast/s_copypix.c                       |  16 +-
 src/mesa/swrast/s_depth.c                         |   4 +-
 src/mesa/swrast/s_drawpix.c                       |  12 +-
 src/mesa/swrast/s_renderbuffer.c                  |  14 +-
 src/mesa/swrast/s_stencil.c                       |   2 +-
 src/mesa/swrast/s_texcombine.c                    |   8 +-
 src/mesa/vbo/vbo_exec_api.c                       |  16 +-
 src/mesa/vbo/vbo_exec_array.c                     |   6 +-
 src/mesa/vbo/vbo_primitive_restart.c              |   3 +-
 src/mesa/vbo/vbo_save_api.c                       |   2 +-
 src/mesa/vbo/vbo_save_draw.c                      |   3 +-
 109 files changed, 1215 insertions(+), 1458 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 3c8ffb5..c1410c1 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -353,7 +353,7 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
       /* non-default array object */
       newObj = _mesa_lookup_vao(ctx, id);
       if (!newObj) {
-         if (genRequired) {
+         if (unlikely(genRequired)) {
             _mesa_error(ctx, GL_INVALID_OPERATION,
                         "glBindVertexArray(non-gen name)");
             return;
@@ -361,7 +361,7 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
 
          /* For APPLE version, generate a new array object now */
 	 newObj = (*ctx->Driver.NewArrayObject)(ctx, id);
-         if (!newObj) {
+         if (unlikely(!newObj)) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindVertexArrayAPPLE");
             return;
          }
@@ -447,7 +447,7 @@ _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids)
    GET_CURRENT_CONTEXT(ctx);
    GLsizei i;
 
-   if (n < 0) {
+   if (unlikely(n < 0)) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArray(n)");
       return;
    }
@@ -491,7 +491,7 @@ gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays)
    GLuint first;
    GLint i;
 
-   if (n < 0) {
+   if (unlikely(n < 0)) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGenVertexArrays");
       return;
    }
@@ -508,7 +508,7 @@ gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays)
       GLuint name = first + i;
 
       obj = (*ctx->Driver.NewArrayObject)( ctx, name );
-      if (!obj) {
+      if (unlikely(!obj)) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenVertexArrays");
          return;
       }
diff --git a/src/mesa/main/atifragshader.c b/src/mesa/main/atifragshader.c
index 9d967b9..f77fd1b 100644
--- a/src/mesa/main/atifragshader.c
+++ b/src/mesa/main/atifragshader.c
@@ -640,10 +618,7 @@ _mesa_FragmentOpXATI(GLint optype, GLuint arg_count, GLenum op, GLuint dst,
       if (!check_arith_arg(curProg, optype, arg3, arg3Rep)) {
 	 return;
       }
-      if ((arg1 >= GL_CON_0_ATI) && (arg1 <= GL_CON_7_ATI) &&
-	  (arg2 >= GL_CON_0_ATI) && (arg2 <= GL_CON_7_ATI) &&
-	  (arg3 >= GL_CON_0_ATI) && (arg3 <= GL_CON_7_ATI) &&
-	  (arg1 != arg2) && (arg1 != arg3) && (arg2 != arg3)) {
+      if (unlikely((arg1 >= GL_CON_0_ATI) && (arg1 <= GL_CON_7_ATI) && (arg2 >= GL_CON_0_ATI) && (arg2 <= GL_CON_7_ATI) && (arg3 >= GL_CON_0_ATI) && (arg3 <= GL_CON_7_ATI) && (arg1 != arg2) && (arg1 != arg3) && (arg2 != arg3))) {
 	 _mesa_error(ctx, GL_INVALID_OPERATION, "C/AFragmentOpATI(3Consts)");
 	 return;
       }


More information about the mesa-dev mailing list