Skip to content

Commit

Permalink
Add predicate likelihood macros.
Browse files Browse the repository at this point in the history
Define the couple of standard macros that we can use to guide gcc
optimisations of which code path will be most likely taken.
  • Loading branch information
Chris Wilson committed Nov 13, 2008
1 parent b06c50c commit 0769d39
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/cairo-compiler-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0769d39

Please sign in to comment.