From 68e5fd5206e75cb367375b4fea2e531a3712fd06 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Thu, 23 Apr 2020 13:41:47 +0200 Subject: vppinfra: more bihash optimizatons * Avoid doing expensive bit extraction for most likely case where bucket .log2_page_size == 0 and .linear_search == 0, saves 3-5 cycles for lookup, data_prefetch and add operation * use bextr instruction when available (x86 BMI instruction set) Type: improvement Change-Id: I163df36a29287482c5f133be8b21d62a2f7440de Signed-off-by: Damjan Marion --- src/vppinfra/clib.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/vppinfra/clib.h') diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h index dac41adb165..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 @@ -293,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); \ -- cgit 1.2.3-korg