From 35ee774ea8eac9b745f93641a192341fe559fa6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcelina=20Ko=C5=9Bcielnicka?= Date: Tue, 25 May 2021 00:58:17 +0200 Subject: [PATCH] kernel/mem: Add a Mem::narrow helper to split up wide ports. --- kernel/mem.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/mem.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/kernel/mem.cc b/kernel/mem.cc index de8ae8b1b..f2c8dd953 100644 --- a/kernel/mem.cc +++ b/kernel/mem.cc @@ -548,3 +548,54 @@ Cell *Mem::extract_rdff(int idx, FfInitVals *initvals) { return c; } + +void Mem::narrow() { + std::vector new_rd_ports; + std::vector new_wr_ports; + std::vector> new_rd_map; + std::vector> new_wr_map; + for (int i = 0; i < GetSize(rd_ports); i++) { + auto &port = rd_ports[i]; + for (int sub = 0; sub < (1 << port.wide_log2); sub++) { + new_rd_map.push_back(std::make_pair(i, sub)); + } + } + for (int i = 0; i < GetSize(wr_ports); i++) { + auto &port = wr_ports[i]; + for (int sub = 0; sub < (1 << port.wide_log2); sub++) { + new_wr_map.push_back(std::make_pair(i, sub)); + } + } + for (auto &it : new_rd_map) { + MemRd &orig = rd_ports[it.first]; + MemRd port = orig; + if (it.second != 0) + port.cell = nullptr; + if (port.wide_log2) { + port.data = port.data.extract(it.second * width, width); + for (int i = 0; i < port.wide_log2; i++) + port.addr[i] = State(it.second >> i & 1); + port.wide_log2 = 0; + } + new_rd_ports.push_back(port); + } + for (auto &it : new_wr_map) { + MemWr &orig = wr_ports[it.first]; + MemWr port = orig; + if (it.second != 0) + port.cell = nullptr; + if (port.wide_log2) { + port.data = port.data.extract(it.second * width, width); + port.en = port.en.extract(it.second * width, width); + for (int i = 0; i < port.wide_log2; i++) + port.addr[i] = State(it.second >> i & 1); + port.wide_log2 = 0; + } + port.priority_mask.clear(); + for (auto &it2 : new_wr_map) + port.priority_mask.push_back(orig.priority_mask[it2.first]); + new_wr_ports.push_back(port); + } + std::swap(rd_ports, new_rd_ports); + std::swap(wr_ports, new_wr_ports); +} diff --git a/kernel/mem.h b/kernel/mem.h index e0d8c277f..214086ac4 100644 --- a/kernel/mem.h +++ b/kernel/mem.h @@ -75,6 +75,8 @@ struct Mem { static std::vector get_all_memories(Module *module); static std::vector get_selected_memories(Module *module); Cell *extract_rdff(int idx, FfInitVals *initvals); + void narrow(); + Mem(Module *module, IdString memid, int width, int start_offset, int size) : module(module), memid(memid), packed(false), mem(nullptr), cell(nullptr), width(width), start_offset(start_offset), size(size) {} }; -- 2.30.2