diff options
author | 2019-06-21 13:00:38 +0300 | |
---|---|---|
committer | 2019-06-21 13:00:38 +0300 | |
commit | 7c4f627ebb0e2d2f1922c4ec18032a3619ea5f1d (patch) | |
tree | 33d82c0a7bbd09f235653b65f9b933167b28a07a /include/rin | |
parent | c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc (diff) | |
download | librin-7c4f627ebb0e2d2f1922c4ec18032a3619ea5f1d.tar.gz librin-7c4f627ebb0e2d2f1922c4ec18032a3619ea5f1d.tar.bz2 librin-7c4f627ebb0e2d2f1922c4ec18032a3619ea5f1d.zip |
definitions: add likely/unlikely branch macros.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'include/rin')
-rw-r--r-- | include/rin/definitions.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/rin/definitions.h b/include/rin/definitions.h index 8364f42..b5f5667 100644 --- a/include/rin/definitions.h +++ b/include/rin/definitions.h @@ -21,12 +21,29 @@ #ifndef LIBRIN_DEFINITIONS_INCLUDED #define LIBRIN_DEFINITIONS_INCLUDED +/* gcc */ #ifdef __GNUC__ + +/* weak symbols */ # define WEAK_SYM __attribute__((weak)) +/* optimizing likely / unlikely branches */ +# define likely(a) (__builtin_expect(!!(a), 1)) +# define unlikely(a) (__builtin_expect((a), 0)) + +/* MSVC */ #elif defined(_MSC_VER) + +/* weak symbols */ # define WEAK_SYM __declspec(selectany) +/* optimizing likely / unlikely branches */ +# define likely(a) (a) +# define unlikely(a) (a) + +/* the rest – NOOP */ #else # define WEAK_SYM +# define likely(a) (a) +# define unlikely(a) (a) #endif #define rin_once(func) \ |