This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ecdaeddfcda1bd78a76cacdc43be68bca0265b20
Author: yinshengkai <yinsheng...@xiaomi.com>
AuthorDate: Thu Feb 23 16:05:19 2023 +0800

    include: add likely and unlikely for branch prediction
    
    Signed-off-by: yinshengkai <yinsheng...@xiaomi.com>
---
 include/nuttx/compiler.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h
index 4b70be9e80..33bc732150 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)

Reply via email to