From bbaf58c9fd0f485266d86868dc35f1d2be3589cd Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 26 Jun 2022 16:24:13 -0700 Subject: Significant changes, and a working "ISA" that just computes fib(n). --- aisa/simple-models.h | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 aisa/simple-models.h (limited to 'aisa/simple-models.h') diff --git a/aisa/simple-models.h b/aisa/simple-models.h new file mode 100644 index 0000000..89e8752 --- /dev/null +++ b/aisa/simple-models.h @@ -0,0 +1,95 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "aisa/aisa.h" + +namespace aisa { + + template struct PagedMem { + using page_t = std::array; + + static const addr_t PAGE_SIZE = 1 << PAGE_BITS; + static const addr_t PAGE_MASK = PAGE_SIZE - 1; + + std::map pages; + + bool fetch_mem(byte_t *bytes, addr_t addr, addr_t size) + { + if (size == 0) + return true; + auto page_base = addr >> PAGE_BITS; + auto page_offset = addr & PAGE_MASK; + auto size_here = std::min(size, PAGE_SIZE - page_offset); + if (auto page = pages.find(page_base); page != pages.end()) + std::memcpy(bytes, page->second.data() + page_offset, size_here); + else + std::memset(bytes, 0, size_here); + return fetch_mem(bytes + size_here, addr + size_here, size - size_here); + } + + bool store_mem(addr_t addr, const byte_t *bytes, addr_t size) + { + if (size == 0) + return true; + auto page_base = addr >> PAGE_BITS; + auto page_offset = addr & PAGE_MASK; + auto size_here = std::min(size, PAGE_SIZE - page_offset); + std::memcpy(pages[page_base].data() + page_offset, bytes, size_here); + return store_mem(addr + size_here, bytes + size_here, size - size_here); + } + }; + + struct TaskStack { + std::deque> tasks; + + bool pop_task() + { + if (tasks.empty()) + return false; + tasks.pop_back(); + return true; + } + + bool push_task(std::unique_ptr &&task) + { + tasks.emplace_back(std::move(task)); + return true; + } + + std::optional top_task() + { + if (tasks.empty()) + return {}; + return tasks.back().get(); + } + }; + + struct VectorRF { + std::vector> rf; + + std::optional load_reg(regnum_t rn) const + { + if (rf.size() <= rn) + return {}; + return rf[rn]; + } + + bool store_reg(regnum_t rn, regval_t rv) + { + if (rf.size() <= rn) + rf.resize(rn + 1); + rf[rn] = rv; + return true; + } + }; + +} -- cgit v1.2.3