1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-28 22:30:30 +00:00

Build max into the sequencer.

This commit is contained in:
Thomas Harte 2023-06-12 15:35:33 -04:00
parent 05d2e78f80
commit 77c67ab59d

View File

@ -11,7 +11,7 @@
namespace Dispatcher {
template <int max, typename SequencerT>
template <typename SequencerT>
struct Dispatcher {
/// Perform @c target.perform<n>() for the input range `start <= n < end`.
@ -21,7 +21,7 @@ struct Dispatcher {
// Minor optimisation: do a comparison with end once outside the loop and if it implies so
// then do no further comparisons within the loop. This is somewhat targetted at expected
// use cases.
if(end < max) {
if(end < SequencerT::max) {
dispatch<true>(target, start, end, args...);
} else {
dispatch<false>(target, start, end, args...);
@ -30,7 +30,7 @@ struct Dispatcher {
private:
template <bool use_end, typename... Args> void dispatch(SequencerT &target, int start, int end, Args&&... args) {
static_assert(max < 2048);
static_assert(SequencerT::max < 2048);
// Yes, macros, yuck. But I want an actual switch statement for the dispatch to start
// and to allow a simple [[fallthrough]] through all subsequent steps up until end.
@ -38,15 +38,15 @@ private:
//
// Sensible choices by the optimiser are assumed.
#define index(n) \
case n: \
if constexpr (n <= max) { \
if constexpr (n == max) return; \
if constexpr (n < max) { \
if(use_end && end == n) return; \
} \
target.template perform<n>(args...); \
} \
#define index(n) \
case n: \
if constexpr (n <= SequencerT::max) { \
if constexpr (n == SequencerT::max) return; \
if constexpr (n < SequencerT::max) { \
if(use_end && end == n) return; \
} \
target.template perform<n>(args...); \
} \
[[fallthrough]];
#define index2(n) index(n); index(n+1);