div32: get rid of edge cases. simplify

This commit is contained in:
Flyinghead 2020-06-15 16:56:09 +02:00
parent 22dcb1ec99
commit 5cfed1e482
5 changed files with 14 additions and 31 deletions

View File

@ -74,9 +74,6 @@ static void recSh4_Run()
sh4_dyna_rcb=(u8*)&Sh4cntx + sizeof(Sh4cntx);
INFO_LOG(DYNAREC, "cntx // fpcb offset: %td // pc offset: %td // pc %08X", (u8*)&sh4rcb.fpcb - sh4_dyna_rcb, (u8*)&sh4rcb.cntx.pc - sh4_dyna_rcb, sh4rcb.cntx.pc);
if (!settings.dynarec.safemode)
NOTICE_LOG(DYNAREC, "Warning: Dynarec safe mode is off");
if (settings.dynarec.unstable_opt)
NOTICE_LOG(DYNAREC, "Warning: Unstable optimizations is on");

View File

@ -103,8 +103,6 @@ extern "C" f32 fipr_asm(float* fn, float* fm);
#include "decoder.h"
#include "../sh4_rom.h"
#define BIN_OP_I_BASE(code,type,rtype) \
shil_canonical \
( \
@ -611,35 +609,18 @@ shil_canonical
(
u64,f1,(u32 r1, s32 r2, s32 r3),
s64 dividend = ((s64)r3 << 32) | r1;
bool negative;
if ((r3 ^ r2) & 0x80000000)
{
// 1's complement -> 2's complement
if (dividend < 0)
dividend++;
negative = true;
}
else
negative = false;
// 1's complement -> 2's complement
if (dividend < 0)
dividend++;
s32 quo = (s32)(dividend / r2);
s32 rem = dividend - quo * r2;
u32 negative = (r3 ^ r2) & 0x80000000;
// 2's complement -> 1's complement
if (negative)
{
if (rem < 0 || (rem == 0 && r2 > 0))
rem--;
quo--;
}
else
{
// edge case
if (rem == 0 && dividend < 0 && !(quo & 1))
{
quo--;
rem += r2;
}
}
else if (r3 < 0)
rem--;
u64 rv;
((u32*)&rv)[0]=quo;
@ -671,6 +652,9 @@ u32,f1,(s32 a,s32 b,u32 T),
}
else
{
// 2's complement -> 1's complement
if (b > 0)
a--;
if (T & 1)
a += b;
}

View File

@ -712,7 +712,7 @@ void InitSettings()
settings.dynarec.Enable = true;
settings.dynarec.idleskip = true;
settings.dynarec.unstable_opt = false;
settings.dynarec.safemode = true;
settings.dynarec.safemode = false;
settings.dynarec.disable_vmem32 = false;
settings.dreamcast.cable = 3; // TV composite
settings.dreamcast.region = 3; // default

View File

@ -1298,7 +1298,7 @@ static void gui_display_settings()
{
ImGui::Checkbox("Safe Mode", &settings.dynarec.safemode);
ImGui::SameLine();
ShowHelpMarker("Do not optimize integer division. Recommended");
ShowHelpMarker("Do not optimize integer division. Not recommended");
#if HOST_CPU == CPU_ARM
ImGui::Checkbox("Unstable Optimizations", &settings.dynarec.unstable_opt);
ImGui::SameLine();

View File

@ -210,6 +210,8 @@ TEST_F(Div32Test, Div32uTest)
div32u(1867228769, 653467280, 0);
div32u(1523687288, 32181601, 0);
div32u(3499805483, 1401792939, 29611);
div32u(3499805483u, 1401792939, 29611);
div32u(0x80000000u, 0x80000000u, 0);
}