New C++ API: Fix branch prediction in CHECK macros. (#3161)
authorAina Niemetz <aina.niemetz@gmail.com>
Tue, 6 Aug 2019 23:25:07 +0000 (16:25 -0700)
committerGitHub <noreply@github.com>
Tue, 6 Aug 2019 23:25:07 +0000 (16:25 -0700)
src/api/cvc4cpp.cpp
src/base/cvc4_check.h

index 32484a49e26a7050d91ed5ed8ee1257ed88ca6f4..6374dad1483ff69af8e3f6e98a7c100958502e3a 100644 (file)
@@ -631,7 +631,7 @@ class CVC4ApiExceptionStream
 };
 
 #define CVC4_API_CHECK(cond) \
-  CVC4_PREDICT_FALSE(cond)   \
+  CVC4_PREDICT_TRUE(cond)    \
   ? (void)0 : OstreamVoider() & CVC4ApiExceptionStream().ostream()
 
 #define CVC4_API_CHECK_NOT_NULL                                           \
@@ -647,14 +647,14 @@ class CVC4ApiExceptionStream
       << "Invalid kind '" << kindToString(kind) << "'";
 
 #define CVC4_API_KIND_CHECK_EXPECTED(cond, kind) \
-  CVC4_PREDICT_FALSE(cond)                       \
+  CVC4_PREDICT_TRUE(cond)                        \
   ? (void)0                                      \
   : OstreamVoider()                              \
           & CVC4ApiExceptionStream().ostream()   \
                 << "Invalid kind '" << kindToString(kind) << "', expected "
 
 #define CVC4_API_ARG_CHECK_EXPECTED(cond, arg)                      \
-  CVC4_PREDICT_FALSE(cond)                                          \
+  CVC4_PREDICT_TRUE(cond)                                           \
   ? (void)0                                                         \
   : OstreamVoider()                                                 \
           & CVC4ApiExceptionStream().ostream()                      \
@@ -662,14 +662,14 @@ class CVC4ApiExceptionStream
                 << "', expected "
 
 #define CVC4_API_ARG_SIZE_CHECK_EXPECTED(cond, arg) \
-  CVC4_PREDICT_FALSE(cond)                          \
+  CVC4_PREDICT_TRUE(cond)                           \
   ? (void)0                                         \
   : OstreamVoider()                                 \
           & CVC4ApiExceptionStream().ostream()      \
                 << "Invalid size of argument '" << #arg << "', expected "
 
 #define CVC4_API_ARG_AT_INDEX_CHECK_EXPECTED(cond, what, arg, idx)          \
-  CVC4_PREDICT_FALSE(cond)                                                  \
+  CVC4_PREDICT_TRUE(cond)                                                   \
   ? (void)0                                                                 \
   : OstreamVoider()                                                         \
           & CVC4ApiExceptionStream().ostream()                              \
index 7039311081589b9a64cff40309aeb6c4599e833a..b18e62303578a51c3ac4a251e2d77532b781905d 100644 (file)
 #ifdef __has_builtin
 #if __has_builtin(__builtin_expect)
 #define CVC4_PREDICT_FALSE(x) (__builtin_expect(x, false))
+#define CVC4_PREDICT_TRUE(x) (__builtin_expect(x, true))
 #else
 #define CVC4_PREDICT_FALSE(x) x
+#define CVC4_PREDICT_TRUE(x) x
 #endif
 #else
 #define CVC4_PREDICT_FALSE(x) x
+#define CVC4_PREDICT_TRUE(x) x
 #endif
 
 namespace CVC4 {