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.
This commit is contained in:
+5
-1
@@ -95,6 +95,8 @@ extern "C"
|
|||||||
#ifndef LFS_ASSERT
|
#ifndef LFS_ASSERT
|
||||||
#ifndef LFS_NO_ASSERT
|
#ifndef LFS_NO_ASSERT
|
||||||
#define LFS_ASSERT(test) assert(test)
|
#define LFS_ASSERT(test) assert(test)
|
||||||
|
#elif !defined(LFS_NO_INTRINSICS)
|
||||||
|
#define LFS_ASSERT(test) ((test) ? (void)0 : __builtin_unreachable())
|
||||||
#else
|
#else
|
||||||
#define LFS_ASSERT(test)
|
#define LFS_ASSERT(test)
|
||||||
#endif
|
#endif
|
||||||
@@ -102,9 +104,11 @@ extern "C"
|
|||||||
|
|
||||||
#ifndef LFS_UNREACHABLE
|
#ifndef LFS_UNREACHABLE
|
||||||
#ifndef LFS_NO_ASSERT
|
#ifndef LFS_NO_ASSERT
|
||||||
|
#define LFS_UNREACHABLE() LFS_ASSERT(false)
|
||||||
|
#elif !defined(LFS_NO_INTRINSICS)
|
||||||
#define LFS_UNREACHABLE() __builtin_unreachable()
|
#define LFS_UNREACHABLE() __builtin_unreachable()
|
||||||
#else
|
#else
|
||||||
#define LFS_UNREACHABLE() LFS_ASSERT(false)
|
#define LFS_UNREACHABLE()
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user