diff --git a/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp b/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp index 4a7fcdb98..a545e15f2 100644 --- a/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp +++ b/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp @@ -517,14 +517,15 @@ void Dispatcher::EmitDispatcher() { ldr(ARMEmitter::XReg::x3, R, Offset); if (!CTX->Config.DisableVixlIndirectCalls) [[unlikely]] { - GenerateIndirectRuntimeCall(ARMEmitter::Reg::r3); + GenerateIndirectRuntimeCall<__uint128_t, uint64_t, uint64_t, uint64_t>(ARMEmitter::Reg::r3); } else { blr(ARMEmitter::Reg::r3); } - // Result is now in x0 + // Result is now in x0, x1 if (!TMP_ABIARGS) { mov(TMP1, ARMEmitter::XReg::x0); + mov(TMP2, ARMEmitter::XReg::x1); } FillStaticRegs(); @@ -539,8 +540,6 @@ void Dispatcher::EmitDispatcher() { LUDIVHandlerAddress = EmitLongALUOpHandler(STATE_PTR(CpuStateFrame, Pointers.AArch64.LUDIV)); LDIVHandlerAddress = EmitLongALUOpHandler(STATE_PTR(CpuStateFrame, Pointers.AArch64.LDIV)); - LUREMHandlerAddress = EmitLongALUOpHandler(STATE_PTR(CpuStateFrame, Pointers.AArch64.LUREM)); - LREMHandlerAddress = EmitLongALUOpHandler(STATE_PTR(CpuStateFrame, Pointers.AArch64.LREM)); // Interpreter fallbacks { @@ -1036,8 +1035,6 @@ void Dispatcher::InitThreadPointers(FEXCore::Core::InternalThreadState* Thread) auto& AArch64 = Thread->CurrentFrame->Pointers.AArch64; AArch64.LUDIVHandler = LUDIVHandlerAddress; AArch64.LDIVHandler = LDIVHandlerAddress; - AArch64.LUREMHandler = LUREMHandlerAddress; - AArch64.LREMHandler = LREMHandlerAddress; // Fill in the fallback handlers InterpreterOps::FillFallbackIndexPointers(Common.FallbackHandlerPointers, &ABIPointers[0]); diff --git a/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.h b/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.h index cdaad271b..01e97faf7 100644 --- a/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.h +++ b/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.h @@ -118,8 +118,6 @@ private: // Long division helpers uint64_t LUDIVHandlerAddress {}; uint64_t LDIVHandlerAddress {}; - uint64_t LUREMHandlerAddress {}; - uint64_t LREMHandlerAddress {}; void EmitDispatcher(); uint64_t GenerateABICall(FallbackABI ABI); diff --git a/FEXCore/Source/Interface/Core/JIT/ALUOps.cpp b/FEXCore/Source/Interface/Core/JIT/ALUOps.cpp index 5a178d83c..4e7ce135a 100644 --- a/FEXCore/Source/Interface/Core/JIT/ALUOps.cpp +++ b/FEXCore/Source/Interface/Core/JIT/ALUOps.cpp @@ -956,18 +956,9 @@ DEF_OP(LDiv) { blr(TMP4); ldr(ARMEmitter::XReg::lr, ARMEmitter::Reg::rsp, 16); - // Move result to its destination register + // Move results to the destination registers mov(EmitSize, Quotient, TMP1); - - // TODO: Merge division/remainder - mov(EmitSize, TMP1, Upper); - mov(EmitSize, TMP2, Lower); - mov(EmitSize, TMP3, Divisor); - ldr(TMP4, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.AArch64.LREMHandler)); - str(ARMEmitter::XReg::lr, ARMEmitter::Reg::rsp, -16); - blr(TMP4); - ldr(ARMEmitter::XReg::lr, ARMEmitter::Reg::rsp, 16); - mov(EmitSize, Remainder, TMP1); + mov(EmitSize, Remainder, TMP2); // Skip 64-bit path b(&LongDIVRet); @@ -1036,18 +1027,9 @@ DEF_OP(LUDiv) { blr(TMP4); ldr(ARMEmitter::XReg::lr, ARMEmitter::Reg::rsp, 16); - // Move result to its destination register + // Move results to the destination registers mov(EmitSize, Quotient, TMP1); - - // TODO: Merge remainder with the division - mov(EmitSize, TMP1, Upper); - mov(EmitSize, TMP2, Lower); - mov(EmitSize, TMP3, Divisor); - ldr(TMP4, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.AArch64.LUREMHandler)); - str(ARMEmitter::XReg::lr, ARMEmitter::Reg::rsp, -16); - blr(TMP4); - ldr(ARMEmitter::XReg::lr, ARMEmitter::Reg::rsp, 16); - mov(EmitSize, Remainder, TMP1); + mov(EmitSize, Remainder, TMP2); // Skip 64-bit path b(&LongDIVRet); diff --git a/FEXCore/Source/Interface/Core/JIT/JIT.cpp b/FEXCore/Source/Interface/Core/JIT/JIT.cpp index 8cd910bf4..f0666f501 100644 --- a/FEXCore/Source/Interface/Core/JIT/JIT.cpp +++ b/FEXCore/Source/Interface/Core/JIT/JIT.cpp @@ -41,31 +41,32 @@ $end_info$ #include namespace { -static uint64_t LUDIV(uint64_t SrcHigh, uint64_t SrcLow, uint64_t Divisor) { +struct DivRem { + uint64_t Quotient; + uint64_t Remainder; +}; + +static struct DivRem LUDIV(uint64_t SrcHigh, uint64_t SrcLow, uint64_t Divisor) { __uint128_t Source = (static_cast<__uint128_t>(SrcHigh) << 64) | SrcLow; - __uint128_t Res = Source / Divisor; - return Res; + + return { + .Quotient = (uint64_t)(Source / Divisor), + .Remainder = (uint64_t)(Source % Divisor), + }; } -static int64_t LDIV(uint64_t SrcHigh, uint64_t SrcLow, int64_t Divisor) { +static struct DivRem +LDIV(uint64_t SrcHigh, uint64_t SrcLow, int64_t Divisor) { __int128_t Source = (static_cast<__uint128_t>(SrcHigh) << 64) | SrcLow; - __int128_t Res = Source / Divisor; - return Res; + + return { + .Quotient = (uint64_t)(Source / Divisor), + .Remainder = (uint64_t)(Source % Divisor), + }; } -static uint64_t LUREM(uint64_t SrcHigh, uint64_t SrcLow, uint64_t Divisor) { - __uint128_t Source = (static_cast<__uint128_t>(SrcHigh) << 64) | SrcLow; - __uint128_t Res = Source % Divisor; - return Res; -} - -static int64_t LREM(uint64_t SrcHigh, uint64_t SrcLow, int64_t Divisor) { - __int128_t Source = (static_cast<__uint128_t>(SrcHigh) << 64) | SrcLow; - __int128_t Res = Source % Divisor; - return Res; -} - -static void PrintValue(uint64_t Value) { +static void +PrintValue(uint64_t Value) { LogMan::Msg::DFmt("Value: 0x{:x}", Value); } @@ -545,8 +546,6 @@ Arm64JITCore::Arm64JITCore(FEXCore::Context::ContextImpl* ctx, FEXCore::Core::In AArch64.LUDIV = reinterpret_cast(LUDIV); AArch64.LDIV = reinterpret_cast(LDIV); - AArch64.LUREM = reinterpret_cast(LUREM); - AArch64.LREM = reinterpret_cast(LREM); } CurrentCodeBuffer = CodeBuffers.GetLatest();