Common: Add likely() and unlikely() macros to hint likeliness of taking a branch.

The compiled can use these hints to generate the code closer or further
from the entry point depending on likeliness of taking a branch, this
helps when entering the function without prior branch prediction, and
on CPUs without proper branch prediction.
This commit is contained in:
Emmanuel Gil Peyrot 2016-09-11 13:07:54 +09:00
parent 722af0703e
commit d909f18195

View File

@ -29,6 +29,14 @@
#define FORCE_INLINE inline __attribute__((always_inline))
#endif
#if defined(__GNUC__)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x) (x)
#define unlikely(x) (x)
#endif
#ifndef _MSC_VER
#ifdef ARCHITECTURE_x86_64