Skip to content

Commit

Permalink
Force inline fast_fail to improve MSVC codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbrindle committed Sep 9, 2024
1 parent 0b6810a commit ffa75ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions include/flux/core/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ namespace detail {
struct runtime_error_fn {
private:
[[noreturn]]
static inline void fail_fast()
FLUX_ALWAYS_INLINE
static void fail_fast()
{
#if FLUX_HAS_BUILTIN_TRAP
__builtin_trap();
Expand Down Expand Up @@ -67,8 +68,9 @@ struct runtime_error_fn {

public:
[[noreturn]]
inline void operator()(char const* msg,
std::source_location loc = std::source_location::current()) const
FLUX_ALWAYS_INLINE
void operator()(char const* msg,
std::source_location loc = std::source_location::current()) const
{
if constexpr (config::on_error == error_policy::fail_fast) {
fail_fast();
Expand Down Expand Up @@ -125,8 +127,7 @@ struct indexed_bounds_check_fn {
}
}
#endif
assert_fn{}(idx >= T{0}, "index cannot be negative", loc);
assert_fn{}(idx < limit, "out-of-bounds sequence access", loc);
assert_fn{}(idx >= T{0} && idx < limit, "out-of-bounds sequence access", loc);
}
}
};
Expand Down
8 changes: 5 additions & 3 deletions include/flux/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

#define FLUX_DECLVAL(...) ((static_cast<__VA_ARGS__(*)()noexcept>(nullptr))())

#ifdef __GNUC__
#define FLUX_ALWAYS_INLINE [[gnu::always_inline]]
#if defined(__GNUC__)
# define FLUX_ALWAYS_INLINE [[gnu::always_inline]] inline
#elif defined(_MSC_VER)
# define FLUX_ALWAYS_INLINE __forceinline
#else
#define FLUX_ALWAYS_INLINE
# define FLUX_ALWAYS_INLINE inline
#endif

#define FLUX_NO_UNIQUE_ADDRESS [[no_unique_address]]
Expand Down

0 comments on commit ffa75ca

Please sign in to comment.