Skip to content

Commit

Permalink
Use more common (and readable) names for branch prediction hints
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeard0531 committed Aug 2, 2011
1 parent a83ddcd commit e2778cd
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bson/bson-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace mongo {
}

inline BSONObj BSONElement::embeddedObjectUserCheck() const {
MONGOIF ( isABSONObj() )
if ( MONGO_likely(isABSONObj()) )
return BSONObj(value());
stringstream ss;
ss << "invalid parameter: expected an object (" << fieldName() << ")";
Expand Down
2 changes: 1 addition & 1 deletion bson/bsonobjiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace mongo {
*/
BSONObjIterator(const BSONObj& jso) {
int sz = jso.objsize();
MONGO_IF ( sz == 0 ) {
if ( MONGO_unlikely(sz == 0) ) {
_pos = _theend = 0;
return;
}
Expand Down
12 changes: 6 additions & 6 deletions bson/inline_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ namespace mongo {

#if !defined(__GNUC__)

// branch prediction. indicate we expect to enter the if statement body
# define MONGOIF(x) if( (x) )
// branch prediction. indicate we expect to be true
# define MONGO_likely(x) ((bool)(x))

// branch prediction. indicate we expect to not enter the if statement body
# define MONGO_IF(x) if( (x) )
// branch prediction. indicate we expect to be false
# define MONGO_unlikely(x) ((bool)(x))

# if defined(_WIN32)
// prefetch data from memory
Expand All @@ -56,8 +56,8 @@ namespace mongo {

#else

# define MONGOIF(x) if( __builtin_expect((x), 1) )
# define MONGO_IF(x) if( __builtin_expect((x), 0) )
# define MONGO_likely(x) ( __builtin_expect((bool)(x), 1) )
# define MONGO_unlikely(x) ( __builtin_expect((bool)(x), 0) )

inline void prefetch(void *p) {
__builtin_prefetch(p);
Expand Down
4 changes: 2 additions & 2 deletions db/dur_preplogbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace mongo {
size_t ofs = 1;
MongoMMF *mmf = findMMF_inlock(i->start(), /*out*/ofs);

_IF( !mmf->willNeedRemap() ) {
if( unlikely(!mmf->willNeedRemap()) ) {
// tag this mmf as needed a remap of its private view later.
// usually it will already be dirty/already set, so we do the if above first
// to avoid possibility of cpu cache line contention
Expand Down Expand Up @@ -97,7 +97,7 @@ namespace mongo {
#endif
bb.appendBuf(i->start(), e.len);

_IF (e.len != (unsigned)i->length()) {
if (unlikely(e.len != (unsigned)i->length())) {
log() << "journal info splitting prepBasicWrite at boundary" << endl;

// This only happens if we write to the last byte in a file and
Expand Down
2 changes: 1 addition & 1 deletion db/ops/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace mongo {
int start = 0;
int n = 0;

_IF ( !cc ) {
if ( unlikely(!cc) ) {
log() << "getMore: cursorid not found " << ns << " " << cursorid << endl;
cursorid = 0;
resultFlags = ResultFlag_CursorNotFound;
Expand Down
8 changes: 4 additions & 4 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

/* Note: do not clutter code with these -- ONLY use in hot spots / significant loops. */

// branch prediction. indicate we expect to enter the if statement body
#define IF MONGOIF
// branch prediction. indicate we expect to be true
#define likely MONGO_likely

// branch prediction. indicate we expect to not enter the if statement body
#define _IF MONGO_IF
// branch prediction. indicate we expect to be false
#define unlikely MONGO_unlikely

2 changes: 1 addition & 1 deletion util/alignedbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace mongo {
inline char* grow(unsigned by) {
unsigned oldlen = _len;
_len += by;
MONGO_IF ( _len > _p._size ) {
if (MONGO_unlikely( _len > _p._size )) {
growReallocate(oldlen);
}
return _p._data + oldlen;
Expand Down
2 changes: 1 addition & 1 deletion util/concurrency/rwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ namespace mongo {
pthread_rwlock_t _lock;
const int _lowPriorityWaitMS;
static void check( int x ) {
MONGOIF( x == 0 )
if( likely(x == 0) )
return;
log() << "pthread rwlock failed: " << x << endl;
assert( x == 0 );
Expand Down
2 changes: 1 addition & 1 deletion util/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace mongo {
return Logstream::get().prolog();
}

#define MONGO_LOG(level) MONGO_IF ( logLevel >= (level) ) log( level )
#define MONGO_LOG(level) if ( MONGO_unlikely(logLevel >= (level)) ) log( level )
#define LOG MONGO_LOG

inline Nullstream& log( LogLevel l ) {
Expand Down

0 comments on commit e2778cd

Please sign in to comment.