Skip to content

Commit

Permalink
Merge pull request #4159 from eggrobin/jumpy-conditions
Browse files Browse the repository at this point in the history
Emit jumps rather than a mix of mov/set/jump for conditions
  • Loading branch information
eggrobin authored Jan 7, 2025
2 parents 535e54c + e98c258 commit d50506b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion geometry/hilbert_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ auto Hilbert<T, T>::Norm(T const& t) -> NormType {
_MSC_FULL_VER == 193'933'523 || \
_MSC_FULL_VER == 194'033'813 || \
_MSC_FULL_VER == 194'134'120 || \
_MSC_FULL_VER == 194'134'123)
_MSC_FULL_VER == 194'134'123 || \
_MSC_FULL_VER == 194'234'435)
template<typename T1, typename T2>
requires hilbert<T1, T2>
auto Hilbert<T1, T2>::InnerProduct(T1 const& t1, T2 const& t2)
Expand Down
27 changes: 16 additions & 11 deletions numerics/osaca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,26 @@ static bool volatile OSACA_loop_terminator = false;

// The branch not taken, determined by evaluating the condition
// `UNDER_OSACA_HYPOTHESES`, is eliminated by `if constexpr`; the condition is
// also compiled normally and assigned to a boolean; whether this results in any
// generated code depends on `OSACA_EVALUATE_CONDITIONS`. Note that, with
// `OSACA_EVALUATE_CONDITIONS`, in `OSACA_IF(p) { } OSACA_ELSE_IF(q) { }`, if
// `p` holds `UNDER_OSACA_HYPOTHESES`, code is generated to evaluate `p`, but
// not `q`.

#define OSACA_IF(condition) \
if constexpr (bool OSACA_CONDITION_QUALIFIER OSACA_computed_condition = \
(condition); \
// also compiled normally. Whether this results in any generated code depends
// on `OSACA_EVALUATE_CONDITIONS`. Note that, with `OSACA_EVALUATE_CONDITIONS`,
// in `OSACA_IF(p) { } OSACA_ELSE_IF(q) { }`, if `p` holds
// `UNDER_OSACA_HYPOTHESES`, code is generated to evaluate `p`, but not `q`.

#define OSACA_IF(condition) \
if constexpr (int const OSACA_evaluate = \
UNDER_OSACA_HYPOTHESES(condition) \
? ((condition) ? 0 : OSACA_branch_not_taken()) \
: ((condition) ? OSACA_branch_not_taken() : 0); \
UNDER_OSACA_HYPOTHESES(condition))

#if OSACA_EVALUATE_CONDITIONS
#define OSACA_CONDITION_QUALIFIER volatile
[[noreturn]] inline int OSACA_branch_not_taken() {
std::abort();
}
#else
#define OSACA_CONDITION_QUALIFIER
inline int OSACA_branch_not_taken() {
return 0;
}
#endif

#else // if !PRINCIPIA_USE_OSACA
Expand Down

0 comments on commit d50506b

Please sign in to comment.