From 03001991f1973f5eed85805de6c17a23ae85c3d2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 17 Nov 2018 13:39:14 +0100 Subject: [PATCH] - fixed IJMP code generation for the JIT compiler. With a proper count value available this can be done properly. The only relevant targets are the jumps immediately succeeding the IJMP instructions, nothing else. --- src/scripting/vm/jit_flow.cpp | 13 +++++-------- src/scripting/vm/vmexec.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/scripting/vm/jit_flow.cpp b/src/scripting/vm/jit_flow.cpp index 1a31b5d02..8c89e36da 100644 --- a/src/scripting/vm/jit_flow.cpp +++ b/src/scripting/vm/jit_flow.cpp @@ -25,24 +25,21 @@ void JitCompiler::EmitJMP() void JitCompiler::EmitIJMP() { - // This uses the whole function as potential jump targets. Can the range be reduced? - - int i = (int)(ptrdiff_t)(pc - sfunc->Code); + int base = (int)(ptrdiff_t)(pc - sfunc->Code) + 1; auto val = newTempInt32(); cc.mov(val, regD[A]); - cc.add(val, i + (int)BCs + 1); - int size = sfunc->CodeSize; - for (i = 0; i < size; i++) + for (int i = 0; i < (int)BCs; i++) { - if (sfunc->Code[i].op == OP_JMP) + if (sfunc->Code[base +i].op == OP_JMP) { - int target = i + JMPOFS(&sfunc->Code[i]) + 1; + int target = base + i + JMPOFS(&sfunc->Code[base + i]) + 1; cc.cmp(val, i); cc.je(GetLabel(target)); } } + pc += BCs; // This should never happen. It means we are jumping to something that is not a JMP instruction! EmitThrowException(X_OTHER); diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index 1e8e0c5c3..e7735c5cb 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -554,7 +554,7 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret) NEXTOP; OP(IJMP): ASSERTD(a); - pc += (BCs + reg.d[a]); + pc += (reg.d[a]); assert(pc[1].op == OP_JMP); pc += 1 + JMPOFS(pc+1); NEXTOP;