Skip to content

Commit

Permalink
Merge branch 'hoist_pool_allocator' of https://github.com/kgorking/ecs
Browse files Browse the repository at this point in the history
…into hoist_pool_allocator
  • Loading branch information
kgorking committed Mar 28, 2024
2 parents 2633be8 + 1b9d566 commit 38b7799
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
44 changes: 23 additions & 21 deletions include/ecs/ecs.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,30 @@ namespace ecs::detail {
}
} // namespace ecs::detail

#if __has_cpp_attribute(assume)
#define Assume(expression) [[assume((expression))]]
#else
#ifdef _MSC_VER
#define Assume(expression) __assume((expression))
#elif defined(__clang)
#define Assume(expression) __builtin_assume((expression))
#elif defined(GCC)
#define Assume(expression) __attribute__((assume((expression))))
#else
#define Assume(expression) /* unknown */
#endif
#endif // __has_cpp_attribute

#define ECS_InvokeContractBreach(expression, message, func) \
do { \
if (!(expression)) { \
if (std::is_constant_evaluated()) \
std::unreachable(); \
else \
func(#expression, message); \
if (!std::is_constant_evaluated()) \
func(#expression, message); \
/* Contract handler should not let execution reach here */ \
std::unreachable(); \
} \
/* (expression) is always true from here on out */ \
Assume(expression); \
} while (false)

#define Assert(expression, message) ECS_InvokeContractBreach(expression, message, ecs::detail::do_assertion_failed)
Expand All @@ -850,23 +866,9 @@ namespace ecs::detail {

#else

#if __has_cpp_attribute(assume)
#define ASSUME(expression) [[assume((expression))]]
#else
#ifdef _MSC_VER
#define ASSUME(expression) __assume((expression))
#elif defined(__clang)
#define ASSUME(expression) __builtin_assume((expression))
#elif defined(GCC)
#define ASSUME(expression) __attribute__((assume((expression))))
#else
#define ASSUME(expression) /* unknown */
#endif
#endif // __has_cpp_attribute

#define Assert(expression, message) ASSUME(expression)
#define Pre(expression, message) ASSUME(expression)
#define Post(expression, message) ASSUME(expression)
#define Assert(expression, message) Assume(expression)
#define Pre(expression, message) Assume(expression)
#define Post(expression, message) Assume(expression)
#define AssertAudit(expression, message)
#define PreAudit(expression, message)
#define PostAudit(expression, message)
Expand Down
44 changes: 23 additions & 21 deletions include/ecs/ecs_sh.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,14 +824,30 @@ namespace ecs::detail {
}
} // namespace ecs::detail

#if __has_cpp_attribute(assume)
#define Assume(expression) [[assume((expression))]]
#else
#ifdef _MSC_VER
#define Assume(expression) __assume((expression))
#elif defined(__clang)
#define Assume(expression) __builtin_assume((expression))
#elif defined(GCC)
#define Assume(expression) __attribute__((assume((expression))))
#else
#define Assume(expression) /* unknown */
#endif
#endif // __has_cpp_attribute

#define ECS_InvokeContractBreach(expression, message, func) \
do { \
if (!(expression)) { \
if (std::is_constant_evaluated()) \
std::unreachable(); \
else \
func(#expression, message); \
if (!std::is_constant_evaluated()) \
func(#expression, message); \
/* Contract handler should not let execution reach here */ \
std::unreachable(); \
} \
/* (expression) is always true from here on out */ \
Assume(expression); \
} while (false)

#define Assert(expression, message) ECS_InvokeContractBreach(expression, message, ecs::detail::do_assertion_failed)
Expand All @@ -851,23 +867,9 @@ namespace ecs::detail {

#else

#if __has_cpp_attribute(assume)
#define ASSUME(expression) [[assume((expression))]]
#else
#ifdef _MSC_VER
#define ASSUME(expression) __assume((expression))
#elif defined(__clang)
#define ASSUME(expression) __builtin_assume((expression))
#elif defined(GCC)
#define ASSUME(expression) __attribute__((assume((expression))))
#else
#define ASSUME(expression) /* unknown */
#endif
#endif // __has_cpp_attribute

#define Assert(expression, message) ASSUME(expression)
#define Pre(expression, message) ASSUME(expression)
#define Post(expression, message) ASSUME(expression)
#define Assert(expression, message) Assume(expression)
#define Pre(expression, message) Assume(expression)
#define Post(expression, message) Assume(expression)
#define AssertAudit(expression, message)
#define PreAudit(expression, message)
#define PostAudit(expression, message)
Expand Down

0 comments on commit 38b7799

Please sign in to comment.