mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 11:58:59 +02:00
Raises the size of each page entry to 32 bytes, however, it merges them into a single structure THEORETICALLY this is better since the access pattern observed corresponds to the program wanting backing_addr/pointers/blocks immediately after one another. This may improve performance at the cost of some extra memory. Another implementation would be to structure only backing_addr/blocks within the same virtual buffer. Alas spamming virtual buffers is evil since each of them is a cache trasher (imagine jumping from wildly different block to wildly different block immediately). Signed-off-by: lizzie lizzie@eden-emu.dev Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3215 Reviewed-by: DraVee <dravee@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "common/page_table.h"
|
|
#include "common/scope_exit.h"
|
|
|
|
namespace Common {
|
|
|
|
PageTable::PageTable() = default;
|
|
|
|
PageTable::~PageTable() noexcept = default;
|
|
|
|
bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
|
|
Common::ProcessAddress address) const {
|
|
out_context->next_offset = GetInteger(address);
|
|
out_context->next_page = address / page_size;
|
|
|
|
return this->ContinueTraversal(out_entry, out_context);
|
|
}
|
|
|
|
bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
|
|
// Setup invalid defaults.
|
|
out_entry->phys_addr = 0;
|
|
out_entry->block_size = page_size;
|
|
// Validate that we can read the actual entry.
|
|
if (auto const page = context->next_page; page < entries.size()) {
|
|
// Validate that the entry is mapped.
|
|
if (auto const paddr = entries[page].addr; paddr != 0) {
|
|
// Populate the results.
|
|
out_entry->phys_addr = paddr + context->next_offset;
|
|
context->next_page += 1;
|
|
context->next_offset += page_size;
|
|
return true;
|
|
}
|
|
}
|
|
context->next_page += 1;
|
|
context->next_offset += page_size;
|
|
return false;
|
|
}
|
|
|
|
void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits) {
|
|
auto const num_page_table_entries = 1ULL << (address_space_width_in_bits - page_size_in_bits);
|
|
entries.resize(num_page_table_entries);
|
|
current_address_space_width_in_bits = address_space_width_in_bits;
|
|
page_size = 1ULL << page_size_in_bits;
|
|
}
|
|
|
|
} // namespace Common
|