mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed division bug
This commit is contained in:
parent
29dd6c832d
commit
dce27867d3
1 changed files with 32 additions and 26 deletions
|
@ -6176,11 +6176,6 @@ void BeMCContext::InitializedPassHelper(BeMCBlock* mcBlock, BeVTrackingGenContex
|
|||
|
||||
//OutputDebugStrF("InitializedPassHelper %@\n", vregsInitialized.mList);
|
||||
|
||||
if (mDebugging)
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
|
||||
mActiveBlock = mcBlock;
|
||||
for (int instIdx = 0; instIdx < (int)mcBlock->mInstructions.size(); instIdx++)
|
||||
{
|
||||
|
@ -9225,6 +9220,35 @@ bool BeMCContext::DoLegalization()
|
|||
auto arg0Type = GetType(arg0);
|
||||
if (arg0Type->IsInt())
|
||||
{
|
||||
if (arg1.mKind == BeMCOperandKind_NativeReg)
|
||||
{
|
||||
// We can't allow division by RDX because we need RAX:RDX for the dividend
|
||||
auto divisorReg = ResizeRegister(arg1.mReg, 8);
|
||||
if ((arg1.IsNativeReg()) &&
|
||||
((divisorReg == X64Reg_RDX) || (divisorReg == X64Reg_RAX)))
|
||||
{
|
||||
BF_ASSERT(inst->mArg1.IsVRegAny());
|
||||
int vregIdx = GetUnderlyingVReg(inst->mArg1.mVRegIdx);
|
||||
auto vregInfo = mVRegInfo[vregIdx];
|
||||
if (vregInfo != NULL)
|
||||
{
|
||||
vregInfo->mDisableRAX = true;
|
||||
vregInfo->mDisableRDX = true;
|
||||
isFinalRun = false;
|
||||
if (debugging)
|
||||
OutputDebugStrF(" Div/Rem invalid reg\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto vregInfo = GetVRegInfo(arg1);
|
||||
if ((vregInfo != NULL) && (vregInfo->mIsExpr))
|
||||
{
|
||||
ReplaceWithNewVReg(inst->mArg1, instIdx, true);
|
||||
}
|
||||
}
|
||||
|
||||
// DIV/IDIV can only operate on the RDX:RAX pair, except for i8 divide which just uses AX
|
||||
bool isRegADividend = (arg0.mReg == X64Reg_RAX) || (arg0.mReg == X64Reg_EAX) || (arg0.mReg == X64Reg_AX) || (arg0.mReg == X64Reg_AL);
|
||||
if ((!arg0.IsNativeReg()) || (!isRegADividend) ||
|
||||
|
@ -9295,24 +9319,6 @@ bool BeMCContext::DoLegalization()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We can't allow division by RDX because we need RAX:RDX for the dividend
|
||||
auto divisorReg = ResizeRegister(arg1.mReg, 8);
|
||||
if ((arg1.IsNativeReg()) &&
|
||||
((divisorReg == X64Reg_RDX) || (divisorReg == X64Reg_RAX)))
|
||||
{
|
||||
BF_ASSERT(inst->mArg1.IsVRegAny());
|
||||
int vregIdx = GetUnderlyingVReg(inst->mArg1.mVRegIdx);
|
||||
auto vregInfo = mVRegInfo[vregIdx];
|
||||
if (vregInfo != NULL)
|
||||
{
|
||||
vregInfo->mDisableRAX = true;
|
||||
vregInfo->mDisableRDX = true;
|
||||
isFinalRun = false;
|
||||
if (debugging)
|
||||
OutputDebugStrF(" Div/Rem invalid reg\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (inst->mKind == BeMCInstKind_IRem)
|
||||
{
|
||||
|
@ -14767,7 +14773,7 @@ void BeMCContext::Generate(BeFunction* function)
|
|||
mDbgPreferredRegs[32] = X64Reg_R8;*/
|
||||
|
||||
//mDbgPreferredRegs[8] = X64Reg_RAX;
|
||||
//mDebugging = function->mName == "?BytesToPixels@Sprite@Strawberry@bf@@AEAAXPEAV?$Array1@E@System@3@PEAV?$Array1@UColor@Strawberry@bf@@@53@W4Modes@123@1@Z";
|
||||
//mDebugging = function->mName == "?Main$oB@Program@GameOfLife@bf@@QEAAXPEAVWindow@Window@SFML@3@UMouseButtonEventData@563@@Z";
|
||||
//"?ColorizeCodeString@IDEUtils@IDE@bf@@SAXPEAVString@System@3@W4CodeKind@123@@Z";
|
||||
//"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue