• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Révision14527 (tree)
l'heure2021-06-11 15:49:23
Auteurgdisirio

Message de Log

Added likely/unlikely infrastructure in RT, implementation details in the port layer. Added an CH_USED() macro for voiding expression results.

Change Summary

Modification

--- trunk/os/common/portability/CW/ccportab.h (revision 14526)
+++ trunk/os/common/portability/CW/ccportab.h (revision 14527)
@@ -120,6 +120,20 @@
120120 * compiler.
121121 */
122122 #define CC_ROMCONST const
123+
124+/**
125+ * @brief Marks a boolean expression as likely true.
126+ *
127+ * @param[in] x a valid expression
128+ */
129+#define CC_LIKELY(x) x
130+
131+/**
132+ * @brief Marks a boolean expression as likely false.
133+ *
134+ * @param[in] x a valid expression
135+ */
136+#define CC_UNLIKELY(x) x
123137 /** @} */
124138
125139 /*===========================================================================*/
--- trunk/os/common/portability/GCC/ccportab.h (revision 14526)
+++ trunk/os/common/portability/GCC/ccportab.h (revision 14527)
@@ -120,6 +120,20 @@
120120 * compiler.
121121 */
122122 #define CC_ROMCONST const
123+
124+/**
125+ * @brief Marks a boolean expression as likely true.
126+ *
127+ * @param[in] x a valid expression
128+ */
129+#define CC_LIKELY(x) __builtin_expect(!!(x), 1)
130+
131+/**
132+ * @brief Marks a boolean expression as likely false.
133+ *
134+ * @param[in] x a valid expression
135+ */
136+#define CC_UNLIKELY(x) __builtin_expect(!!(x), 0)
123137 /** @} */
124138
125139 /*===========================================================================*/
--- trunk/os/common/portability/GHS/ccportab.h (revision 14526)
+++ trunk/os/common/portability/GHS/ccportab.h (revision 14527)
@@ -120,6 +120,20 @@
120120 * compiler.
121121 */
122122 #define CC_ROMCONST const
123+
124+/**
125+ * @brief Marks a boolean expression as likely true.
126+ *
127+ * @param[in] x a valid expression
128+ */
129+#define CC_LIKELY(x) x
130+
131+/**
132+ * @brief Marks a boolean expression as likely false.
133+ *
134+ * @param[in] x a valid expression
135+ */
136+#define CC_UNLIKELY(x) x
123137 /** @} */
124138
125139 /*===========================================================================*/
--- trunk/os/common/portability/IAR/ccportab.h (revision 14526)
+++ trunk/os/common/portability/IAR/ccportab.h (revision 14527)
@@ -120,6 +120,20 @@
120120 * compiler.
121121 */
122122 #define CC_ROMCONST const
123+
124+/**
125+ * @brief Marks a boolean expression as likely true.
126+ *
127+ * @param[in] x a valid expression
128+ */
129+#define CC_LIKELY(x) x
130+
131+/**
132+ * @brief Marks a boolean expression as likely false.
133+ *
134+ * @param[in] x a valid expression
135+ */
136+#define CC_UNLIKELY(x) x
123137 /** @} */
124138
125139 /*===========================================================================*/
--- trunk/os/common/portability/Keil/ccportab.h (revision 14526)
+++ trunk/os/common/portability/Keil/ccportab.h (revision 14527)
@@ -120,6 +120,20 @@
120120 * compiler.
121121 */
122122 #define CC_ROMCONST const
123+
124+/**
125+ * @brief Marks a boolean expression as likely true.
126+ *
127+ * @param[in] x a valid expression
128+ */
129+#define CC_LIKELY(x) x
130+
131+/**
132+ * @brief Marks a boolean expression as likely false.
133+ *
134+ * @param[in] x a valid expression
135+ */
136+#define CC_UNLIKELY(x) x
123137 /** @} */
124138
125139 /*===========================================================================*/
--- trunk/os/common/ports/ARM-common/chtypes.h (revision 14526)
+++ trunk/os/common/ports/ARM-common/chtypes.h (revision 14527)
@@ -101,6 +101,28 @@
101101 */
102102 #define SIZEOF_PTR PORT_ARCH_SIZEOF_DATA_PTR
103103
104+/**
105+ * @brief Marks a boolean expression as likely true.
106+ *
107+ * @param[in] x a valid expression
108+ */
109+#if defined(CC_LIKELY) || defined(__DOXYGEN__)
110+#define PORT_LIKELY(x) CC_LIKELY(x)
111+#else
112+#define PORT_LIKELY(x) x
113+#endif
114+
115+/**
116+ * @brief Marks a boolean expression as likely false.
117+ *
118+ * @param[in] x a valid expression
119+ */
120+#if defined(CC_UNLIKELY) || defined(__DOXYGEN__)
121+#define PORT_UNLIKELY(x) CC_UNLIKELY(x)
122+#else
123+#define PORT_UNLIKELY(x) x
124+#endif
125+
104126 #endif /* CHTYPES_H */
105127
106128 /** @} */
--- trunk/os/rt/include/chearly.h (revision 14526)
+++ trunk/os/rt/include/chearly.h (revision 14527)
@@ -146,7 +146,7 @@
146146 *
147147 * @param[in] a literal to be string-ified
148148 */
149-#define __CH_STRINGIFY(a) #a
149+#define __CH_STRINGIFY(a) #a
150150
151151 /**
152152 * @brief Structure field offset utility.
@@ -161,6 +161,39 @@
161161 ((size_t)((char *)&((st *)0)->m - (char *)0)) \
162162 /*lint -restore*/
163163
164+/**
165+ * @brief Marks an expression result as used.
166+ *
167+ * @param[in] x a valid expression
168+ */
169+#define __CH_USED(x) (void)(x)
170+
171+/**
172+ * @brief Marks a boolean expression as likely true.
173+ * @note No namespace prefix for this macro because it is commonly defined
174+ * by operating systems.
175+ *
176+ * @param[in] x a valid expression
177+ */
178+#if defined(PORT_LIKELY) || defined(__DOXYGEN__)
179+#define likely(x) PORT_LIKELY(x)
180+#else
181+#define likely(x) x
182+#endif
183+
184+/**
185+ * @brief Marks a boolean expression as likely false.
186+ * @note No namespace prefix for this macro because it is commonly defined
187+ * by operating systems.
188+ *
189+ * @param[in] x a valid expression
190+ */
191+#if defined(PORT_UNLIKELY) || defined(__DOXYGEN__)
192+#define unlikely(x) PORT_UNLIKELY(x)
193+#else
194+#define unlikely(x) x
195+#endif
196+
164197 /*===========================================================================*/
165198 /* External declarations. */
166199 /*===========================================================================*/
Afficher sur ancien navigateur de dépôt.