mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 21:11:39 +00:00
- clean up assembly output slightly by only generating labels for the opcodes jumped to
This commit is contained in:
parent
c099b2d3c8
commit
44294a051a
3 changed files with 45 additions and 11 deletions
|
@ -148,13 +148,15 @@ void JitCompiler::Codegen()
|
|||
cc.comment("", 0);
|
||||
cc.comment(lineinfo.GetChars(), lineinfo.Len());
|
||||
|
||||
cc.bind(labels[i]);
|
||||
labels[i].cursor = cc.getCursor();
|
||||
ResetTemp();
|
||||
EmitOpcode();
|
||||
|
||||
pc++;
|
||||
}
|
||||
|
||||
BindLabels();
|
||||
|
||||
cc.endFunc();
|
||||
cc.finalize();
|
||||
}
|
||||
|
@ -173,6 +175,22 @@ void JitCompiler::EmitOpcode()
|
|||
}
|
||||
}
|
||||
|
||||
void JitCompiler::BindLabels()
|
||||
{
|
||||
asmjit::CBNode *cursor = cc.getCursor();
|
||||
unsigned int size = labels.Size();
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
{
|
||||
const OpcodeLabel &label = labels[i];
|
||||
if (label.inUse)
|
||||
{
|
||||
cc.setCursor(label.cursor);
|
||||
cc.bind(label.label);
|
||||
}
|
||||
}
|
||||
cc.setCursor(cursor);
|
||||
}
|
||||
|
||||
void JitCompiler::Setup()
|
||||
{
|
||||
using namespace asmjit;
|
||||
|
@ -245,10 +263,7 @@ void JitCompiler::Setup()
|
|||
regA[i] = cc.newIntPtr(regname.GetChars());
|
||||
}
|
||||
|
||||
int size = sfunc->CodeSize;
|
||||
labels.Resize(size);
|
||||
for (int i = 0; i < size; i++)
|
||||
labels[i] = cc.newLabel();
|
||||
labels.Resize(sfunc->CodeSize);
|
||||
|
||||
// VMCalls[0]++
|
||||
auto vmcallsptr = newTempIntPtr();
|
||||
|
|
|
@ -5,7 +5,7 @@ void JitCompiler::EmitTEST()
|
|||
{
|
||||
int i = (int)(ptrdiff_t)(pc - sfunc->Code);
|
||||
cc.cmp(regD[A], BC);
|
||||
cc.jne(labels[i + 2]);
|
||||
cc.jne(GetLabel(i + 2));
|
||||
}
|
||||
|
||||
void JitCompiler::EmitTESTN()
|
||||
|
@ -13,14 +13,14 @@ void JitCompiler::EmitTESTN()
|
|||
int bc = BC;
|
||||
int i = (int)(ptrdiff_t)(pc - sfunc->Code);
|
||||
cc.cmp(regD[A], -bc);
|
||||
cc.jne(labels[i + 2]);
|
||||
cc.jne(GetLabel(i + 2));
|
||||
}
|
||||
|
||||
void JitCompiler::EmitJMP()
|
||||
{
|
||||
auto dest = pc + JMPOFS(pc) + 1;
|
||||
int i = (int)(ptrdiff_t)(dest - sfunc->Code);
|
||||
cc.jmp(labels[i]);
|
||||
cc.jmp(GetLabel(i));
|
||||
}
|
||||
|
||||
void JitCompiler::EmitIJMP()
|
||||
|
@ -40,7 +40,7 @@ void JitCompiler::EmitIJMP()
|
|||
int target = i + JMPOFS(&sfunc->Code[i]) + 1;
|
||||
|
||||
cc.cmp(val, i);
|
||||
cc.je(labels[target]);
|
||||
cc.je(GetLabel(target));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ private:
|
|||
#undef xx
|
||||
|
||||
void Setup();
|
||||
void BindLabels();
|
||||
void EmitOpcode();
|
||||
void EmitPopFrame();
|
||||
|
||||
|
@ -63,7 +64,7 @@ private:
|
|||
|
||||
auto successLabel = cc.newLabel();
|
||||
|
||||
auto failLabel = labels[i + 2 + JMPOFS(pc + 1)];
|
||||
auto failLabel = GetLabel(i + 2 + JMPOFS(pc + 1));
|
||||
|
||||
jmpFunc(static_cast<bool>(A & CMP_CHECK), failLabel, successLabel);
|
||||
|
||||
|
@ -172,7 +173,25 @@ private:
|
|||
TArray<asmjit::X86Gp> regA;
|
||||
TArray<asmjit::X86Gp> regS;
|
||||
|
||||
TArray<asmjit::Label> labels;
|
||||
struct OpcodeLabel
|
||||
{
|
||||
asmjit::CBNode *cursor = nullptr;
|
||||
asmjit::Label label;
|
||||
bool inUse = false;
|
||||
};
|
||||
|
||||
asmjit::Label GetLabel(size_t pos)
|
||||
{
|
||||
auto &label = labels[pos];
|
||||
if (!label.inUse)
|
||||
{
|
||||
label.label = cc.newLabel();
|
||||
label.inUse = true;
|
||||
}
|
||||
return label.label;
|
||||
}
|
||||
|
||||
TArray<OpcodeLabel> labels;
|
||||
|
||||
const VMOP *pc;
|
||||
VM_UBYTE op;
|
||||
|
|
Loading…
Reference in a new issue