fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/27046 )
Change subject: core/utils.h: add OSMO_LIKELY / OSMO_UNLIKELY macros
......................................................................
core/utils.h: add OSMO_LIKELY / OSMO_UNLIKELY macros
Change-Id: I0b029654ba050f079eed4a0574a3fa8019677067
---
M include/osmocom/core/utils.h
1 file changed, 9 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/46/27046/1
diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h
index 327aa3d..30d8be6 100644
--- a/include/osmocom/core/utils.h
+++ b/include/osmocom/core/utils.h
@@ -38,6 +38,15 @@
/*! Copy a C-string into a sized buffer using sizeof to detect buffer's size */
#define OSMO_STRLCPY_ARRAY(array, src) osmo_strlcpy(array, src, sizeof(array))
+/*! Branch prediction optimizations */
+#if defined(__GNUC__)
+#define OSMO_LIKELY(exp) __builtin_expect (!!(exp), 1)
+#define OSMO_UNLIKELY(exp) __builtin_expect (!!(exp), 0)
+#else
+#define OSMO_LIKELY(exp) exp
+#define OSMO_UNLIKELY(exp) exp
+#endif
+
/*! A mapping between human-readable string and numeric value */
struct value_string {
uint32_t value; /*!< numeric value */
--
To view, visit
https://gerrit.osmocom.org/c/libosmocore/+/27046
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0b029654ba050f079eed4a0574a3fa8019677067
Gerrit-Change-Number: 27046
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newchange