Skip to content

Commit

Permalink
Merge branch 'dragonbookgz' into dragonbook
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Jun 28, 2023
2 parents 2213a09 + 2248fbc commit 5c873ee
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 74 deletions.
4 changes: 2 additions & 2 deletions libraries/dragonbook/src/mc/MachineCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ void MachineCodeWriter::or8(MachineInst* inst)

void MachineCodeWriter::xorpd(MachineInst* inst)
{
emitInstSSE_RM(0, { 0x66, 0x0f, 0x57 }, inst);
emitInstSSE_RM(OpFlags::SizeOverride, { 0x0f, 0x57 }, inst);
}

void MachineCodeWriter::xorps(MachineInst* inst)
Expand Down Expand Up @@ -789,7 +789,7 @@ void MachineCodeWriter::div8(MachineInst* inst)

void MachineCodeWriter::ucomisd(MachineInst* inst)
{
emitInstSSE_RM(0, { 0x66, 0x0f, 0x2e }, inst);
emitInstSSE_RM(OpFlags::SizeOverride, { 0x0f, 0x2e }, inst);
}

void MachineCodeWriter::ucomiss(MachineInst* inst)
Expand Down
13 changes: 6 additions & 7 deletions src/common/scripting/jit/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ JITRuntime* GetJITRuntime();
JitFuncPtr JitCompile(VMScriptFunction* sfunc)
{
#if 0
if (strcmp(sfunc->PrintableName.GetChars(), "DisdainPlayer.AddBloodStain") != 0)
if (strcmp(sfunc->PrintableName.GetChars(), "DisdainPlayer.MovePlayer") != 0)
return nullptr;
#endif

Expand Down Expand Up @@ -109,21 +109,20 @@ IRFunction* JitCompiler::Codegen()
int i = (int)(ptrdiff_t)(pc - sfunc->Code);
op = pc->op;

if (labels[i].block) // This is already a known jump target
if (labels[i].block) // This is already a known jump target (GetLabel already called for this index)
{
if (cc.GetInsertBlock())
cc.CreateBr(labels[i].block);
cc.SetInsertPoint(labels[i].block);
}
else // Save start location in case GetLabel gets called later
else // Save location in case GetLabel gets called later
{
if (!cc.GetInsertBlock())
cc.SetInsertPoint(irfunc->createBasicBlock({}));
labels[i].block = cc.GetInsertBlock();
labels[i].index = labels[i].block->code.size();
}

labels[i].index = labels[i].block->code.size();

int curLine = sfunc->PCToLine(pc);

FString lineinfo;
Expand Down Expand Up @@ -198,10 +197,10 @@ IRBasicBlock* JitCompiler::GetLabel(size_t pos)
curbb->code.erase(itbegin, itend);

// Jump from prev block to next
IRBasicBlock* old = cc.GetInsertBlock();
IRBasicBlock* activebb = cc.GetInsertBlock();
cc.SetInsertPoint(curbb);
cc.CreateBr(newlabelbb);
cc.SetInsertPoint(old);
cc.SetInsertPoint(activebb == curbb ? newlabelbb : activebb);

// Update label
labels[pos].block = newlabelbb;
Expand Down
124 changes: 62 additions & 62 deletions src/common/scripting/jit/jit_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ void JitCompiler::EmitCMPS()
int method = A & CMP_METHOD_MASK;
if (method == CMP_EQ)
{
if (check) result = cc.CreateICmpEQ(result, zero);
else result = cc.CreateICmpNE(result, zero);
if (check) result = cc.CreateICmpNE(result, zero);
else result = cc.CreateICmpEQ(result, zero);
}
else if (method == CMP_LT)
{
if (check) result = cc.CreateICmpSLT(result, zero);
else result = cc.CreateICmpSGE(result, zero);
if (check) result = cc.CreateICmpSGE(result, zero);
else result = cc.CreateICmpSLT(result, zero);
}
else
{
if (check) result = cc.CreateICmpSLE(result, zero);
else result = cc.CreateICmpSGT(result, zero);
if (check) result = cc.CreateICmpSGT(result, zero);
else result = cc.CreateICmpSLE(result, zero);
}

return result;
Expand Down Expand Up @@ -457,8 +457,8 @@ void JitCompiler::EmitEQ_R()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpEQ(LoadD(B), LoadD(C));
else result = cc.CreateICmpNE(LoadD(B), LoadD(C));
if (check) result = cc.CreateICmpNE(LoadD(B), LoadD(C));
else result = cc.CreateICmpEQ(LoadD(B), LoadD(C));
return result;
});
}
Expand All @@ -467,8 +467,8 @@ void JitCompiler::EmitEQ_K()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpEQ(LoadD(B), ConstD(C));
else result = cc.CreateICmpNE(LoadD(B), ConstD(C));
if (check) result = cc.CreateICmpNE(LoadD(B), ConstD(C));
else result = cc.CreateICmpEQ(LoadD(B), ConstD(C));
return result;
});
}
Expand All @@ -477,8 +477,8 @@ void JitCompiler::EmitLT_RR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpSLT(LoadD(B), LoadD(C));
else result = cc.CreateICmpSGE(LoadD(B), LoadD(C));
if (check) result = cc.CreateICmpSGE(LoadD(B), LoadD(C));
else result = cc.CreateICmpSLT(LoadD(B), LoadD(C));
return result;
});
}
Expand All @@ -487,8 +487,8 @@ void JitCompiler::EmitLT_RK()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpSLT(LoadD(B), ConstD(C));
else result = cc.CreateICmpSGE(LoadD(B), ConstD(C));
if (check) result = cc.CreateICmpSGE(LoadD(B), ConstD(C));
else result = cc.CreateICmpSLT(LoadD(B), ConstD(C));
return result;
});
}
Expand All @@ -497,8 +497,8 @@ void JitCompiler::EmitLT_KR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpSLT(ConstD(B), LoadD(C));
else result = cc.CreateICmpSGE(ConstD(B), LoadD(C));
if (check) result = cc.CreateICmpSGE(ConstD(B), LoadD(C));
else result = cc.CreateICmpSLT(ConstD(B), LoadD(C));
return result;
});
}
Expand All @@ -507,8 +507,8 @@ void JitCompiler::EmitLE_RR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpSLE(LoadD(B), LoadD(C));
else result = cc.CreateICmpSGT(LoadD(B), LoadD(C));
if (check) result = cc.CreateICmpSGT(LoadD(B), LoadD(C));
else result = cc.CreateICmpSLE(LoadD(B), LoadD(C));
return result;
});
}
Expand All @@ -517,8 +517,8 @@ void JitCompiler::EmitLE_RK()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpSLE(LoadD(B), ConstD(C));
else result = cc.CreateICmpSGT(LoadD(B), ConstD(C));
if (check) result = cc.CreateICmpSGT(LoadD(B), ConstD(C));
else result = cc.CreateICmpSLE(LoadD(B), ConstD(C));
return result;
});
}
Expand All @@ -527,8 +527,8 @@ void JitCompiler::EmitLE_KR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpSLE(ConstD(B), LoadD(C));
else result = cc.CreateICmpSGT(ConstD(B), LoadD(C));
if (check) result = cc.CreateICmpSGT(ConstD(B), LoadD(C));
else result = cc.CreateICmpSLE(ConstD(B), LoadD(C));
return result;
});
}
Expand All @@ -537,8 +537,8 @@ void JitCompiler::EmitLTU_RR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpULT(LoadD(B), LoadD(C));
else result = cc.CreateICmpUGE(LoadD(B), LoadD(C));
if (check) result = cc.CreateICmpUGE(LoadD(B), LoadD(C));
else result = cc.CreateICmpULT(LoadD(B), LoadD(C));
return result;
});
}
Expand All @@ -547,8 +547,8 @@ void JitCompiler::EmitLTU_RK()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpULT(LoadD(B), ConstD(C));
else result = cc.CreateICmpUGE(LoadD(B), ConstD(C));
if (check) result = cc.CreateICmpUGE(LoadD(B), ConstD(C));
else result = cc.CreateICmpULT(LoadD(B), ConstD(C));
return result;
});
}
Expand All @@ -557,8 +557,8 @@ void JitCompiler::EmitLTU_KR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpULT(ConstD(B), LoadD(C));
else result = cc.CreateICmpUGE(ConstD(B), LoadD(C));
if (check) result = cc.CreateICmpUGE(ConstD(B), LoadD(C));
else result = cc.CreateICmpULT(ConstD(B), LoadD(C));
return result;
});
}
Expand All @@ -567,8 +567,8 @@ void JitCompiler::EmitLEU_RR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpULE(LoadD(B), LoadD(C));
else result = cc.CreateICmpUGT(LoadD(B), LoadD(C));
if (check) result = cc.CreateICmpUGT(LoadD(B), LoadD(C));
else result = cc.CreateICmpULE(LoadD(B), LoadD(C));
return result;
});
}
Expand All @@ -577,8 +577,8 @@ void JitCompiler::EmitLEU_RK()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpULE(LoadD(B), ConstD(C));
else result = cc.CreateICmpUGT(LoadD(B), ConstD(C));
if (check) result = cc.CreateICmpUGT(LoadD(B), ConstD(C));
else result = cc.CreateICmpULE(LoadD(B), ConstD(C));
return result;
});
}
Expand All @@ -587,8 +587,8 @@ void JitCompiler::EmitLEU_KR()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpULE(ConstD(B), LoadD(C));
else result = cc.CreateICmpUGT(ConstD(B), LoadD(C));
if (check) result = cc.CreateICmpUGT(ConstD(B), LoadD(C));
else result = cc.CreateICmpULE(ConstD(B), LoadD(C));
return result;
});
}
Expand Down Expand Up @@ -857,9 +857,9 @@ void JitCompiler::EmitEQF_K()
{
IRValue* result;
if (check)
result = cc.CreateFCmpUEQ(LoadF(B), ConstF(C));
else
result = cc.CreateFCmpUNE(LoadF(B), ConstF(C));
else
result = cc.CreateFCmpUEQ(LoadF(B), ConstF(C));

return result;
}
Expand All @@ -868,13 +868,13 @@ void JitCompiler::EmitEQF_K()
IRValue* diff = cc.CreateFSub(ConstF(C), LoadF(B));
IRValue* result;
if (check)
result = cc.CreateAnd(
cc.CreateFCmpUGT(diff, ConstValueF(-VM_EPSILON)),
cc.CreateFCmpULT(diff, ConstValueF(VM_EPSILON)));
else
result = cc.CreateOr(
cc.CreateFCmpULE(diff, ConstValueF(-VM_EPSILON)),
cc.CreateFCmpUGE(diff, ConstValueF(VM_EPSILON)));
else
result = cc.CreateAnd(
cc.CreateFCmpUGT(diff, ConstValueF(-VM_EPSILON)),
cc.CreateFCmpULT(diff, ConstValueF(VM_EPSILON)));

