Last active
August 29, 2015 14:12
-
-
Save savanovich/8d9a9af940291861dc14 to your computer and use it in GitHub Desktop.
C: likely / unlikely userspace macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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