From 1e13124091beff28c4b25df903ce10bd7447f283 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 5 Oct 2023 14:16:00 -0500 Subject: [PATCH] Tweaked LFS_ASSERT impl to use __builtin_unreachable First, realized the the LFS_UNREACHABLE logic was flipped after a confusing test bug (damn double negatives). But also realized LFS_ASSERT could be tweaked to "call" __builtin_unreachable() on assert failure to act as a sort of compiler hint. Turns out this hint saves a little bit of code, note both builds have LFS_UNREACHABLE fixed: code stack without __builtin_unreachable: 28408 1928 with __builtin_unreachable: 28324 (-0.3%) 1920 (+0.0%) Since __builtin_unreachable is a compiler extension, its usage respects LFS_NO_INTRINSICS. --- lfs_util.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lfs_util.h b/lfs_util.h index 555569e0..b816d305 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -95,6 +95,8 @@ extern "C" #ifndef LFS_ASSERT #ifndef LFS_NO_ASSERT #define LFS_ASSERT(test) assert(test) +#elif !defined(LFS_NO_INTRINSICS) +#define LFS_ASSERT(test) ((test) ? (void)0 : __builtin_unreachable()) #else #define LFS_ASSERT(test) #endif @@ -102,9 +104,11 @@ extern "C" #ifndef LFS_UNREACHABLE #ifndef LFS_NO_ASSERT +#define LFS_UNREACHABLE() LFS_ASSERT(false) +#elif !defined(LFS_NO_INTRINSICS) #define LFS_UNREACHABLE() __builtin_unreachable() #else -#define LFS_UNREACHABLE() LFS_ASSERT(false) +#define LFS_UNREACHABLE() #endif #endif