1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

libreplace: added likely()/unlikely() macros for gcc

These macros allow the compile to better optimise code that has a lot
of if statements. I particularly want to use this for our low level
generated NDR code.
This commit is contained in:
Andrew Tridgell 2009-09-17 09:07:17 -07:00
parent 44674efc81
commit d27140ab76

View File

@ -704,4 +704,23 @@ char *ufc_crypt(const char *key, const char *salt);
#endif #endif
#endif #endif
/* these macros gain us a few percent of speed on gcc */
#if (__GNUC__ >= 3)
/* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
as its first argument */
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#else
#ifndef likely
#define likely(x) (x)
#endif
#ifndef unlikely
#define unlikely(x) (x)
#endif
#endif
#endif /* _LIBREPLACE_REPLACE_H */ #endif /* _LIBREPLACE_REPLACE_H */