diff options
| author | Julian Blake Kongslie | 2022-07-02 13:45:09 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-07-02 13:45:09 -0700 |
| commit | c72951a36d6cb9775dc1ecd9bc26bc13e796f10c (patch) | |
| tree | 5a8fe196beba5c7c674d1b3d627c9a0beac849f5 /uarch/memory.cpp | |
| parent | Trivial code reorg. (diff) | |
| download | issim-c72951a36d6cb9775dc1ecd9bc26bc13e796f10c.tar.xz | |
Dropping the async interface, and adding some real uarch.
Diffstat (limited to 'uarch/memory.cpp')
| -rw-r--r-- | uarch/memory.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/uarch/memory.cpp b/uarch/memory.cpp new file mode 100644 index 0000000..5cf9920 --- /dev/null +++ b/uarch/memory.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <cstdint> | ||
| 3 | #include <initializer_list> | ||
| 4 | #include <iostream> | ||
| 5 | #include <set> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "aisa/aisa.h" | ||
| 10 | #include "uarch/memory.h" | ||
| 11 | #include "util/assert.h" | ||
| 12 | |||
| 13 | namespace uarch { | ||
| 14 | |||
| 15 | MemStage::MemStage(sim::Scheduler &scheduler, sim::Queue<FillReq> &fillreqq, const std::initializer_list<sim::Queue<Fill> *> &fillqs, sim::Queue<Store> &storeq) | ||
| 16 | : sim::Schedulable(scheduler) | ||
| 17 | , fillreqq(fillreqq) | ||
| 18 | , storeq(storeq) | ||
| 19 | { | ||
| 20 | fillreqq.add_reader(this); | ||
| 21 | for (const auto &q : fillqs) | ||
| 22 | q->add_writer(this); | ||
| 23 | storeq.add_reader(this); | ||
| 24 | } | ||
| 25 | |||
| 26 | void MemStage::clock() | ||
| 27 | { | ||
| 28 | if (storeq.available()) { | ||
| 29 | auto s = storeq.read(); | ||
| 30 | std::uint64_t x = 0; | ||
| 31 | for (unsigned int i = 0; i < s.bytes.size(); ++i) | ||
| 32 | x |= static_cast<std::uint64_t>(s.bytes[i]) << 8 * i; | ||
| 33 | std::cout << "mem stores " << s.bytes.size() << " bytes to " << s.physical_addr << " <- " << x << "\n"; | ||
| 34 | ASSERT(store_mem(s.physical_addr, s.bytes.data(), s.bytes.size()), "Could not complete store"); | ||
| 35 | } else if (fillreqq.available()) { | ||
| 36 | auto r = fillreqq.read(); | ||
| 37 | std::cout << "mem fills " << r.size << " bytes from " << r.physical_addr << "\n"; | ||
| 38 | Fill f; | ||
| 39 | f.physical_addr = r.physical_addr; | ||
| 40 | f.bytes.resize(r.size); | ||
| 41 | ASSERT(fetch_mem(f.bytes.data(), r.physical_addr, r.size), "Could not complete fill"); | ||
| 42 | r.fillq->write(std::move(f)); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | } | ||
