From cb594a4c9ca1fbfb71f6c44e3c219de338703e47 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Thu, 23 Feb 2023 16:11:17 +0800 Subject: [PATCH] include: add branch prediction for assert Signed-off-by: yinshengkai --- 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