From 8f3e5dcc1710f1298d40098868a0fcc64683abbf Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 2 Jul 2016 18:05:09 +0300 Subject: [PATCH] Added cds_likely/cds_unlikely macro --- cds/compiler/clang/defs.h | 5 +++++ cds/compiler/defs.h | 5 +++++ cds/compiler/gcc/defs.h | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/cds/compiler/clang/defs.h b/cds/compiler/clang/defs.h index 4a84e3a0..7d271354 100644 --- a/cds/compiler/clang/defs.h +++ b/cds/compiler/clang/defs.h @@ -122,6 +122,11 @@ #define CDS_DATA_ALIGNMENT(n) __attribute__ ((aligned (n))) +// likely/unlikely + +#define cds_likely( expr ) __builtin_expect( !!( expr ), 1 ) +#define cds_unlikely( expr ) __builtin_expect( !!( expr ), 0 ) + #include #endif // #ifndef CDSLIB_COMPILER_GCC_DEFS_H diff --git a/cds/compiler/defs.h b/cds/compiler/defs.h index 0e663c8f..34706435 100644 --- a/cds/compiler/defs.h +++ b/cds/compiler/defs.h @@ -65,6 +65,11 @@ # define CDS_EXPORT_API #endif +#ifndef cds_likely +# define cds_likely( expr ) expr +# define cds_unlikely( expr ) expr +#endif + // Features #include diff --git a/cds/compiler/gcc/defs.h b/cds/compiler/gcc/defs.h index e3c91e76..a6028cc6 100644 --- a/cds/compiler/gcc/defs.h +++ b/cds/compiler/gcc/defs.h @@ -97,6 +97,11 @@ # define CDS_DEPRECATED( reason ) __attribute__((deprecated( reason ))) #endif +// likely/unlikely + +#define cds_likely( expr ) __builtin_expect( !!( expr ), 1 ) +#define cds_unlikely( expr ) __builtin_expect( !!( expr ), 0 ) + #include #endif // #ifndef CDSLIB_COMPILER_GCC_DEFS_H -- 2.34.1