- some jump fixes

This commit is contained in:
Magnus Norddahl 2018-09-09 22:03:57 +02:00
parent b40cbfb22e
commit 19442732d4

View file

@ -37,10 +37,11 @@ public:
Setup(); Setup();
int size = sfunc->CodeSize; pc = sfunc->Code;
for (int i = 0; i < size; i++) auto end = pc + sfunc->CodeSize;
while (pc != end)
{ {
pc = sfunc->Code + i; int i = (int)(ptrdiff_t)(pc - sfunc->Code);
op = pc->op; op = pc->op;
cc.bind(labels[i]); cc.bind(labels[i]);
@ -53,6 +54,8 @@ public:
if (!opcodeFunc) if (!opcodeFunc)
I_FatalError("JIT error: Unknown VM opcode %d\n", op); I_FatalError("JIT error: Unknown VM opcode %d\n", op);
(this->*opcodeFunc)(); (this->*opcodeFunc)();
pc++;
} }
cc.endFunc(); cc.endFunc();
@ -956,7 +959,7 @@ private:
{ {
int i = (int)(ptrdiff_t)(pc - sfunc->Code); int i = (int)(ptrdiff_t)(pc - sfunc->Code);
cc.cmp(regD[A], BC); cc.cmp(regD[A], BC);
cc.jne(labels[i + 1]); cc.jne(labels[i + 2]);
} }
void EmitTESTN() void EmitTESTN()
@ -964,7 +967,7 @@ private:
int bc = BC; int bc = BC;
int i = (int)(ptrdiff_t)(pc - sfunc->Code); int i = (int)(ptrdiff_t)(pc - sfunc->Code);
cc.cmp(regD[A], -bc); cc.cmp(regD[A], -bc);
cc.jne(labels[i + 1]); cc.jne(labels[i + 2]);
} }
void EmitJMP() void EmitJMP()
@ -2728,7 +2731,7 @@ private:
using namespace asmjit; using namespace asmjit;
FString funcname; FString funcname;
funcname.Format("Function: %1", sfunc->PrintableName.GetChars()); funcname.Format("Function: %s", sfunc->PrintableName.GetChars());
cc.comment(funcname.GetChars(), funcname.Len()); cc.comment(funcname.GetChars(), funcname.Len());
stack = cc.newIntPtr("stack"); // VMFrameStack *stack stack = cc.newIntPtr("stack"); // VMFrameStack *stack
@ -2820,8 +2823,8 @@ private:
auto jmplabel = labels[i + 2 + JMPOFS(pc + 1)]; auto jmplabel = labels[i + 2 + JMPOFS(pc + 1)];
cc.test(tmp, tmp); cc.test(tmp, tmp);
if (check) cc.je(jmplabel); if (check) cc.jne(jmplabel);
else cc.jne(jmplabel); else cc.je(jmplabel);
pc++; // This instruction uses two instruction slots - skip the next one pc++; // This instruction uses two instruction slots - skip the next one
} }
@ -3046,18 +3049,20 @@ static void OutputJitLog(const asmjit::StringLogger &logger)
Printf("%s\n", pos); Printf("%s\n", pos);
} }
//#define DEBUG_JIT #define DEBUG_JIT
JitFuncPtr JitCompile(VMScriptFunction *sfunc) JitFuncPtr JitCompile(VMScriptFunction *sfunc)
{ {
#if defined(DEBUG_JIT) #if defined(DEBUG_JIT)
if (strcmp(sfunc->Name.GetChars(), "EmptyFunction") != 0) if (strcmp(sfunc->Name.GetChars(), "CanPickup") != 0)
return nullptr; return nullptr;
#else #else
if (!JitCompiler::CanJit(sfunc)) if (!JitCompiler::CanJit(sfunc))
return nullptr; return nullptr;
#endif #endif
Printf("Jitting function: %s\n", sfunc->PrintableName.GetChars());
using namespace asmjit; using namespace asmjit;
StringLogger logger; StringLogger logger;
try try