Skip to content
Permalink
Browse files

- fix incorrect asmjit usage

  • Loading branch information...
dpjudas committed Aug 7, 2019
1 parent ef72e91 commit 9cda722a87b344a1c342b4953bf596cb4d0b4a9c
@@ -17,6 +17,13 @@ JitFuncPtr JitCompile(VMScriptFunction *sfunc)

using namespace asmjit;
StringLogger logger;

// Keep annotations to make it easier to process the debug log in case of error.
logger.setFlags(
FormatOptions::kFlagDebugRA |
FormatOptions::kFlagRegCasts |
FormatOptions::kFlagAnnotations);

try
{
ThrowingErrorHandler errorHandler;
@@ -37,14 +37,14 @@ void JitCompiler::EmitLK_R()
{
auto base = newTempIntPtr();
cc.mov(base, asmjit::imm(konstd + C));
cc.mov(regD[A], asmjit::x86::ptr(base, regD[B], 2));
cc.mov(regD[A], asmjit::x86::ptr(base, regD[B].cloneAs(base), 2));
}

void JitCompiler::EmitLKF_R()
{
auto base = newTempIntPtr();
cc.mov(base, asmjit::imm(konstf + C));
cc.movsd(regF[A], asmjit::x86::qword_ptr(base, regD[B], 3));
cc.movsd(regF[A], asmjit::x86::qword_ptr(base, regD[B].cloneAs(base), 3));
}

void JitCompiler::EmitLKS_R()
@@ -53,9 +53,9 @@ void JitCompiler::EmitLKS_R()
cc.mov(base, asmjit::imm(konsts + C));
auto ptr = newTempIntPtr();
if (cc.is64Bit())
cc.lea(ptr, asmjit::x86::ptr(base, regD[B], 3));
cc.lea(ptr, asmjit::x86::ptr(base, regD[B].cloneAs(base), 3));
else
cc.lea(ptr, asmjit::x86::ptr(base, regD[B], 2));
cc.lea(ptr, asmjit::x86::ptr(base, regD[B].cloneAs(base), 2));
auto call = CreateCall<void, FString*, FString*>(&JitCompiler::CallAssignString);
call->setArg(0, regS[A]);
call->setArg(1, ptr);
@@ -66,9 +66,9 @@ void JitCompiler::EmitLKP_R()
auto base = newTempIntPtr();
cc.mov(base, asmjit::imm(konsta + C));
if (cc.is64Bit())
cc.mov(regA[A], asmjit::x86::ptr(base, regD[B], 3));
cc.mov(regA[A], asmjit::x86::ptr(base, regD[B].cloneAs(base), 3));
else
cc.mov(regA[A], asmjit::x86::ptr(base, regD[B], 2));
cc.mov(regA[A], asmjit::x86::ptr(base, regD[B].cloneAs(base), 2));
}

