From ecdaeddfcda1bd78a76cacdc43be68bca0265b20 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Thu, 23 Feb 2023 16:05:19 +0800 Subject: [PATCH] include: add likely and unlikely for branch prediction Signed-off-by: yinshengkai --- include/nuttx/compiler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 4b70be9e801..33bc7321508 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -154,6 +154,11 @@ # define farcall_function __attribute__((long_call)) # endif +/* Branch prediction */ + +# define likely(x) __builtin_expect((x), 1) +# define unlikely(x) __builtin_expect((x), 0) + /* Code locate */ # define locate_code(n) __attribute__((section(n))) @@ -471,6 +476,8 @@ */ # define noreturn_function +# define likely(x) (x) +# define unlikely(x) (x) # define locate_code(n) # define aligned_data(n) # define locate_data(n) @@ -621,6 +628,8 @@ */ # define noreturn_function +# define likely(x) (x) +# define unlikely(x) (x) # define aligned_data(n) # define locate_code(n) # define locate_data(n) @@ -728,6 +737,8 @@ # define weak_const_function # define noreturn_function # define farcall_function +# define likely(x) (x) +# define unlikely(x) (x) # define locate_code(n) # define aligned_data(n) # define locate_data(n) @@ -815,6 +826,8 @@ # define restrict # define noreturn_function # define farcall_function +# define likely(x) (x) +# define unlikely(x) (x) # define aligned_data(n) # define locate_code(n) # define locate_data(n) @@ -877,6 +890,8 @@ # define restrict # define noreturn_function # define farcall_function +# define likely(x) (x) +# define unlikely(x) (x) # define aligned_data(n) # define locate_code(n) # define locate_data(n)