summaryrefslogtreecommitdiff
path: root/aisa
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-06-25 12:54:33 -0700
committerJulian Blake Kongslie2022-06-25 12:54:33 -0700
commitb62095815137b308a4457c20fec97ca9672c599a (patch)
treee6bd5232545d478d1428cc0d1f4c2fb46b5bf3e7 /aisa
parentDemo for a coroutine-based step evaluator. (diff)
downloadissim-b62095815137b308a4457c20fec97ca9672c599a.tar.xz
Testing some actual support for destinations and custom steps.
Diffstat (limited to 'aisa')
-rw-r--r--aisa/aisa.h44
1 files changed, 22 insertions, 22 deletions
diff --git a/aisa/aisa.h b/aisa/aisa.h
index 8cb302e..123b12a 100644
--- a/aisa/aisa.h
+++ b/aisa/aisa.h
@@ -2,6 +2,7 @@
2 2
3#include <coroutine> 3#include <coroutine>
4#include <cstdint> 4#include <cstdint>
5#include <initializer_list>
5#include <iostream> 6#include <iostream>
6#include <optional> 7#include <optional>
7#include <utility> 8#include <utility>
@@ -16,6 +17,7 @@ namespace aisa {
16 17
17 template<typename CRTP> struct EvalState { 18 template<typename CRTP> struct EvalState {
18 CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); } 19 CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); }
20
19 task<regval_t> async_load_reg(regnum_t rn) 21 task<regval_t> async_load_reg(regnum_t rn)
20 { 22 {
21 while (true) { 23 while (true) {
@@ -24,12 +26,21 @@ namespace aisa {
24 co_await suspend(); 26 co_await suspend();
25 } 27 }
26 } 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 }
27 }; 38 };
28 39
29 struct Step { 40 struct Step {
30 const std::optional<std::pair<regnum_t, regval_t>> predicate; 41 std::optional<std::pair<regnum_t, regval_t>> predicate;
31 const std::vector<regnum_t> source_regs; 42 std::vector<regnum_t> source_regs;
32 const std::vector<regnum_t> destination_regs; 43 std::vector<regnum_t> destination_regs;
33 44
34 std::optional<regnum_t> predicate_reg() const 45 std::optional<regnum_t> predicate_reg() const
35 { 46 {
@@ -45,33 +56,22 @@ namespace aisa {
45 return {}; 56 return {};
46 } 57 }
47 58
48 template<typename State> task<void> evaluate(State &state) const 59 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
49 { 62 {
50 if (predicate.has_value()) { 63 if (predicate.has_value()) {
51 std::cout << "checking predicate...\n";
52 std::cout << "\texpect " << predicate->second << "\n";
53 regval_t pval = co_await state.async_load_reg(predicate->first); 64 regval_t pval = co_await state.async_load_reg(predicate->first);
54 std::cout << "\tgot " << pval << "\n"; 65 if (pval != predicate->second)
55 if (pval != predicate->second) {
56 std::cout << "\tpredicate skipped\n";
57 co_return; 66 co_return;
58 } else {
59 std::cout << "\tpredicate not skipped\n";
60 }
61 } 67 }
62 std::cout << "reading sources...\n";
63 std::vector<regval_t> source_vals; 68 std::vector<regval_t> source_vals;
64 source_vals.reserve(source_regs.size()); 69 source_vals.reserve(source_regs.size());
65 for (unsigned int i = 0; i < source_regs.size(); ++i) {
66 std::cout << "\tgetting source " << i << "...\n";
67 source_vals.emplace_back(co_await state.async_load_reg(source_regs[i]));
68 std::cout << "\t\tgot " << source_vals.back() << "\n";
69 }
70 std::cout << "sources:";
71 for (unsigned int i = 0; i < source_regs.size(); ++i) 70 for (unsigned int i = 0; i < source_regs.size(); ++i)
72 std::cout << " " << source_regs[i] << "=" << source_vals[i]; 71 source_vals.emplace_back(co_await state.async_load_reg(source_regs[i]));
73 std::cout << "\n"; 72 auto destination_vals = compute_destinations(source_vals);
74 std::cout << "done with evaluate\n"; 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 } 75 }
76 }; 76 };
77 77