From: Nikos Mavrogiannopoulos Date: Fri, 11 Nov 2011 12:52:45 +0000 (+0100) Subject: define likely() and unlikely() and use them to prevent debugging code from being... X-Git-Tag: gnutls_3_0_8~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0ce54b38ba3060bbee8f3314138fba45ce816e7;p=thirdparty%2Fgnutls.git define likely() and unlikely() and use them to prevent debugging code from being prioritized in branch prediction. --- diff --git a/lib/gnutls_errors.h b/lib/gnutls_errors.h index 8f1c05d9ed..9907c63a62 100644 --- a/lib/gnutls_errors.h +++ b/lib/gnutls_errors.h @@ -58,10 +58,10 @@ _gnutls_audit_log (gnutls_session_t, const char *fmt, ...) void _gnutls_mpi_log (const char *prefix, bigint_t a); #ifdef C99_MACROS -#define LEVEL(l, ...) do { if (_gnutls_log_level >= l || _gnutls_log_level > 9) \ +#define LEVEL(l, ...) do { if (unlikely(_gnutls_log_level >= l || _gnutls_log_level > 9)) \ _gnutls_log( l, __VA_ARGS__); } while(0) -#define LEVEL_EQ(l, ...) do { if (_gnutls_log_level == l || _gnutls_log_level > 9) \ +#define LEVEL_EQ(l, ...) do { if (unlikely(_gnutls_log_level == l || _gnutls_log_level > 9)) \ _gnutls_log( l, __VA_ARGS__); } while(0) #define _gnutls_debug_log(...) LEVEL(2, __VA_ARGS__) diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 4818eebaeb..92acdd26c6 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -58,6 +58,21 @@ typedef int ssize_t; # define memxor gl_memxor #endif +#ifdef __GNUC__ +# ifndef _GNUTLS_GCC_VERSION +# define _GNUTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +# endif +# if _GNUTLS_GCC_VERSION >= 30100 +# define likely(x) __builtin_expect((x), 1) +# define unlikely(x) __builtin_expect((x), 0) +# endif +#endif + +#ifndef likely +# define likely +# define unlikely +#endif + /* some systems had problems with long long int, thus, * it is not used. */