Files
mongo/bson/inline_decls.h

69 lines
1.6 KiB
C
Raw Normal View History

2011-05-10 12:40:01 -04:00
// inline_decls.h
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2010-08-03 11:08:08 -04:00
#pragma once
#if defined(__GNUC__)
#define NOINLINE_DECL __attribute__((noinline))
#elif defined(_MSC_VER)
#define NOINLINE_DECL __declspec(noinline)
2011-01-04 00:40:41 -05:00
#else
2010-08-03 11:08:08 -04:00
#define NOINLINE_DECL
#endif
2011-07-15 14:14:08 -04:00
namespace mongo {
2011-07-11 10:10:50 -04:00
/* Note: do not clutter code with these -- ONLY use in hot spots / significant loops. */
2011-07-11 20:00:54 -04:00
#if !defined(__GNUC__)
2011-07-11 10:10:50 -04:00
// branch prediction. indicate we expect to be true
# define MONGO_likely(x) ((bool)(x))
2011-07-11 10:10:50 -04:00
// branch prediction. indicate we expect to be false
# define MONGO_unlikely(x) ((bool)(x))
2011-07-11 10:10:50 -04:00
2011-07-15 14:14:08 -04:00
# if defined(_WIN32)
// prefetch data from memory
inline void prefetch(const void *p) {
2011-07-15 14:27:12 -04:00
#if defined(_MM_HINT_T0)
2011-07-15 14:14:08 -04:00
_mm_prefetch((char *) p, _MM_HINT_T0);
2011-07-15 14:27:12 -04:00
#endif
2011-07-15 14:14:08 -04:00
}
#else
inline void prefetch(void *p) { }
#endif
2011-07-11 10:10:50 -04:00
2011-07-11 20:00:54 -04:00
#else
2011-07-11 10:10:50 -04:00
# define MONGO_likely(x) ( __builtin_expect((bool)(x), 1) )
# define MONGO_unlikely(x) ( __builtin_expect((bool)(x), 0) )
2011-07-15 14:14:08 -04:00
inline void prefetch(void *p) {
2011-08-02 18:03:46 -04:00
__builtin_prefetch(p);
2011-07-15 14:14:08 -04:00
}
2011-07-11 10:10:50 -04:00
#endif
2011-07-15 14:14:08 -04:00
}