From 31ee6f5d3069c23b4a11005b95ee3744b9720a17 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Wed, 27 Oct 2021 18:19:43 +0200 Subject: vppinfra: add CLIB_ASSUME() macro This macro privides a way to tell compiler that it is safe to assume that specified expression is true so it can optimize code accordingly. i.e. CLIB_ASSUME (n < 3); while (n) { /* ... */ } Will tell compiler that n is never going to be >= 3 so instead of creating loop it will just unroll loop 2 times. Type: improvement Change-Id: I718a9b95ff7980d7ac68eb9a88357a4ab6eee74a Signed-off-by: Damjan Marion --- src/vppinfra/clib.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h index 81b59e21a0b..52e721768bc 100644 --- a/src/vppinfra/clib.h +++ b/src/vppinfra/clib.h @@ -124,6 +124,13 @@ #define PREDICT_FALSE(x) __builtin_expect((x),0) #define PREDICT_TRUE(x) __builtin_expect((x),1) #define COMPILE_TIME_CONST(x) __builtin_constant_p (x) +#define CLIB_ASSUME(x) \ + do \ + { \ + if (!(x)) \ + __builtin_unreachable (); \ + } \ + while (0) /* * Compiler barrier -- cgit 1.2.3-korg