void JitCompiler::EmitLFP()
@@ -107,7 +107,7 @@ void JitCompiler::EmitLB()
void JitCompiler::EmitLB_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.movsx(regD[A], asmjit::x86::byte_ptr(regA[B], regD[C]));
cc.movsx(regD[A], asmjit::x86::byte_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLH()
@@ -119,7 +119,7 @@ void JitCompiler::EmitLH()
void JitCompiler::EmitLH_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.movsx(regD[A], asmjit::x86::word_ptr(regA[B], regD[C]));
cc.movsx(regD[A], asmjit::x86::word_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLW()
@@ -131,7 +131,7 @@ void JitCompiler::EmitLW()
void JitCompiler::EmitLW_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.mov(regD[A], asmjit::x86::dword_ptr(regA[B], regD[C]));
cc.mov(regD[A], asmjit::x86::dword_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLBU()
@@ -143,19 +143,19 @@ void JitCompiler::EmitLBU()
void JitCompiler::EmitLBU_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.movzx(regD[A].r8Lo(), asmjit::x86::byte_ptr(regA[B], regD[C]));
cc.movzx(regD[A], asmjit::x86::byte_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLHU()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.movzx(regD[A].r16(), asmjit::x86::word_ptr(regA[B], konstd[C]));
cc.movzx(regD[A], asmjit::x86::word_ptr(regA[B], konstd[C]));
}

void JitCompiler::EmitLHU_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.movzx(regD[A].r16(), asmjit::x86::word_ptr(regA[B], regD[C]));
cc.movzx(regD[A], asmjit::x86::word_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLSP()
@@ -169,7 +169,7 @@ void JitCompiler::EmitLSP_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.xorpd(regF[A], regF[A]);
cc.cvtss2sd(regF[A], asmjit::x86::dword_ptr(regA[B], regD[C]));
cc.cvtss2sd(regF[A], asmjit::x86::dword_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLDP()
@@ -181,7 +181,7 @@ void JitCompiler::EmitLDP()
void JitCompiler::EmitLDP_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.movsd(regF[A], asmjit::x86::qword_ptr(regA[B], regD[C]));
cc.movsd(regF[A], asmjit::x86::qword_ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLS()
@@ -198,7 +198,7 @@ void JitCompiler::EmitLS_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
auto ptr = newTempIntPtr();
cc.lea(ptr, asmjit::x86::ptr(regA[B], regD[C]));
cc.lea(ptr, asmjit::x86::ptr(regA[B], regD[C].cloneAs(regA[B])));
auto call = CreateCall<void, FString*, FString*>(&JitCompiler::CallAssignString);
call->setArg(0, regS[A]);
call->setArg(1, ptr);
@@ -234,7 +234,7 @@ void JitCompiler::EmitLO_R()
{
EmitNullPointerThrow(B, X_READ_NIL);

cc.mov(regA[A], asmjit::x86::ptr(regA[B], regD[C]));
cc.mov(regA[A], asmjit::x86::ptr(regA[B], regD[C].cloneAs(regA[B])));
EmitReadBarrier();
}

@@ -264,7 +264,7 @@ void JitCompiler::EmitLO_R()
EmitNullPointerThrow(B, X_READ_NIL);
auto ptr = newTempIntPtr();
cc.mov(ptr, asmjit::x86::ptr(regA[B], regD[C]));
cc.mov(ptr, asmjit::x86::ptr(regA[B], regD[C].cloneAs(regA[B])));
auto result = newResultIntPtr();
auto call = CreateCall<DObject*, DObject*>(ReadBarrier);
@@ -284,7 +284,7 @@ void JitCompiler::EmitLP()
void JitCompiler::EmitLP_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.mov(regA[A], asmjit::x86::ptr(regA[B], regD[C]));
cc.mov(regA[A], asmjit::x86::ptr(regA[B], regD[C].cloneAs(regA[B])));
}

void JitCompiler::EmitLV2()
@@ -300,7 +300,7 @@ void JitCompiler::EmitLV2_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
auto tmp = newTempIntPtr();
cc.lea(tmp, asmjit::x86::qword_ptr(regA[B], regD[C]));
cc.lea(tmp, asmjit::x86::qword_ptr(regA[B], regD[C].cloneAs(regA[B])));
cc.movsd(regF[A], asmjit::x86::qword_ptr(tmp));
cc.movsd(regF[A + 1], asmjit::x86::qword_ptr(tmp, 8));
}
@@ -319,7 +319,7 @@ void JitCompiler::EmitLV3_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
auto tmp = newTempIntPtr();
cc.lea(tmp, asmjit::x86::qword_ptr(regA[B], regD[C]));
cc.lea(tmp, asmjit::x86::qword_ptr(regA[B], regD[C].cloneAs(regA[B])));
cc.movsd(regF[A], asmjit::x86::qword_ptr(tmp));
cc.movsd(regF[A + 1], asmjit::x86::qword_ptr(tmp, 8));
cc.movsd(regF[A + 2], asmjit::x86::qword_ptr(tmp, 16));
@@ -344,7 +344,7 @@ void JitCompiler::EmitLCS_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
auto ptr = newTempIntPtr();
cc.lea(ptr, asmjit::x86::ptr(regA[B], regD[C]));
cc.lea(ptr, asmjit::x86::ptr(regA[B], regD[C].cloneAs(regA[B])));
auto call = CreateCall<void, FString*, char**>(SetString);
call->setArg(0, regS[A]);
call->setArg(1, ptr);
@@ -356,5 +356,5 @@ void JitCompiler::EmitLBIT()
cc.movsx(regD[A], asmjit::x86::byte_ptr(regA[B]));
cc.and_(regD[A], C);
cc.cmp(regD[A], 0);
cc.setne(regD[A]);
cc.setne(regD[A].r8());
}
@@ -84,7 +84,7 @@ void JitCompiler::EmitSLL_RR()
auto rc = CheckRegD(C, A);
if (A != B)
cc.mov(regD[A], regD[B]);
cc.shl(regD[A], rc);
cc.shl(regD[A], rc.r8());
}

void JitCompiler::EmitSLL_RI()
@@ -98,15 +98,15 @@ void JitCompiler::EmitSLL_KR()
{
auto rc = CheckRegD(C, A);
cc.mov(regD[A], konstd[B]);
cc.shl(regD[A], rc);
cc.shl(regD[A], rc.r8());
}

void JitCompiler::EmitSRL_RR()
{
auto rc = CheckRegD(C, A);
if (A != B)
cc.mov(regD[A], regD[B]);
cc.shr(regD[A], rc);
cc.shr(regD[A], rc.r8());
}

void JitCompiler::EmitSRL_RI()
@@ -120,15 +120,15 @@ void JitCompiler::EmitSRL_KR()
{
auto rc = CheckRegD(C, A);
cc.mov(regD[A], konstd[B]);
cc.shr(regD[A], rc);
cc.shr(regD[A], rc.r8());
}

void JitCompiler::EmitSRA_RR()
{
auto rc = CheckRegD(C, A);
if (A != B)
cc.mov(regD[A], regD[B]);
cc.sar(regD[A], rc);
cc.sar(regD[A], rc.r8());
}

void JitCompiler::EmitSRA_RI()
@@ -142,7 +142,7 @@ void JitCompiler::EmitSRA_KR()
{
auto rc = CheckRegD(C, A);
cc.mov(regD[A], konstd[B]);
cc.sar(regD[A], rc);
cc.sar(regD[A], rc.r8());
}

void JitCompiler::EmitADD_RR()
@@ -1461,7 +1461,7 @@ void JitCompiler::EmitADDA_RR()
cc.je(label);

auto tmpptr = newTempIntPtr();
cc.mov(tmpptr, regD[C]);
cc.mov(tmpptr.r32(), regD[C]);
cc.add(tmp, tmpptr);

cc.bind(label);
@@ -1488,8 +1488,9 @@ void JitCompiler::EmitADDA_RK()
void JitCompiler::EmitSUBA()
{
auto tmp = newTempIntPtr();
cc.mov(tmp, regA[B]);
cc.sub(tmp, regD[C]);
cc.mov(tmp.r32(), regD[C]);
cc.sub(tmp, regA[B]);
cc.neg(tmp);
cc.mov(regA[A], tmp);
}

@@ -185,7 +185,7 @@ void JitCompiler::EmitCASTB()
if (C == CASTB_I)
{
cc.cmp(regD[B], (int)0);
cc.setne(regD[A]);
cc.setne(regD[A].r8());
cc.movzx(regD[A], regD[A].r8Lo()); // not sure if this is needed
}
else if (C == CASTB_F)
@@ -196,13 +196,13 @@ void JitCompiler::EmitCASTB()
cc.mov(one, 1);
cc.xor_(regD[A], regD[A]);
cc.ucomisd(regF[B], zero);
cc.setp(regD[A]);
cc.setp(regD[A].r8());
cc.cmovne(regD[A], one);
}
else if (C == CASTB_A)
{
cc.test(regA[B], regA[B]);
cc.setne(regD[A]);
cc.setne(regD[A].r8());
cc.movzx(regD[A], regD[A].r8Lo()); // not sure if this is needed
}
else
@@ -403,7 +403,7 @@ static void WriteCIE(TArray<uint8_t> &stream, const TArray<uint8_t> &cieInstruct
unsigned int lengthPos = stream.Size();
WriteUInt32(stream, 0); // Length
WriteUInt32(stream, 0); // CIE ID

WriteUInt8(stream, 1); // CIE Version
WriteUInt8(stream, 'z');
WriteUInt8(stream, 'R'); // fde encoding
@@ -428,7 +428,7 @@ static void WriteFDE(TArray<uint8_t> &stream, const TArray<uint8_t> &fdeInstruct
WriteUInt32(stream, 0); // Length
uint32_t offsetToCIE = stream.Size() - cieLocation;
WriteUInt32(stream, offsetToCIE);

functionStart = stream.Size();
WriteUInt64(stream, 0); // func start
WriteUInt64(stream, 0); // func size
@@ -499,7 +499,7 @@ static TArray<uint8_t> CreateUnwindInfoUnix(asmjit::FuncNode *func, unsigned int
//
// The CFI_Parser<A>::decodeFDE parser on the other side..
// https://github.com/llvm-mirror/libunwind/blob/master/src/DwarfParser.hpp

// Asmjit -> DWARF register id
int dwarfRegId[16];
dwarfRegId[x86::Gp::kIdAx] = 0;
@@ -520,7 +520,7 @@ static TArray<uint8_t> CreateUnwindInfoUnix(asmjit::FuncNode *func, unsigned int
dwarfRegId[x86::Gp::kIdR15] = 15;
int dwarfRegRAId = 16;
int dwarfRegXmmId = 17;

TArray<uint8_t> cieInstructions;
TArray<uint8_t> fdeInstructions;

@@ -704,7 +704,7 @@ void *AddJitFunction(asmjit::CodeHolder* code, JitCompiler *compiler)
uint64_t length64 = *((uint64_t *)(entry + 4));
if (length64 == 0)
break;

uint64_t offset = *((uint64_t *)(entry + 12));
if (offset != 0)
{
@@ -133,8 +133,8 @@ void JitCompiler::EmitSV2_R()
{
EmitNullPointerThrow(A, X_WRITE_NIL);
auto tmp = newTempIntPtr();
cc.mov(tmp, regA[A]);
cc.add(tmp, regD[C]);
cc.mov(tmp.r32(), regD[C]);
cc.add(tmp, regA[A]);
cc.movsd(asmjit::x86::qword_ptr(tmp), regF[B]);
cc.movsd(asmjit::x86::qword_ptr(tmp, 8), regF[B + 1]);
}
@@ -154,8 +154,8 @@ void JitCompiler::EmitSV3_R()
{
EmitNullPointerThrow(A, X_WRITE_NIL);
auto tmp = newTempIntPtr();
cc.mov(tmp, regA[A]);
cc.add(tmp, regD[C]);
cc.mov(tmp.r32(), regD[C]);
cc.add(tmp, regA[A]);
cc.movsd(asmjit::x86::qword_ptr(tmp), regF[B]);
cc.movsd(asmjit::x86::qword_ptr(tmp, 8), regF[B + 1]);
cc.movsd(asmjit::x86::qword_ptr(tmp, 16), regF[B + 2]);
@@ -166,11 +166,11 @@ void JitCompiler::EmitSBIT()
EmitNullPointerThrow(A, X_WRITE_NIL);
auto tmp1 = newTempInt32();
auto tmp2 = newTempInt32();
cc.mov(tmp1, asmjit::x86::byte_ptr(regA[A]));
cc.movzx(tmp1, asmjit::x86::byte_ptr(regA[A]));
cc.mov(tmp2, tmp1);
cc.or_(tmp1, (int)C);
cc.and_(tmp2, ~(int)C);
cc.test(regD[B], regD[B]);
cc.cmove(tmp1, tmp2);
cc.mov(asmjit::x86::byte_ptr(regA[A]), tmp1);
cc.mov(asmjit::x86::byte_ptr(regA[A]), tmp1.r8());
}

0 comments on commit 9cda722

Please sign in to comment.
You can’t perform that action at this time.