1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-06 15:00:05 +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 { namespace Dispatcher {
template <int max, typename SequencerT> template <typename SequencerT>
struct Dispatcher { struct Dispatcher {
/// Perform @c target.perform<n>() for the input range `start <= n < end`. /// 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 // 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 // then do no further comparisons within the loop. This is somewhat targetted at expected
// use cases. // use cases.
if(end < max) { if(end < SequencerT::max) {
dispatch<true>(target, start, end, args...); dispatch<true>(target, start, end, args...);
} else { } else {
dispatch<false>(target, start, end, args...); dispatch<false>(target, start, end, args...);
@ -30,7 +30,7 @@ struct Dispatcher {
private: private:
template <bool use_end, typename... Args> void dispatch(SequencerT &target, int start, int end, Args&&... args) { 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 // 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. // 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. // Sensible choices by the optimiser are assumed.
#define index(n) \ #define index(n) \
case n: \ case n: \
if constexpr (n <= max) { \ if constexpr (n <= SequencerT::max) { \
if constexpr (n == max) return; \ if constexpr (n == SequencerT::max) return; \
if constexpr (n < max) { \ if constexpr (n < SequencerT::max) { \
if(use_end && end == n) return; \ if(use_end && end == n) return; \
} \ } \
target.template perform<n>(args...); \ target.template perform<n>(args...); \
} \ } \
[[fallthrough]]; [[fallthrough]];
#define index2(n) index(n); index(n+1); #define index2(n) index(n); index(n+1);