Skip to content

Commit

Permalink
Emit jumps rather than stores for conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Jan 6, 2025
1 parent 8c5eb1e commit ac924ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 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
29 changes: 17 additions & 12 deletions numerics/osaca.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define PRINCIPIA_USE_OSACA 0
#define PRINCIPIA_USE_OSACA 1

// The macros OSACA_FUNCTION_BEGIN and OSACA_RETURN are used to analyse the
// latency of a double -> double function, as measured, e.g., by the
Expand Down 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 ac924ce

Please sign in to comment.