From: Aina Niemetz Date: Tue, 6 Aug 2019 23:25:07 +0000 (-0700) Subject: New C++ API: Fix branch prediction in CHECK macros. (#3161) X-Git-Tag: cvc5-1.0.0~4039 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6b5b18c6bfd924f0e20b0c9439da3113acb76a27;p=cvc5.git New C++ API: Fix branch prediction in CHECK macros. (#3161) --- 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 {