Thanks to Alex Horn for raising the issue on the CVC-BUGS mailing list.
operator=(const NodeTemplate& e) {
Assert(d_nv != NULL, "Expecting a non-NULL expression value!");
Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!");
- if(EXPECT_TRUE( d_nv != e.d_nv )) {
+ if(__builtin_expect( ( d_nv != e.d_nv ), true )) {
if(ref_count) {
// shouldn't ever fail
Assert(d_nv->d_rc > 0,
operator=(const NodeTemplate<!ref_count>& e) {
Assert(d_nv != NULL, "Expecting a non-NULL expression value!");
Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!");
- if(EXPECT_TRUE( d_nv != e.d_nv )) {
+ if(__builtin_expect( ( d_nv != e.d_nv ), true )) {
if(ref_count) {
// shouldn't ever fail
Assert(d_nv->d_rc > 0, "Node reference count would be negative");
* Internally, this state is represented by d_nv pointing to NULL.
*/
inline bool isUsed() const {
- return EXPECT_FALSE( d_nv == NULL );
+ return __builtin_expect( ( d_nv == NULL ), false );
}
/**
* heap-allocated by this class).
*/
inline bool nvIsAllocated() const {
- return EXPECT_FALSE( d_nv != &d_inlineNv ) && EXPECT_TRUE( d_nv != NULL );
+ return __builtin_expect( ( d_nv != &d_inlineNv ), false ) && __builtin_expect(( d_nv != NULL ), true );
}
/**
* first.
*/
inline bool nvNeedsToBeAllocated() const {
- return EXPECT_FALSE( d_nv->d_nchildren == d_nvMaxChildren );
+ return __builtin_expect( ( d_nv->d_nchildren == d_nvMaxChildren ), false );
}
/**
inline void realloc() {
size_t newSize = 2 * size_t(d_nvMaxChildren);
size_t hardLimit = (1lu << __CVC4__EXPR__NODE_VALUE__NBITS__NCHILDREN) - 1;
- realloc(EXPECT_FALSE( newSize > hardLimit ) ? hardLimit : newSize);
+ realloc(__builtin_expect( ( newSize > hardLimit ), false ) ? hardLimit : newSize);
}
/**
* double-decremented on destruction/clear. Otherwise, do nothing.
*/
inline void allocateNvIfNecessaryForAppend() {
- if(EXPECT_FALSE( nvNeedsToBeAllocated() )) {
+ if(__builtin_expect( ( nvNeedsToBeAllocated() ), false )) {
realloc();
}
}
* @throws bad_alloc if the reallocation fails
*/
void crop() {
- if(EXPECT_FALSE( nvIsAllocated() ) &&
- EXPECT_TRUE( d_nvMaxChildren > d_nv->d_nchildren )) {
+ if(__builtin_expect( ( nvIsAllocated() ), false ) &&
+ __builtin_expect( ( d_nvMaxChildren > d_nv->d_nchildren ), true )) {
// Ensure d_nv is not modified on allocation failure
expr::NodeValue* newBlock = (expr::NodeValue*)
std::realloc(d_nv,
}
inline ~NodeBuilder() {
- if(EXPECT_FALSE( nvIsAllocated() )) {
+ if(__builtin_expect( ( nvIsAllocated() ), false )) {
dealloc();
- } else if(EXPECT_FALSE( !isUsed() )) {
+ } else if(__builtin_expect( ( !isUsed() ), false )) {
decrRefCounts();
}
}
// NodeBuilder construction or at the last clear()), but we do
// now. That means we appended a Kind with operator<<(Kind),
// which now (lazily) we'll collapse.
- if(EXPECT_FALSE( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND )) {
+ if(__builtin_expect( ( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND ), false )) {
Node n2 = operator Node();
clear();
append(n2);
// NodeBuilder construction or at the last clear()), but we do
// now. That means we appended a Kind with operator<<(Kind),
// which now (lazily) we'll collapse.
- if(EXPECT_FALSE( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND )) {
+ if(__builtin_expect( ( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND ), false )) {
Node n2 = operator Node();
clear();
append(n2);
// NodeBuilder construction or at the last clear()), but we do
// now. That means we appended a Kind with operator<<(Kind),
// which now (lazily) we'll collapse.
- if(EXPECT_FALSE( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND )) {
+ if(__builtin_expect( ( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND ), false )) {
Node n2 = operator Node();
clear();
append(n2);
void NodeBuilder<nchild_thresh>::clear(Kind k) {
Assert(k != kind::NULL_EXPR, "illegal Node-building clear kind");
- if(EXPECT_FALSE( nvIsAllocated() )) {
+ if(__builtin_expect( ( nvIsAllocated() ), false )) {
dealloc();
- } else if(EXPECT_FALSE( !isUsed() )) {
+ } else if(__builtin_expect( ( !isUsed() ), false )) {
decrRefCounts();
} else {
setUnused();
"attempt to realloc() a NodeBuilder to size %u (beyond hard limit of %u)",
toSize, (1lu << __CVC4__EXPR__NODE_VALUE__NBITS__NCHILDREN) - 1 );
- if(EXPECT_FALSE( nvIsAllocated() )) {
+ if(__builtin_expect( ( nvIsAllocated() ), false )) {
// Ensure d_nv is not modified on allocation failure
expr::NodeValue* newBlock = (expr::NodeValue*)
std::realloc(d_nv, sizeof(expr::NodeValue) +
// NodeManager pool of Nodes. See implementation notes at the top
// of this file.
- if(EXPECT_TRUE( ! nvIsAllocated() )) {
+ if(__builtin_expect( ( ! nvIsAllocated() ), true )) {
/** Case 1. d_nv points to d_inlineNv: it is the backing store
** allocated "inline" in this NodeBuilder. **/
// NodeManager pool of Nodes. See implementation notes at the top
// of this file.
- if(EXPECT_TRUE( ! nvIsAllocated() )) {
+ if(__builtin_expect( ( ! nvIsAllocated() ), true )) {
/** Case 1. d_nv points to d_inlineNv: it is the backing store
** allocated "inline" in this NodeBuilder. **/
RefCountGuard(const NodeValue* nv) :
d_nv(const_cast<NodeValue*>(nv)) {
// inc()
- if(EXPECT_TRUE( d_nv->d_rc < MAX_RC )) {
+ if(__builtin_expect( ( d_nv->d_rc < MAX_RC ), true )) {
++d_nv->d_rc;
}
}
// E.g., this can happen when debugging code calls the print
// routines below. As RefCountGuards are scoped on the stack,
// this should be fine---but not in multithreaded contexts!
- if(EXPECT_TRUE( d_nv->d_rc < MAX_RC )) {
+ if(__builtin_expect( ( d_nv->d_rc < MAX_RC ), true )) {
--d_nv->d_rc;
}
}
"NodeValue is currently being deleted "
"and increment is being called on it. Don't Do That!");
// FIXME multithreading
- if(EXPECT_TRUE( d_rc < MAX_RC )) {
+ if(__builtin_expect( ( d_rc < MAX_RC ), true )) {
++d_rc;
}
}
inline void NodeValue::dec() {
// FIXME multithreading
- if(EXPECT_TRUE( d_rc < MAX_RC )) {
+ if(__builtin_expect( ( d_rc < MAX_RC ), true )) {
--d_rc;
- if(EXPECT_FALSE( d_rc == 0 )) {
+ if(__builtin_expect( ( d_rc == 0 ), false )) {
Assert(NodeManager::currentNM() != NULL,
"No current NodeManager on destruction of NodeValue: "
"maybe a public CVC4 interface function is missing a NodeManagerScope ?");
Assert(!t0.isNull());
Assert(!t1.isNull());
- if(EXPECT_TRUE(t0 == t1)) {
+ if(__builtin_expect( (t0 == t1), true )) {
return t0;
} else { // t0 != t1
if(t0.getKind()== kind::TYPE_CONSTANT) {
Assert(d_nv != NULL, "Expecting a non-NULL expression value!");
Assert(typeNode.d_nv != NULL,
"Expecting a non-NULL expression value on RHS!");
- if(EXPECT_TRUE( d_nv != typeNode.d_nv )) {
+ if(__builtin_expect( ( d_nv != typeNode.d_nv ), true )) {
d_nv->dec();
d_nv = typeNode.d_nv;
d_nv->inc();
# define CVC4_WARN_UNUSED_RESULT
#endif /* __GNUC__ */
-#define EXPECT_TRUE(x) __builtin_expect( (x), true )
-#define EXPECT_FALSE(x) __builtin_expect( (x), false )
-
#endif /* __CVC4_PUBLIC_H */
}
/* Initialize the buffer on our first call. */
- if( EXPECT_FALSE(buffer->empty == ANTLR3_TRUE) ) {
+ if( __builtin_expect( (buffer->empty == ANTLR3_TRUE), false ) ) {
assert( buffer->tokenBuffer != NULL );
buffer->tokenBuffer[ 0 ] = nextToken(buffer);
buffer->maxIndex = 0;
const char* propagatingException) {
static CVC4_THREADLOCAL(bool) alreadyFired = false;
- if(EXPECT_TRUE( !std::uncaught_exception() ) || alreadyFired) {
+ if(__builtin_expect( ( !std::uncaught_exception() ), true ) || alreadyFired) {
throw thisException;
}
// details of the exception
# define AlwaysAssert(cond, msg...) \
do { \
- if(EXPECT_FALSE( ! (cond) )) { \
+ if(__builtin_expect( ( ! (cond) ), false )) { \
/* save the last assertion failure */ \
const char* lastException = ::CVC4::s_debugLastException; \
::CVC4::AssertionException exception(#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \
// will terminate() if thrown during stack unwinding.
# define AlwaysAssert(cond, msg...) \
do { \
- if(EXPECT_FALSE( ! (cond) )) { \
+ if(__builtin_expect( ( ! (cond) ), false )) { \
throw ::CVC4::AssertionException(#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \
} \
} while(0)
throw ::CVC4::IllegalArgumentException("", #arg, __PRETTY_FUNCTION__, ## msg)
#define CheckArgument(cond, arg, msg...) \
do { \
- if(EXPECT_FALSE( ! (cond) )) { \
+ if(__builtin_expect( ( ! (cond) ), false )) { \
throw ::CVC4::IllegalArgumentException(#cond, #arg, __PRETTY_FUNCTION__, ## msg); \
} \
} while(0)
#define AlwaysAssertArgument(cond, arg, msg...) \
do { \
- if(EXPECT_FALSE( ! (cond) )) { \
+ if(__builtin_expect( ( ! (cond) ), false )) { \
throw ::CVC4::AssertArgumentException(#cond, #arg, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \
} \
} while(0)
# define AssertArgument(cond, arg, msg...) AlwaysAssertArgument(cond, arg, ## msg)
# define DebugCheckArgument(cond, arg, msg...) CheckArgument(cond, arg, ## msg)
#else /* ! CVC4_ASSERTIONS */
-# define Assert(cond, msg...) /*EXPECT_TRUE( cond )*/
-# define AssertArgument(cond, arg, msg...) /*EXPECT_TRUE( cond )*/
-# define DebugCheckArgument(cond, arg, msg...) /*EXPECT_TRUE( cond )*/
+# define Assert(cond, msg...) /*__builtin_expect( ( cond ), true )*/
+# define AssertArgument(cond, arg, msg...) /*__builtin_expect( ( cond ), true )*/
+# define DebugCheckArgument(cond, arg, msg...) /*__builtin_expect( ( cond ), true )*/
#endif /* CVC4_ASSERTIONS */
}/* CVC4 namespace */
#ifdef CVC4_ASSERTIONS
// the __builtin_expect() helps us if assert is built-in or a macro
-# define cvc4assert(x) assert(EXPECT_TRUE( x ))
+# define cvc4assert(x) assert(__builtin_expect( ( x ), true ))
#else
// TODO: use a compiler annotation when assertions are off ?
// (to improve optimization)
-# define cvc4assert(x) /*EXPECT_TRUE( x )*/
+# define cvc4assert(x) /*__builtin_expect( ( x ), true )*/
#endif /* CVC4_ASSERTIONS */
#endif /* __CVC4__DEBUG_H */
#ifndef CheckArgument
template <class T> inline void CheckArgument(bool cond, const T& arg, const char* fmt, ...) CVC4_PUBLIC;
template <class T> inline void CheckArgument(bool cond, const T& arg, const char* fmt, ...) {
- if(EXPECT_FALSE( !cond )) { \
+ if(__builtin_expect( ( !cond ), false )) { \
throw ::CVC4::IllegalArgumentException("", "", ""); \
} \
}
template <class T> inline void CheckArgument(bool cond, const T& arg) CVC4_PUBLIC;
template <class T> inline void CheckArgument(bool cond, const T& arg) {
- if(EXPECT_FALSE( !cond )) { \
+ if(__builtin_expect( ( !cond ), false )) { \
throw ::CVC4::IllegalArgumentException("", "", ""); \
} \
}
#ifndef DebugCheckArgument
template <class T> inline void DebugCheckArgument(bool cond, const T& arg, const char* fmt, ...) CVC4_PUBLIC;
template <class T> inline void DebugCheckArgument(bool cond, const T& arg, const char* fmt, ...) {
- if(EXPECT_FALSE( !cond )) { \
+ if(__builtin_expect( ( !cond ), false )) { \
throw ::CVC4::IllegalArgumentException("", "", ""); \
} \
}
template <class T> inline void DebugCheckArgument(bool cond, const T& arg) CVC4_PUBLIC;
template <class T> inline void DebugCheckArgument(bool cond, const T& arg) {
- if(EXPECT_FALSE( !cond )) { \
+ if(__builtin_expect( ( !cond ), false )) { \
throw ::CVC4::IllegalArgumentException("", "", ""); \
} \
}