summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhigang Gong <zhigang.gong@linux.intel.com>2012-06-26 20:00:21 +0800
committerAdam Jackson <ajax@redhat.com>2013-10-30 10:37:01 -0400
commit372a1680cedcafbe44aa06ba2f829fb375388de4 (patch)
tree2d2c857d89ad56d2428d1d70fcd78ce1db084b18
parent7c4e922534742dcf96fa2e562968b63626893fc3 (diff)
optimize: Use likely and unlikely.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r--glamor/compiler.h59
-rw-r--r--glamor/glamor_priv.h2
-rw-r--r--glamor/glamor_utils.h36
3 files changed, 78 insertions, 19 deletions
diff --git a/glamor/compiler.h b/glamor/compiler.h
new file mode 100644
index 000000000..154f92f51
--- /dev/null
+++ b/glamor/compiler.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ * Copied from sna
+ *
+ */
+
+#ifndef _GLAMOR_COMPILER_H_
+#define _GLAMOR_COMPILER_H_
+
+#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
+#define likely(expr) (__builtin_expect (!!(expr), 1))
+#define unlikely(expr) (__builtin_expect (!!(expr), 0))
+#define noinline __attribute__((noinline))
+#define fastcall __attribute__((regparm(3)))
+#define must_check __attribute__((warn_unused_result))
+#define constant __attribute__((const))
+#else
+#define likely(expr) (expr)
+#define unlikely(expr) (expr)
+#define noinline
+#define fastcall
+#define must_check
+#define constant
+#endif
+
+#ifdef HAVE_VALGRIND
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
+#define VG_CLEAR(s) VG(memset(&s, 0, sizeof(s)))
+
+#define COMPILE_TIME_ASSERT(E) ((void)sizeof(char[1 - 2*!(E)]))
+
+#endif /* _SNA_COMPILER_H_ */
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 101d0db47..bc0ca7b7a 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -31,6 +31,8 @@
#include "config.h"
#endif
+#include "compiler.h"
+
#include <xorg-server.h>
#ifndef DEBUG
#define NDEBUG
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index ab91f313d..88c66168a 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -59,7 +59,7 @@
#define PIXMAP_PRIV_GET_ACTUAL_SIZE(priv, w, h) \
do { \
- if (priv->type == GLAMOR_TEXTURE_LARGE) { \
+ if (unlikely(priv->type == GLAMOR_TEXTURE_LARGE)) { \
w = priv->large.box.x2 - priv->large.box.x1; \
h = priv->large.box.y2 - priv->large.box.y1; \
} else { \
@@ -80,8 +80,8 @@
#define pixmap_priv_get_fbo_off(_priv_, _xoff_, _yoff_) \
do { \
- if (_priv_ && (_priv_)->type \
- == GLAMOR_TEXTURE_LARGE) { \
+ if (unlikely(_priv_ && (_priv_)->type \
+ == GLAMOR_TEXTURE_LARGE)) { \
*(_xoff_) = - (_priv_)->large.box.x1; \
*(_yoff_) = - (_priv_)->large.box.y1; \
} else { \
@@ -316,7 +316,7 @@
texcoord, yInverted) \
do { \
(texcoord)[0] = t_from_x_coord_x(xscale, _tx_); \
- if (yInverted) \
+ if (likely(yInverted)) \
(texcoord)[1] = t_from_x_coord_y_inverted(yscale, _ty_);\
else \
(texcoord)[1] = t_from_x_coord_y(yscale, _ty_); \
@@ -339,7 +339,7 @@
tx += fbo_x_off; \
ty += fbo_y_off; \
(texcoord)[0] = t_from_x_coord_x(xscale, tx); \
- if (yInverted) \
+ if (likely(yInverted)) \
(texcoord)[1] = t_from_x_coord_y_inverted(yscale, ty); \
else \
(texcoord)[1] = t_from_x_coord_y(yscale, ty); \
@@ -436,14 +436,12 @@
texcoords, \
stride) \
do { \
- if (priv->type != GLAMOR_TEXTURE_LARGE) { \
+ if (likely(priv->type != GLAMOR_TEXTURE_LARGE)) { \
glamor_set_transformed_normalize_tcoords_ext(priv, matrix, xscale, \
yscale, _x1_, _y1_, \
_x2_, _y2_, yInverted, \
texcoords, stride); \
} else { \
- /* For a large pixmap, if both transform and repeat are set,
- * the transform must only has x and y scale factor.*/ \
float tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4; \
float ttx1, tty1, ttx2, tty2, ttx3, tty3, ttx4, tty4; \
DEBUGF("original coords %d %d %d %d\n", _x1_, _y1_, _x2_, _y2_); \
@@ -512,7 +510,7 @@
(vertices)[1 * stride] = _t2_ = t_from_x_coord_x(xscale, tx2); \
(vertices)[2 * stride] = _t2_; \
(vertices)[3 * stride] = _t0_; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = _t1_ = t_from_x_coord_y_inverted(yscale, ty1); \
(vertices)[2 * stride + 1] = _t5_ = t_from_x_coord_y_inverted(yscale, ty2);\
} \
@@ -528,7 +526,7 @@
x1, y1, x2, y2, \
yInverted, vertices, stride) \
do { \
- if (priv->type == GLAMOR_TEXTURE_LARGE) { \
+ if (unlikely(priv->type == GLAMOR_TEXTURE_LARGE)) { \
float tx1, tx2, ty1, ty2; \
int fbo_x_off, fbo_y_off; \
pixmap_priv_get_fbo_off(priv, &fbo_x_off, &fbo_y_off); \
@@ -559,7 +557,7 @@
_x1_, _y1_, _x2_, _y2_, \
yInverted, vertices, stride)\
do { \
- if (priv->type == GLAMOR_TEXTURE_LARGE) { \
+ if (unlikely(priv->type == GLAMOR_TEXTURE_LARGE)) { \
float tx1, tx2, ty1, ty2; \
if (repeat_type == RepeatPad) { \
tx1 = _x1_ - priv->large.box.x1; \
@@ -600,7 +598,7 @@
(vertices)[2] = t_from_x_coord_x(xscale, x2); \
(vertices)[6] = (vertices)[2]; \
(vertices)[4] = (vertices)[0]; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = t_from_x_coord_y_inverted(yscale, y1); \
(vertices)[7] = t_from_x_coord_y_inverted(yscale, y2); \
} \
@@ -619,7 +617,7 @@
(vertices)[2] = (x2); \
(vertices)[4] = (vertices)[2]; \
(vertices)[6] = (vertices)[0]; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = (y1); \
(vertices)[5] = (y2); \
} \
@@ -635,7 +633,7 @@
yInverted, vertices) \
do { \
(vertices)[0] = v_from_x_coord_x(xscale, x); \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = v_from_x_coord_y_inverted(yscale, y); \
} else { \
(vertices)[1] = v_from_x_coord_y(yscale, y); \
@@ -663,7 +661,7 @@
(vertices)[2] = (x2); \
(vertices)[6] = (vertices)[2]; \
(vertices)[4] = (vertices)[0]; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = (y1); \
(vertices)[7] = (y2); \
} \
@@ -689,7 +687,7 @@
x2 + fbo_x_off); \
(vertices)[2 * stride] = _t2_; \
(vertices)[3 * stride] = _t0_; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = _t1_ = v_from_x_coord_y_inverted(yscale, \
y1 + fbo_y_off); \
(vertices)[2 * stride + 1] = _t5_ = \
@@ -723,7 +721,7 @@
(vertices)[2] = v_from_x_coord_x(xscale, x2); \
(vertices)[6] = (vertices)[2]; \
(vertices)[4] = (vertices)[0]; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(vertices)[1] = v_from_x_coord_y_inverted(yscale, y1); \
(vertices)[7] = v_from_x_coord_y_inverted(yscale, y2); \
} \
@@ -739,7 +737,7 @@
yInverted, pt) \
do { \
(pt)[0] = t_from_x_coord_x(xscale, x); \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(pt)[1] = t_from_x_coord_y_inverted(yscale, y); \
} else { \
(pt)[1] = t_from_x_coord_y(yscale, y); \
@@ -750,7 +748,7 @@
yInverted, c) \
do { \
(c)[0] = (float)x; \
- if (yInverted) { \
+ if (likely(yInverted)) { \
(c)[1] = (float)y; \
} else { \
(c)[1] = (float)height - (float)y; \