From 4dae7d20f030278b9ba3597c52c6497d371cbcb4 Mon Sep 17 00:00:00 2001 From: Gabriel Correia Date: Wed, 12 Jun 2024 22:59:42 -0300 Subject: [PATCH] `EE`: We dont need to store the diff. between the generated cycles --- .../main/cpp/cosmic/creeper/cached_blocks.cpp | 2 +- .../main/cpp/cosmic/creeper/cached_blocks.h | 2 +- .../cpp/cosmic/creeper/dispatch_functions.cpp | 4 +-- app/src/main/cpp/cosmic/ee/ee_core.cpp | 32 +----------------- app/src/main/cpp/cosmic/ee/ee_core.h | 33 ++++++++++++++++--- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp b/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp index 382f127..e244d79 100644 --- a/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp +++ b/app/src/main/cpp/cosmic/creeper/cached_blocks.cpp @@ -163,7 +163,7 @@ namespace cosmic::creeper { isCached = true; } if (!isCached || !chosen || !chosen->isLoaded) { - throw AppErr("No translated block was created or found; there is a bug in the code"); + throw AppErr("No translated block was created or found"); } runFasterBlock(PCs[0], PCs[1]); executionPipe[0] = cpu->runCycles; diff --git a/app/src/main/cpp/cosmic/creeper/cached_blocks.h b/app/src/main/cpp/cosmic/creeper/cached_blocks.h index ee73947..87da9ad 100644 --- a/app/src/main/cpp/cosmic/creeper/cached_blocks.h +++ b/app/src/main/cpp/cosmic/creeper/cached_blocks.h @@ -29,7 +29,7 @@ namespace cosmic::creeper { return static_cast(static_cast(dest) ^ static_cast(src)); } }; - enum InstructionExtraCycles: i16 { + enum InstructionExtraCycles: u32 { None = 0, Div = 37, Mul = 4 diff --git a/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp b/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp index 12127d3..8bd1316 100644 --- a/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp +++ b/app/src/main/cpp/cosmic/creeper/dispatch_functions.cpp @@ -158,8 +158,8 @@ namespace cosmic::creeper { getOpcodeHandler(ivCore, coreOps, microCodes, set); if (!microCodes.execute) { - microCodes.execute = [&](Operands& err) { - throw AppErr("Currently, we cannot handle the operation {:#x} at PC address {:#x}", err.inst, actualPc); + microCodes.execute = [](Operands& err) { + throw AppErr("Currently, we cannot handle the operation {:#x} at PC address {:#x}", err.inst, static_cast(cpu->eePc)); }; return; } diff --git a/app/src/main/cpp/cosmic/ee/ee_core.cpp b/app/src/main/cpp/cosmic/ee/ee_core.cpp index 6b1e1e6..6b4c743 100644 --- a/app/src/main/cpp/cosmic/ee/ee_core.cpp +++ b/app/src/main/cpp/cosmic/ee/ee_core.cpp @@ -30,12 +30,11 @@ namespace cosmic::ee { vst1_u64_x4(gprs + regRange + 4, zero); vst1_u64_x4(gprs + regRange + 6, zero); } - runCycles = cycles[0] = 0; + runCycles = {}; user->info("(EE): Emotion Engine is finally reset to default, " "GPR {}: {}", eeAllGprIdentifier[15], fmt::join(GPRs[15].dw, ", ")); } void EeMipsCore::pulse(u32 cycles) { - this->cycles[0] = cycles; cop0.count += cycles; if (!irqTrigger) { const i64 beforeInc{runCycles}; @@ -55,35 +54,6 @@ namespace cosmic::ee { } } } - template - T EeMipsCore::mipsRead(u32 address) { - const u32 virt{address / 4096}; - const auto page{cop0.virtMap[virt]}; - const auto br{page == first}; - if (br) { - if constexpr (sizeof(T) == 4) { - return PipeRead(memPipe, address & 0x1fffffff); - } - } else if (page > first) { - return *PipeCraftPtr(memPipe, address & 0xfff); - } - return {}; - } - template - void EeMipsCore::mipsWrite(u32 address, T value) { - const u32 pn{address / 4096}; - const u8* page{cop0.virtMap[pn]}; - [[unlikely]] if (page == first) { - cop0.virtCache->tlbChangeModified(pn, true); - - PipeWrite(memPipe, address & 0x1fffffff, value); - } else if (page > first) { - - auto target{PipeCraftPtr(memPipe, address & 0xfff)}; - *target = value; - } - invalidateExecRegion(address); - } u32 EeMipsCore::fetchByPc() { const u32 orderPC{lastPc}; diff --git a/app/src/main/cpp/cosmic/ee/ee_core.h b/app/src/main/cpp/cosmic/ee/ee_core.h index a70c3f7..d83f38b 100644 --- a/app/src/main/cpp/cosmic/ee/ee_core.h +++ b/app/src/main/cpp/cosmic/ee/ee_core.h @@ -52,10 +52,34 @@ namespace cosmic::ee { const u8* first{reinterpret_cast(1)}; template - T mipsRead(u32 address); - + T mipsRead(u32 address) { + const u32 virt{address / 4096}; + const auto page{cop0.virtMap[virt]}; + const auto br{page == first}; + if (br) { + if constexpr (sizeof(T) == 4) { + return PipeRead(memPipe, address & 0x1fffffff); + } + } else if (page > first) { + return *PipeCraftPtr(memPipe, address & 0xfff); + } + return {}; + } template - void mipsWrite(u32 address, T value); + void mipsWrite(u32 address, T value) { + const u32 pn{address / 4096}; + const u8* page{cop0.virtMap[pn]}; + [[unlikely]] if (page == first) { + cop0.virtCache->tlbChangeModified(pn, true); + + PipeWrite(memPipe, address & 0x1fffffff, value); + } else if (page > first) { + + auto target{PipeCraftPtr(memPipe, address & 0xfff)}; + *target = value; + } + invalidateExecRegion(address); + } inline u32 incPc() { chPc(eePc); @@ -90,8 +114,7 @@ namespace cosmic::ee { } bool isABranch{}; u32 delaySlot{}; - i64 cycles[1], - runCycles; + u32 runCycles; ExecutionMode cpuMode{ExecutionMode::CachedInterpreter}; CtrlCop cop0;