Skip to content

Instantly share code, notes, and snippets.

@savanovich
Last active August 29, 2015 14:12
Show Gist options
  • Save savanovich/8d9a9af940291861dc14 to your computer and use it in GitHub Desktop.
Save savanovich/8d9a9af940291861dc14 to your computer and use it in GitHub Desktop.
C: likely / unlikely userspace macros
#if __GNUC__ >= 3
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
#else
# define likely(x) (x)
# define unlikely(x) (x)
#endif
#ifndef UNLIKELY_H
#define UNLIKELY_H
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define likely(expr) __builtin_expect((expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
#else
#define likely(expr) (expr)
#define unlikely(expr) (expr)
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment