From be07ae05b2abaa07ec09fa8de1d1d2b89fdd8201 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 4 Jun 2020 23:14:13 -0700 Subject: [PATCH] ircd::portable: Optimize redefined macro if conditions are favorable. --- include/ircd/assert.h | 2 +- include/ircd/portable.h | 13 +++++++++++++ include/ircd/stdinc.h | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/ircd/assert.h b/include/ircd/assert.h index 12ec29c06..eff141e24 100644 --- a/include/ircd/assert.h +++ b/include/ircd/assert.h @@ -35,7 +35,7 @@ namespace ircd { void debugtrap() noexcept; template 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 diff --git a/include/ircd/portable.h b/include/ircd/portable.h index e1a0a1691..88c57288a 100644 --- a/include/ircd/portable.h +++ b/include/ircd/portable.h @@ -65,6 +65,19 @@ namespace ircd typedef u_long ulong; #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(expr))) \ + { \ + asm volatile ("lfence"); \ + __assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__); \ + } \ + }) +#endif + // // Trouble; clang w/ our custom assert // diff --git a/include/ircd/stdinc.h b/include/ircd/stdinc.h index bd5edd07f..6e40d45b1 100644 --- a/include/ircd/stdinc.h +++ b/include/ircd/stdinc.h @@ -26,7 +26,10 @@ extern "C" { - #include