From c7747ec5a015b15ea5270a35dd547c9cfbc999ea Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 29 Apr 2024 22:16:06 -0400 Subject: [PATCH] Remove a conditional from the hot path. --- Machines/Acorn/Archimedes/MemoryController.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Machines/Acorn/Archimedes/MemoryController.hpp b/Machines/Acorn/Archimedes/MemoryController.hpp index 48056e6a6..0a7c83a7d 100644 --- a/Machines/Acorn/Archimedes/MemoryController.hpp +++ b/Machines/Acorn/Archimedes/MemoryController.hpp @@ -135,7 +135,7 @@ struct MemoryController { case Zone::LogicallyMappedRAM: { const auto item = logical_ram(address, trans); - if(!item) { + if(item < reinterpret_cast(ram_.data())) { return false; } *item = source; @@ -182,7 +182,7 @@ struct MemoryController { case Zone::LogicallyMappedRAM: { const auto item = logical_ram(address, trans); - if(!item) { + if(item < reinterpret_cast(ram_.data())) { return false; } source = *item; @@ -276,8 +276,8 @@ struct MemoryController { } bool has_moved_rom_ = false; - std::array ram_{}; std::array rom_; + std::array ram_{}; InputOutputController ioc_; template @@ -353,6 +353,7 @@ struct MemoryController { bool map_dirty_ = true; + /// @returns A pointer to somewhere in @c ram_ if RAM is mapped to this area, or a pointer to somewhere lower than @c ram_.data() otherwise. template IntT *logical_ram(uint32_t address, bool trans) { // Possibly TODO: this recompute-if-dirty flag is supposed to ameliorate for an expensive @@ -366,10 +367,6 @@ struct MemoryController { const size_t page = address >> page_address_shift_; const auto &map = mapping(trans, os_mode_); - if(!map[page]) { - return nullptr; - } - address &= page_adddress_mask_; return reinterpret_cast(&map[page][address]); } @@ -389,7 +386,9 @@ struct MemoryController { void update_mapping() { // Clear all logical mappings. for(auto &map: mapping_) { - std::fill(map.begin(), map.end(), nullptr); + // Seed all pointers to an address sufficiently far lower than the beginning of RAM as to mark + // the entire page as unmapped no matter what offset is added. + std::fill(map.begin(), map.end(), ram_.data() - 32768); } // For each physical page, project it into logical space