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 cb594a4c9ca1fbfb71f6c44e3c219de338703e47
Author: yinshengkai <yinsheng...@xiaomi.com>
AuthorDate: Thu Feb 23 16:11:17 2023 +0800

    include: add branch prediction for assert
    
    Signed-off-by: yinshengkai <yinsheng...@xiaomi.com>
---
 include/assert.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/assert.h b/include/assert.h
index c72a3b998b..7ce0e1512d 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -50,11 +50,11 @@
 #define PANIC()          __assert(__FILE__, __LINE__, "panic")
 
 #ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION
-#define ASSERT(f)        do { if (!(f)) __assert(__FILE__, __LINE__, #f); } 
while (0)
-#define VERIFY(f)        do { if ((f) < 0) __assert(__FILE__, __LINE__, #f); } 
while (0)
+#define ASSERT(f)        do { if (unlikely(!(f))) __assert(__FILE__, __LINE__, 
#f); } while (0)
+#define VERIFY(f)        do { if (unlikely((f) < 0)) __assert(__FILE__, 
__LINE__, #f); } while (0)
 #else
-#define ASSERT(f)        do { if (!(f)) __assert(__FILE__, __LINE__, NULL); } 
while (0)
-#define VERIFY(f)        do { if ((f) < 0) __assert(__FILE__, __LINE__, NULL); 
} while (0)
+#define ASSERT(f)        do { if (unlikely(!(f))) __assert(__FILE__, __LINE__, 
NULL); } while (0)
+#define VERIFY(f)        do { if (unlikely((f) < 0)) __assert(__FILE__, 
__LINE__, NULL); } while (0)
 #endif
 
 #ifdef CONFIG_DEBUG_ASSERTIONS

Reply via email to