From 7c4f627ebb0e2d2f1922c4ec18032a3619ea5f1d Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Fri, 21 Jun 2019 13:00:38 +0300 Subject: definitions: add likely/unlikely branch macros. Signed-off-by: Gediminas Jakutis --- include/rin/definitions.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) \ -- cgit v1.2.3