diff options
| author | lizzie <lizzie@eden-emu.dev> | 2026-09-19 01:39:46 +0200 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2026-09-19 01:39:46 +0200 |
| commit | 9a30172e45fcb7833cc49ba4d6450211449b14df (patch) | |
| tree | 4ab0ffbb276464086615fa247d69a9cdf9d5ac55 /src/dynarmic/tests/print_info.cpp | |
| parent | 07f40d5cac635ff102aa6ce9c32572cc20d69959 (diff) | |
[dynarmic] Coalesce non-exclusive Write/Read fallback functions (#4158)
the general idea is to have a common procedure form whom to call
this way theres less "jumping around" for values of different sizes
additionally this **should** allow for better codegen since
most of the u8,u16,u32,u64 can be held within a u64
theoretically this means that you could deifne callbacks in suck
a way that it's essentially as costly as a `mov r64, m64`
but that's not doable due to the fact we have to do translations...
Is this a good change?
Primarily aimed for x86 and ARM to benefit, but I suppose LooooooongArch64 can benefit too.
Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4158
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Diffstat (limited to 'src/dynarmic/tests/print_info.cpp')
| -rw-r--r-- | src/dynarmic/tests/print_info.cpp | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/src/dynarmic/tests/print_info.cpp b/src/dynarmic/tests/print_info.cpp index 5b1c5cfe63..87f4438ad4 100644 --- a/src/dynarmic/tests/print_info.cpp +++ b/src/dynarmic/tests/print_info.cpp @@ -18,6 +18,7 @@ #include <fmt/format.h> #include <fmt/ostream.h> #include <fmt/ranges.h> +#include "dynarmic/frontend/A32/translate/translate_callbacks.h" #include "dynarmic/mcl/bit.hpp" #include "common/common_types.h" @@ -118,36 +119,47 @@ public: u64 ticks_left = 0; std::map<u32, u8> memory; - std::uint8_t MemoryRead8(u32 vaddr) override { - if (auto iter = memory.find(vaddr); iter != memory.end()) { - return iter->second; + u64 MemoryRead(Dynarmic::A32::VAddr vaddr, size_t size) override { + switch (size) { + case sizeof(u64): + return MemoryRead(vaddr, sizeof(u32)) + | MemoryRead(vaddr + sizeof(u32), sizeof(u32)) << 32; + case sizeof(u32): + return MemoryRead(vaddr, sizeof(u16)) + | MemoryRead(vaddr + sizeof(u16), sizeof(u16)) << 16; + case sizeof(u16): + return MemoryRead(vaddr, sizeof(u8)) + | MemoryRead(vaddr + sizeof(u8), sizeof(u8)) << 8; + case sizeof(u8): { + if (auto const it = memory.find(vaddr); it != memory.end()) + return it->second; + return 0; + } + default: + std::abort(); } - return 0; - } - std::uint16_t MemoryRead16(u32 vaddr) override { - return u16(MemoryRead8(vaddr)) | u16(MemoryRead8(vaddr + 1)) << 8; - } - std::uint32_t MemoryRead32(u32 vaddr) override { - return u32(MemoryRead16(vaddr)) | u32(MemoryRead16(vaddr + 2)) << 16; - } - std::uint64_t MemoryRead64(u32 vaddr) override { - return u64(MemoryRead32(vaddr)) | u64(MemoryRead32(vaddr + 4)) << 32; } - void MemoryWrite8(u32 vaddr, std::uint8_t value) override { - memory[vaddr] = value; - } - void MemoryWrite16(u32 vaddr, std::uint16_t value) override { - MemoryWrite8(vaddr, static_cast<u8>(value)); - MemoryWrite8(vaddr + 1, static_cast<u8>(value >> 8)); - } - void MemoryWrite32(u32 vaddr, std::uint32_t value) override { - MemoryWrite16(vaddr, static_cast<u16>(value)); - MemoryWrite16(vaddr + 2, static_cast<u16>(value >> 16)); - } - void MemoryWrite64(u32 vaddr, std::uint64_t value) override { - MemoryWrite32(vaddr, static_cast<u32>(value)); - MemoryWrite32(vaddr + 4, static_cast<u32>(value >> 32)); + void MemoryWrite(Dynarmic::A32::VAddr vaddr, u64 value, size_t size) override { + switch (size) { + case sizeof(u64): + MemoryWrite(vaddr, u32(value), sizeof(u32)); + MemoryWrite(vaddr + 4, u32(value >> 32), sizeof(u32)); + break; + case sizeof(u32): + MemoryWrite(vaddr, u16(value), sizeof(u16)); + MemoryWrite(vaddr + 2, u16(value >> 16), sizeof(u16)); + break; + case sizeof(u16): + MemoryWrite(vaddr, u8(value), sizeof(u8)); + MemoryWrite(vaddr + 1, u8(value >> 8), sizeof(u8)); + break; + case sizeof(u8): + memory[vaddr] = value; + break; + default: + std::abort(); + } } void CallSVC(std::uint32_t swi) override { @@ -231,7 +243,7 @@ void ExecuteA32Instruction(u32 instruction) { if (const auto address = get_value()) { fmt::print("value: "); if (const auto value = get_value()) { - env.MemoryWrite32(*address, *value); + env.MemoryWrite(*address, *value, sizeof(u32)); fmt::print("> mem[{:#08x}] = {:#08x}\n", *address, *value); } } @@ -247,8 +259,8 @@ void ExecuteA32Instruction(u32 instruction) { cpu.SetFpscr(fpscr); const u32 initial_pc = regs[15]; - env.MemoryWrite32(initial_pc + 0, instruction); - env.MemoryWrite32(initial_pc + 4, 0xEAFFFFFE); // B +0 + env.MemoryWrite(initial_pc + 0, instruction, sizeof(u32)); + env.MemoryWrite(initial_pc + 4, 0xEAFFFFFE, sizeof(u32)); // B +0 cpu.Run(); fmt::print("{}", fmt::join(cpu.Disassemble(), "\n")); |
