summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/clib.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-04-23 13:41:47 +0200
committerDamjan Marion <damarion@cisco.com>2020-04-23 13:45:25 +0200
commit68e5fd5206e75cb367375b4fea2e531a3712fd06 (patch)
tree857b29b0a960a4147c6009cf2edc70bdc0ca7be3 /src/vppinfra/clib.h
parent59f71132edffcfa1b94c400736575bd55bdbd7d7 (diff)
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 <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/clib.h')
-rw-r--r--src/vppinfra/clib.h13
1 files changed, 13 insertions, 0 deletions
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 <vppinfra/config.h>
+#ifdef __x86_64__
+#include <x86intrin.h>
+#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); \