From 7d58a63071fb8a675275b38a28b7e18c1a9046a5 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 13 Jan 2007 23:06:06 +0100 Subject: [PATCH] [MINOR] added the Linux-style likely/unlikely macros Recent GCC versions support the __builtin_expect() macro which is undecipherable. Let's use likely()/unlikely() like it's done in Linux. --- include/common/standard.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/common/standard.h b/include/common/standard.h index 0b2ea8d8a..fa9ed17ac 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -36,6 +36,19 @@ * power of 2, and 0 otherwise */ #define POWEROF2(x) (((x) & ((x)-1)) == 0) +/* + * Gcc >= 3 provides the ability for the programme to give hints to the + * compiler about what branch of an if is most likely to be taken. This + * helps the compiler produce the most compact critical paths, which is + * generally better for the cache and to reduce the number of jumps. + */ +#if __GNUC__ < 3 +#define __builtin_expect(x,y) (x) +#endif + +#define likely(x) (__builtin_expect((x) != 0, 1)) +#define unlikely(x) (__builtin_expect((x) != 0, 0)) + /* * copies at most chars from to . Last char is always