From ea26bf6b2f1b76f8183a28911adeeddef3876bee Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 17 Nov 2018 00:04:15 +0100 Subject: [PATCH] - make functions using too many registers (more than 200) fall back to the VM --- src/scripting/vm/vmframe.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scripting/vm/vmframe.cpp b/src/scripting/vm/vmframe.cpp index 8d3649490..5f4e1f6a4 100644 --- a/src/scripting/vm/vmframe.cpp +++ b/src/scripting/vm/vmframe.cpp @@ -221,10 +221,17 @@ int VMScriptFunction::PCToLine(const VMOP *pc) return -1; } +static bool CanJit(VMScriptFunction *func) +{ + // Asmjit has a 256 register limit. Stay safely away from it as the jit compiler uses a few for temporaries as well. + // Any function exceeding the limit will use the VM - a fair punishment to someone for writing a function so bloated ;) + return func->NumRegA + func->NumRegD + func->NumRegF + func->NumRegS < 200; +} + int VMScriptFunction::FirstScriptCall(VMFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret) { #ifdef ARCH_X64 - if (vm_jit) + if (vm_jit && CanJit(static_cast(func))) { func->ScriptCall = JitCompile(static_cast(func)); if (!func->ScriptCall)