Skip to content

Instantly share code, notes, and snippets.

@fritzo
Last active October 7, 2015 08:58
Show Gist options
  • Save fritzo/3138949 to your computer and use it in GitHub Desktop.
Save fritzo/3138949 to your computer and use it in GitHub Desktop.
Add unlikely() and likely() wrappers in gnu C++
/* from the cython compiler */
#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x) (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x) (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment