[or-cvs] r9781: Excise PREDICT and PREDICT_FALSE in favor of PREDICT_LIKELY (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Fri Mar 9 21:39:22 UTC 2007


Author: nickm
Date: 2007-03-09 16:39:19 -0500 (Fri, 09 Mar 2007)
New Revision: 9781

Modified:
   tor/trunk/
   tor/trunk/src/common/compat.h
   tor/trunk/src/common/util.h
Log:
 r12473 at Kushana:  nickm | 2007-03-06 15:49:45 -0500
 Excise PREDICT and PREDICT_FALSE in favor of PREDICT_LIKELY and PREDICT_UNLIKELY.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12473] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/src/common/compat.h
===================================================================
--- tor/trunk/src/common/compat.h	2007-03-09 13:12:52 UTC (rev 9780)
+++ tor/trunk/src/common/compat.h	2007-03-09 21:39:19 UTC (rev 9781)
@@ -98,15 +98,17 @@
 #define ATTR_PURE __attribute__((pure))
 #define ATTR_MALLOC __attribute__((malloc))
 #define ATTR_NONNULL(x) __attribute__((nonnull x))
-#define PREDICT(exp, val) __builtin_expect((exp), (val))
-#define PREDICT_LIKELY(exp) PREDICT((exp), 1)
-#define PREDICT_UNLIKELY(exp) PREDICT((exp), 0)
+/** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
+ * of <b>exp</b> will probably be true. */
+#define PREDICT_LIKELY(exp) __builtin_expect((exp), 1)
+/** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
+ * of <b>exp</b> will probably be false. */
+#define PREDICT_UNLIKELY(exp) __builtin_expect((exp), 0)
 #else
 #define ATTR_NORETURN
 #define ATTR_PURE
 #define ATTR_MALLOC
 #define ATTR_NONNULL(x)
-#define PREDICT(exp, val) (exp)
 #define PREDICT_LIKELY(exp) (exp)
 #define PREDICT_UNLIKELY(exp) (exp)
 #endif

Modified: tor/trunk/src/common/util.h
===================================================================
--- tor/trunk/src/common/util.h	2007-03-09 13:12:52 UTC (rev 9780)
+++ tor/trunk/src/common/util.h	2007-03-09 21:39:19 UTC (rev 9781)
@@ -39,17 +39,16 @@
 #error "Sorry; we don't support building with NDEBUG."
 #else
 #ifdef __GNUC__
-/** Macro: evaluate the expression x, which we expect to be false.
- * Used to hint the compiler that a branch won't be taken. */
-#define PREDICT_FALSE(x) PREDICT_UNLIKELY((x) == ((typeof(x)) 0))
+/* Give an int-valued version of !x that won't confuse PREDICT_UNLIKELY. */
+#define IS_FALSE_AS_INT(x) ((x) == ((typeof(x)) 0))
 #else
-#define PREDICT_FALSE(x) !(x)
+#define IS_FALSE_AS_INT(x) !(x)
 #endif
 
 /** Like assert(3), but send assertion failures to the log as well as to
  * stderr. */
 #define tor_assert(expr) do {                                           \
-    if (PREDICT_FALSE(expr)) {                                          \
+    if (PREDICT_UNLIKELY(IS_FALSE_AS_INT(expr))) {                      \
       log(LOG_ERR, LD_BUG, "%s:%d: %s: Assertion %s failed; aborting.", \
           _SHORT_FILE_, __LINE__, __func__, #expr);                     \
       fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n",      \



More information about the tor-commits mailing list