X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fclib.h;h=bdea43b3fe08b17d4b75f71cd1a7c5696b7ce008;hb=3a76dc3f4f32b8af6bd4bb2486008b6ba73a848f;hp=95dadd9c09d68c31a5a255a8339c092e03799a63;hpb=2f6d7bb93c157b874efb79a2d1583a4c368bf89a;p=vpp.git diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h index 95dadd9c09d..bdea43b3fe0 100644 --- a/src/vppinfra/clib.h +++ b/src/vppinfra/clib.h @@ -40,6 +40,10 @@ #include +#ifdef __x86_64__ +#include +#endif + /* Standalone means to not assume we are running on a Unix box. */ #if ! defined (CLIB_STANDALONE) && ! defined (CLIB_LINUX_KERNEL) #define CLIB_UNIX @@ -81,6 +85,9 @@ #define CLIB_PACKED(x) x __attribute__ ((packed)) #define CLIB_UNUSED(x) x __attribute__ ((unused)) +/* similar to CLIB_CACHE_LINE_ALIGN_MARK() but with arbitrary alignment */ +#define CLIB_ALIGN_MARK(name, alignment) u8 name[0] __attribute__((aligned(alignment))) + /* Make a string from the macro's argument */ #define CLIB_STRING_MACRO(x) #x @@ -108,6 +115,14 @@ #define PREDICT_FALSE(x) __builtin_expect((x),0) #define PREDICT_TRUE(x) __builtin_expect((x),1) +/* + * Compiler barrier + * prevent compiler to reorder memory access accross this boundary + * prevent compiler to cache values in register (force reload) + * Not to be confused with CPU memory barrier below + */ +#define CLIB_COMPILER_BARRIER() asm volatile ("":::"memory") + /* Full memory barrier (read and write). */ #define CLIB_MEMORY_BARRIER() __sync_synchronize () @@ -282,6 +297,15 @@ flt_round_to_multiple (f64 x, f64 f) return f * flt_round_nearest (x / f); } +always_inline uword +extract_bits (uword x, int start, int count) +{ +#ifdef __BMI__ + return _bextr_u64 (x, start, count); +#endif + return (x >> start) & pow2_mask (count); +} + #define clib_max(x,y) \ ({ \ __typeof__ (x) _x = (x); \