diff options
| author | Julian Blake Kongslie | 2022-06-25 18:56:44 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-06-25 18:56:44 -0700 |
| commit | 968414044e87be7399f73a01b718b4894bb65e01 (patch) | |
| tree | b4ce807d1645d68589028213d9b08d0b496c1b85 /aisa/aisa.h | |
| parent | Testing some actual support for destinations and custom steps. (diff) | |
| download | issim-968414044e87be7399f73a01b718b4894bb65e01.tar.xz | |
Move EvalState and the eval coroutines to a separate header.
Diffstat (limited to 'aisa/aisa.h')
| -rw-r--r-- | aisa/aisa.h | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/aisa/aisa.h b/aisa/aisa.h index 123b12a..c9a215c 100644 --- a/aisa/aisa.h +++ b/aisa/aisa.h | |||
| @@ -15,28 +15,6 @@ namespace aisa { | |||
| 15 | using regnum_t = std::uint_fast64_t; | 15 | using regnum_t = std::uint_fast64_t; |
| 16 | using regval_t = std::uint64_t; | 16 | using regval_t = std::uint64_t; |
| 17 | 17 | ||
| 18 | template<typename CRTP> struct EvalState { | ||
| 19 | CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); } | ||
| 20 | |||
| 21 | task<regval_t> async_load_reg(regnum_t rn) | ||
| 22 | { | ||
| 23 | while (true) { | ||
| 24 | if (auto rv = crtp().load_reg(rn); rv.has_value()) | ||
| 25 | co_return *rv; | ||
| 26 | co_await suspend(); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | task<void> async_store_reg(regnum_t rn, regval_t rv) | ||
| 31 | { | ||
| 32 | while (true) { | ||
| 33 | if (crtp().store_reg(rn, rv)) | ||
| 34 | co_return; | ||
| 35 | co_await suspend(); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | }; | ||
| 39 | |||
| 40 | struct Step { | 18 | struct Step { |
| 41 | std::optional<std::pair<regnum_t, regval_t>> predicate; | 19 | std::optional<std::pair<regnum_t, regval_t>> predicate; |
| 42 | std::vector<regnum_t> source_regs; | 20 | std::vector<regnum_t> source_regs; |
| @@ -57,22 +35,6 @@ namespace aisa { | |||
| 57 | } | 35 | } |
| 58 | 36 | ||
| 59 | virtual std::vector<regval_t> compute_destinations(const std::vector<regval_t> &source_vals) const = 0; | 37 | virtual std::vector<regval_t> compute_destinations(const std::vector<regval_t> &source_vals) const = 0; |
| 60 | |||
| 61 | template<typename State> task<void> eval(State &state) const | ||
| 62 | { | ||
| 63 | if (predicate.has_value()) { | ||
| 64 | regval_t pval = co_await state.async_load_reg(predicate->first); | ||
| 65 | if (pval != predicate->second) | ||
| 66 | co_return; | ||
| 67 | } | ||
| 68 | std::vector<regval_t> source_vals; | ||
| 69 | source_vals.reserve(source_regs.size()); | ||
| 70 | for (unsigned int i = 0; i < source_regs.size(); ++i) | ||
| 71 | source_vals.emplace_back(co_await state.async_load_reg(source_regs[i])); | ||
| 72 | auto destination_vals = compute_destinations(source_vals); | ||
| 73 | for (unsigned int i = 0; i < destination_regs.size(); ++i) | ||
| 74 | co_await state.async_store_reg(destination_regs[i], destination_vals[i]); | ||
| 75 | } | ||
| 76 | }; | 38 | }; |
| 77 | 39 | ||
| 78 | } | 40 | } |
