0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 12:18:54 +02:00

ircd::portable: Optimize redefined macro if conditions are favorable.

This commit is contained in:
Jason Volk 2020-06-04 23:14:13 -07:00
parent 04020a91b7
commit be07ae05b2
3 changed files with 18 additions and 2 deletions

View file

@ -35,7 +35,7 @@ namespace ircd
{ {
void debugtrap() noexcept; void debugtrap() noexcept;
template<class expr> void always_assert(expr&&) noexcept; template<class expr> void always_assert(expr&&) noexcept;
void print_assertion(const char *const &, const char *const &, const unsigned &, const char *const &) noexcept; [[gnu::cold]] void print_assertion(const char *const &, const char *const &, const unsigned &, const char *const &) noexcept;
} }
/// Override the standard assert behavior to take one of several different /// Override the standard assert behavior to take one of several different

View file

@ -65,6 +65,19 @@ namespace ircd
typedef u_long ulong; typedef u_long ulong;
#endif #endif
///TODO: XXX hoist lfence out of unlikely target block
#if defined(RB_ASSERT) && defined(RB_ASSERT_INTRINSIC) && !defined(NDEBUG) && defined(__SSE2__)
#undef assert
#define assert(expr) \
({ \
if(unlikely(!static_cast<bool>(expr))) \
{ \
asm volatile ("lfence"); \
__assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__); \
} \
})
#endif
// //
// Trouble; clang w/ our custom assert // Trouble; clang w/ our custom assert
// //

View file

@ -26,7 +26,10 @@
extern "C" extern "C"
{ {
#include <RB_INC_ASSERT_H #ifndef assert
#include <RB_INC_ASSERT_H
#endif
#include <RB_INC_STDARG_H #include <RB_INC_STDARG_H
#include <RB_INC_UNISTD_H #include <RB_INC_UNISTD_H
#include <RB_INC_SYS_TYPES_H #include <RB_INC_SYS_TYPES_H