aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-06-21 13:00:38 +0300
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-06-21 13:00:38 +0300
commit7c4f627ebb0e2d2f1922c4ec18032a3619ea5f1d (patch)
tree33d82c0a7bbd09f235653b65f9b933167b28a07a /include
parentc499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc (diff)
downloadlibrin-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')
-rw-r--r--include/rin/definitions.h17
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) \