Add predicate likelihood macros.

Define the couple of standard macros that we can use to guide gcc
optimisations of which code path will be most likely taken.
This commit is contained in:
Chris Wilson 2008-11-13 11:13:22 +00:00
parent b06c50cc54
commit 0769d39d00

View file

@ -139,6 +139,23 @@
#define cairo_const
#endif
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _CAIRO_BOOLEAN_EXPR(expr) \
__extension__ ({ \
int _cairo_boolean_var_; \
if (expr) \
_cairo_boolean_var_ = 1; \
else \
_cairo_boolean_var_ = 0; \
_cairo_boolean_var_; \
})
#define _cairo_likely(expr) (__builtin_expect (_CAIRO_BOOLEAN_EXPR(expr), 1))
#define _cairo_unlikely(expr) (__builtin_expect (_CAIRO_BOOLEAN_EXPR(expr), 0))
#else
#define _cairo_likely(expr) (expr)
#define _cairo_unlikely(expr) (expr)
#endif
#ifndef __GNUC__
#undef __attribute__
#define __attribute__(x)