summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/basedefs.h
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-07-24 09:00:18 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-07-25 10:07:42 +0200
commita1f7d7d430466fe66ead3155a9015ddde237fd44 (patch)
tree345c928410b1a7216b48473f4792742389b540e1 /cpukit/include/rtems/score/basedefs.h
parent_SMP_Start_multitasking_on_secondary_processor() (diff)
downloadrtems-a1f7d7d430466fe66ead3155a9015ddde237fd44.tar.bz2
score: RTEMS_PREDICT_TRUE(), RTEMS_PREDICT_FALSE()
Add RTEMS_PREDICT_TRUE() and RTEMS_PREDICT_FALSE() for static branch prediction hints. Close #3475.
Diffstat (limited to 'cpukit/include/rtems/score/basedefs.h')
-rw-r--r--cpukit/include/rtems/score/basedefs.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/cpukit/include/rtems/score/basedefs.h b/cpukit/include/rtems/score/basedefs.h
index 8169f6db8c..679f4bd1b4 100644
--- a/cpukit/include/rtems/score/basedefs.h
+++ b/cpukit/include/rtems/score/basedefs.h
@@ -281,6 +281,34 @@
#define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value )
#endif
+/**
+ * @brief Returns the value of the specified integral expression and tells the
+ * compiler that the predicted value is true (1).
+ *
+ * @param[in] _exp The expression.
+ *
+ * @return The value of the expression.
+ */
+#if defined(__GNUC__)
+ #define RTEMS_PREDICT_TRUE( _exp ) __builtin_expect( ( _exp ), 1 )
+#else
+ #define RTEMS_PREDICT_TRUE( _exp ) ( _exp )
+#endif
+
+/**
+ * @brief Returns the value of the specified integral expression and tells the
+ * compiler that the predicted value is false (0).
+ *
+ * @param[in] _exp The expression.
+ *
+ * @return The value of the expression.
+ */
+#if defined(__GNUC__)
+ #define RTEMS_PREDICT_FALSE( _exp ) __builtin_expect( ( _exp ), 0 )
+#else
+ #define RTEMS_PREDICT_FALSE( _exp ) ( _exp )
+#endif
+
#if __cplusplus >= 201103L
#define RTEMS_STATIC_ASSERT(cond, msg) \
static_assert(cond, # msg)