return result;
}
Expand All @@ -888,9 +888,9 @@ void JitCompiler::EmitLTF_RR()

IRValue* result;
if (check)
result = cc.CreateFCmpULT(LoadF(B), LoadF(C));
else
result = cc.CreateFCmpUGE(LoadF(B), LoadF(C));
else
result = cc.CreateFCmpULT(LoadF(B), LoadF(C));

return result;
});
Expand All @@ -903,9 +903,9 @@ void JitCompiler::EmitLTF_RK()

IRValue* result;
if (check)
result = cc.CreateFCmpULT(LoadF(B), ConstF(C));
else
result = cc.CreateFCmpUGE(LoadF(B), ConstF(C));
else
result = cc.CreateFCmpULT(LoadF(B), ConstF(C));

return result;
});
Expand All @@ -918,9 +918,9 @@ void JitCompiler::EmitLTF_KR()

IRValue* result;
if (check)
result = cc.CreateFCmpULT(ConstF(B), LoadF(C));
else
result = cc.CreateFCmpUGE(ConstF(B), LoadF(C));
else
result = cc.CreateFCmpULT(ConstF(B), LoadF(C));

return result;
});
Expand All @@ -933,9 +933,9 @@ void JitCompiler::EmitLEF_RR()

IRValue* result;
if (check)
result = cc.CreateFCmpULE(LoadF(B), LoadF(C));
else
result = cc.CreateFCmpUGT(LoadF(B), LoadF(C));
else
result = cc.CreateFCmpULE(LoadF(B), LoadF(C));

