From 6b5b18c6bfd924f0e20b0c9439da3113acb76a27 Mon Sep 17 00:00:00 2001 From: Aina Niemetz Date: Tue, 6 Aug 2019 16:25:07 -0700 Subject: [PATCH] New C++ API: Fix branch prediction in CHECK macros. (#3161) --- src/api/cvc4cpp.cpp | 10 +++++----- src/base/cvc4_check.h | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp index 32484a49e..6374dad14 100644 --- a/src/api/cvc4cpp.cpp +++ b/src/api/cvc4cpp.cpp @@ -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() \ diff --git a/src/base/cvc4_check.h b/src/base/cvc4_check.h index 703931108..b18e62303 100644 --- a/src/base/cvc4_check.h +++ b/src/base/cvc4_check.h @@ -55,11 +55,14 @@ #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 { -- 2.30.2