- inline ReadBarrier, GetClass and GetClassMeta

This commit is contained in:
Magnus Norddahl 2018-11-17 10:54:16 +01:00
parent 6398c27646
commit 68afc419af
3 changed files with 64 additions and 0 deletions

View file

@ -357,6 +357,7 @@ protected:
template<typename T, typename... Args> template<typename T, typename... Args>
friend T* Create(Args&&... args); friend T* Create(Args&&... args);
friend class JitCompiler;
}; };
// This is the only method aside from calling CreateNew that should be used for creating DObjects // This is the only method aside from calling CreateNew that should be used for creating DObjects

View file

@ -76,6 +76,28 @@ void JitCompiler::EmitLFP()
cc.lea(regA[A], asmjit::x86::ptr(vmframe, offsetExtra)); cc.lea(regA[A], asmjit::x86::ptr(vmframe, offsetExtra));
} }
#if 1 // Inline implementation
void JitCompiler::EmitMETA()
{
auto label = EmitThrowExceptionLabel(X_READ_NIL);
cc.test(regA[B], regA[B]);
cc.je(label);
cc.mov(regA[A], asmjit::x86::qword_ptr(regA[B], offsetof(DObject, Class)));
cc.mov(regA[A], asmjit::x86::qword_ptr(regA[A], offsetof(PClass, Meta)));
}
void JitCompiler::EmitCLSS()
{
auto label = EmitThrowExceptionLabel(X_READ_NIL);
cc.test(regA[B], regA[B]);
cc.je(label);
cc.mov(regA[A], asmjit::x86::qword_ptr(regA[B], offsetof(DObject, Class)));
}
#else
static uint8_t *GetClassMeta(DObject *o) static uint8_t *GetClassMeta(DObject *o)
{ {
return o->GetClass()->Meta; return o->GetClass()->Meta;
@ -112,6 +134,8 @@ void JitCompiler::EmitCLSS()
cc.mov(regA[A], result); cc.mov(regA[A], result);
} }
#endif
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Load from memory. rA = *(rB + rkC) // Load from memory. rA = *(rB + rkC)
@ -221,6 +245,41 @@ void JitCompiler::EmitLS_R()
call->setArg(1, ptr); call->setArg(1, ptr);
} }
#if 1 // Inline read barrier impl
void JitCompiler::EmitReadBarrier()
{
auto isnull = cc.newLabel();
cc.test(regA[A], regA[A]);
cc.je(isnull);
auto mask = newTempIntPtr();
cc.mov(mask.r32(), asmjit::x86::dword_ptr(regA[A], offsetof(DObject, ObjectFlags)));
cc.shl(mask, 63 - 5); // put OF_EuthanizeMe (1 << 5) in the highest bit
cc.sar(mask, 63); // sign extend so all bits are set if OF_EuthanizeMe was set
cc.andn(regA[A], mask, regA[A]);
cc.bind(isnull);
}
void JitCompiler::EmitLO()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.mov(regA[A], asmjit::x86::ptr(regA[B], konstd[C]));
EmitReadBarrier();
}
void JitCompiler::EmitLO_R()
{
EmitNullPointerThrow(B, X_READ_NIL);
cc.mov(regA[A], asmjit::x86::ptr(regA[B], regD[C]));
EmitReadBarrier();
}
#else
static DObject *ReadBarrier(DObject *p) static DObject *ReadBarrier(DObject *p)
{ {
return GC::ReadBarrier(p); return GC::ReadBarrier(p);
@ -254,6 +313,8 @@ void JitCompiler::EmitLO_R()
cc.mov(regA[A], result); cc.mov(regA[A], result);
} }
#endif
void JitCompiler::EmitLP() void JitCompiler::EmitLP()
{ {
EmitNullPointerThrow(B, X_READ_NIL); EmitNullPointerThrow(B, X_READ_NIL);

View file

@ -203,6 +203,8 @@ private:
asmjit::X86Gp newResultIntPtr() { return newTempRegister(regResultIntPtr, resultPosIntPtr, "resultPtr", [&](const char *name) { return cc.newIntPtr(name); }); } asmjit::X86Gp newResultIntPtr() { return newTempRegister(regResultIntPtr, resultPosIntPtr, "resultPtr", [&](const char *name) { return cc.newIntPtr(name); }); }
asmjit::X86Xmm newResultXmmSd() { return newTempRegister(regResultXmmSd, resultPosXmmSd, "resultXmmSd", [&](const char *name) { return cc.newXmmSd(name); }); } asmjit::X86Xmm newResultXmmSd() { return newTempRegister(regResultXmmSd, resultPosXmmSd, "resultXmmSd", [&](const char *name) { return cc.newXmmSd(name); }); }
void EmitReadBarrier();
void EmitNullPointerThrow(int index, EVMAbortException reason); void EmitNullPointerThrow(int index, EVMAbortException reason);
void EmitThrowException(EVMAbortException reason); void EmitThrowException(EVMAbortException reason);
asmjit::Label EmitThrowExceptionLabel(EVMAbortException reason); asmjit::Label EmitThrowExceptionLabel(EVMAbortException reason);