return result;
});
Expand All @@ -948,9 +948,9 @@ void JitCompiler::EmitLEF_RK()

IRValue* result;
if (check)
result = cc.CreateFCmpULE(LoadF(B), ConstF(C));
else
result = cc.CreateFCmpUGT(LoadF(B), ConstF(C));
else
result = cc.CreateFCmpULE(LoadF(B), ConstF(C));

return result;
});
Expand All @@ -963,9 +963,9 @@ void JitCompiler::EmitLEF_KR()

IRValue* result;
if (check)
result = cc.CreateFCmpULE(ConstF(B), LoadF(C));
else
result = cc.CreateFCmpUGT(ConstF(B), LoadF(C));
else
result = cc.CreateFCmpULE(ConstF(B), LoadF(C));

return result;
});
Expand Down Expand Up @@ -1328,8 +1328,8 @@ void JitCompiler::EmitEQA_R()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpEQ(LoadA(B), LoadA(C));
else result = cc.CreateICmpNE(LoadA(B), LoadA(C));
if (check) result = cc.CreateICmpNE(LoadA(B), LoadA(C));
else result = cc.CreateICmpEQ(LoadA(B), LoadA(C));
return result;
});
}
Expand All @@ -1338,8 +1338,8 @@ void JitCompiler::EmitEQA_K()
{
EmitComparisonOpcode([&](bool check) {
IRValue* result;
if (check) result = cc.CreateICmpEQ(LoadA(B), ConstA(C));
else result = cc.CreateICmpNE(LoadA(B), ConstA(C));
if (check) result = cc.CreateICmpNE(LoadA(B), ConstA(C));
else result = cc.CreateICmpEQ(LoadA(B), ConstA(C));
return result;
});
}
Expand All @@ -1354,21 +1354,21 @@ IRValue* JitCompiler::EmitVectorComparison(int N, bool check)
if (!approx)
{
if (check)
elementresult = cc.CreateFCmpUEQ(LoadF(B + i), LoadF(C + i));
else
elementresult = cc.CreateFCmpUNE(LoadF(B + i), LoadF(C + i));
else
elementresult = cc.CreateFCmpUEQ(LoadF(B + i), LoadF(C + i));
}
else
{
IRValue* diff = cc.CreateFSub(LoadF(C + i), LoadF(B + i));
if (check)
elementresult = cc.CreateAnd(
cc.CreateFCmpUGT(diff, ConstValueF(-VM_EPSILON)),
cc.CreateFCmpULT(diff, ConstValueF(VM_EPSILON)));
else
elementresult = cc.CreateOr(
cc.CreateFCmpULE(diff, ConstValueF(-VM_EPSILON)),
cc.CreateFCmpUGE(diff, ConstValueF(VM_EPSILON)));
else
elementresult = cc.CreateAnd(
cc.CreateFCmpUGT(diff, ConstValueF(-VM_EPSILON)),
cc.CreateFCmpULT(diff, ConstValueF(VM_EPSILON)));
}

if (i == 0)
Expand Down
Loading

0 comments on commit 5c873ee

Please sign in to comment.