mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-25 05:21:02 +00:00
- allocate VMFrame on the stack for simple functions with no strings
This commit is contained in:
parent
bee3a964ae
commit
f0d9b49099
1 changed files with 82 additions and 38 deletions
|
@ -189,32 +189,73 @@ void JitCompiler::Setup()
|
||||||
int offsetD = offsetA + (int)(sfunc->NumRegA * sizeof(void*));
|
int offsetD = offsetA + (int)(sfunc->NumRegA * sizeof(void*));
|
||||||
offsetExtra = (offsetD + (int)(sfunc->NumRegD * sizeof(int32_t)) + 15) & ~15;
|
offsetExtra = (offsetD + (int)(sfunc->NumRegD * sizeof(int32_t)) + 15) & ~15;
|
||||||
|
|
||||||
stack = cc.newIntPtr("stack");
|
vmframe = cc.newIntPtr("vmframe");
|
||||||
auto allocFrame = CreateCall<VMFrameStack *, VMScriptFunction *, VMValue *, int, JitExceptionInfo *>([](VMScriptFunction *func, VMValue *args, int numargs, JitExceptionInfo *exceptinfo) -> VMFrameStack* {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
VMFrameStack *stack = &GlobalVMStack;
|
|
||||||
VMFrame *newf = stack->AllocFrame(func);
|
|
||||||
VMFillParams(args, newf, numargs);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
exceptinfo->reason = X_OTHER;
|
|
||||||
exceptinfo->cppException = std::current_exception();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
allocFrame->setRet(0, stack);
|
|
||||||
allocFrame->setArg(0, imm_ptr(sfunc));
|
|
||||||
allocFrame->setArg(1, args);
|
|
||||||
allocFrame->setArg(2, numargs);
|
|
||||||
allocFrame->setArg(3, exceptInfo);
|
|
||||||
EmitCheckForException();
|
|
||||||
|
|
||||||
vmframe = cc.newIntPtr();
|
if (sfunc->SpecialInits.Size() == 0 && sfunc->NumRegS == 0)
|
||||||
cc.mov(vmframe, x86::ptr(stack)); // stack->Blocks
|
{
|
||||||
cc.mov(vmframe, x86::ptr(vmframe, VMFrameStack::OffsetLastFrame())); // Blocks->LastFrame
|
// This is a simple frame with no constructors or destructors. Allocate it on the stack ourselves.
|
||||||
|
|
||||||
|
//auto vmstack = cc.newStack(offsetExtra + sfunc->ExtraSpace, 16); // To do: fill in params without VMFillParams
|
||||||
|
auto vmstack = cc.newStack(sfunc->StackSize, 16);
|
||||||
|
cc.lea(vmframe, vmstack);
|
||||||
|
auto sfuncptr = cc.newIntPtr();
|
||||||
|
cc.mov(sfuncptr, imm_ptr(sfunc));
|
||||||
|
if (cc.is64Bit())
|
||||||
|
cc.mov(x86::qword_ptr(vmframe, offsetof(VMFrame, Func)), sfuncptr);
|
||||||
|
else
|
||||||
|
cc.mov(x86::dword_ptr(vmframe, offsetof(VMFrame, Func)), sfuncptr);
|
||||||
|
cc.mov(x86::byte_ptr(vmframe, offsetof(VMFrame, NumRegD)), sfunc->NumRegD);
|
||||||
|
cc.mov(x86::byte_ptr(vmframe, offsetof(VMFrame, NumRegF)), sfunc->NumRegF);
|
||||||
|
cc.mov(x86::byte_ptr(vmframe, offsetof(VMFrame, NumRegS)), sfunc->NumRegS);
|
||||||
|
cc.mov(x86::byte_ptr(vmframe, offsetof(VMFrame, NumRegA)), sfunc->NumRegA);
|
||||||
|
cc.mov(x86::word_ptr(vmframe, offsetof(VMFrame, MaxParam)), sfunc->MaxParam);
|
||||||
|
cc.mov(x86::word_ptr(vmframe, offsetof(VMFrame, NumParam)), 0);
|
||||||
|
|
||||||
|
auto fillParams = CreateCall<void, VMFrame *, VMValue *, int, JitExceptionInfo *>([](VMFrame *newf, VMValue *args, int numargs, JitExceptionInfo *exceptinfo) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
VMFillParams(args, newf, numargs);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
exceptinfo->reason = X_OTHER;
|
||||||
|
exceptinfo->cppException = std::current_exception();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fillParams->setArg(0, vmframe);
|
||||||
|
fillParams->setArg(1, args);
|
||||||
|
fillParams->setArg(2, numargs);
|
||||||
|
fillParams->setArg(3, exceptInfo);
|
||||||
|
EmitCheckForException();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stack = cc.newIntPtr("stack");
|
||||||
|
auto allocFrame = CreateCall<VMFrameStack *, VMScriptFunction *, VMValue *, int, JitExceptionInfo *>([](VMScriptFunction *func, VMValue *args, int numargs, JitExceptionInfo *exceptinfo) -> VMFrameStack* {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
VMFrameStack *stack = &GlobalVMStack;
|
||||||
|
VMFrame *newf = stack->AllocFrame(func);
|
||||||
|
VMFillParams(args, newf, numargs);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
exceptinfo->reason = X_OTHER;
|
||||||
|
exceptinfo->cppException = std::current_exception();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
allocFrame->setRet(0, stack);
|
||||||
|
allocFrame->setArg(0, imm_ptr(sfunc));
|
||||||
|
allocFrame->setArg(1, args);
|
||||||
|
allocFrame->setArg(2, numargs);
|
||||||
|
allocFrame->setArg(3, exceptInfo);
|
||||||
|
EmitCheckForException();
|
||||||
|
|
||||||
|
cc.mov(vmframe, x86::ptr(stack)); // stack->Blocks
|
||||||
|
cc.mov(vmframe, x86::ptr(vmframe, VMFrameStack::OffsetLastFrame())); // Blocks->LastFrame
|
||||||
|
}
|
||||||
|
|
||||||
cc.lea(params, x86::ptr(vmframe, offsetParams));
|
cc.lea(params, x86::ptr(vmframe, offsetParams));
|
||||||
cc.lea(frameF, x86::ptr(vmframe, offsetF));
|
cc.lea(frameF, x86::ptr(vmframe, offsetF));
|
||||||
|
@ -261,19 +302,22 @@ void JitCompiler::Setup()
|
||||||
|
|
||||||
void JitCompiler::EmitPopFrame()
|
void JitCompiler::EmitPopFrame()
|
||||||
{
|
{
|
||||||
auto popFrame = CreateCall<void, VMFrameStack *, JitExceptionInfo *>([](VMFrameStack *stack, JitExceptionInfo *exceptinfo) {
|
if (sfunc->SpecialInits.Size() != 0 || sfunc->NumRegS != 0)
|
||||||
try
|
{
|
||||||
{
|
auto popFrame = CreateCall<void, VMFrameStack *, JitExceptionInfo *>([](VMFrameStack *stack, JitExceptionInfo *exceptinfo) {
|
||||||
stack->PopFrame();
|
try
|
||||||
}
|
{
|
||||||
catch (...)
|
stack->PopFrame();
|
||||||
{
|
}
|
||||||
exceptinfo->reason = X_OTHER;
|
catch (...)
|
||||||
exceptinfo->cppException = std::current_exception();
|
{
|
||||||
}
|
exceptinfo->reason = X_OTHER;
|
||||||
});
|
exceptinfo->cppException = std::current_exception();
|
||||||
popFrame->setArg(0, stack);
|
}
|
||||||
popFrame->setArg(1, exceptInfo);
|
});
|
||||||
|
popFrame->setArg(0, stack);
|
||||||
|
popFrame->setArg(1, exceptInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JitCompiler::EmitNullPointerThrow(int index, EVMAbortException reason)
|
void JitCompiler::EmitNullPointerThrow(int index, EVMAbortException reason)
|
||||||
|
|
Loading…
Reference in a new issue