emit_x64: Use JitStateInfo

This commit is contained in:
MerryMage 2018-01-23 18:47:10 +00:00
parent d4b05b28cf
commit 58c4a25527
5 changed files with 31 additions and 13 deletions

View file

@ -104,6 +104,8 @@ public:
bool DoesCpuSupport(Xbyak::util::Cpu::Type type) const; bool DoesCpuSupport(Xbyak::util::Cpu::Type type) const;
JitStateInfo GetJitStateInfo() const { return jsi; }
private: private:
RunCodeCallbacks cb; RunCodeCallbacks cb;
JitStateInfo jsi; JitStateInfo jsi;

View file

@ -72,19 +72,19 @@ void EmitX64<JST>::PushRSBHelper(Xbyak::Reg64 loc_desc_reg, Xbyak::Reg64 index_r
? iter->second.entrypoint ? iter->second.entrypoint
: code->GetReturnFromRunCodeAddress(); : code->GetReturnFromRunCodeAddress();
code->mov(index_reg.cvt32(), dword[r15 + offsetof(JST, rsb_ptr)]); code->mov(index_reg.cvt32(), dword[r15 + code->GetJitStateInfo().offsetof_rsb_ptr]);
code->mov(loc_desc_reg, target.Value()); code->mov(loc_desc_reg, target.Value());
patch_information[target].mov_rcx.emplace_back(code->getCurr()); patch_information[target].mov_rcx.emplace_back(code->getCurr());
EmitPatchMovRcx(target_code_ptr); EmitPatchMovRcx(target_code_ptr);
code->mov(qword[r15 + index_reg * 8 + offsetof(JST, rsb_location_descriptors)], loc_desc_reg); code->mov(qword[r15 + index_reg * 8 + code->GetJitStateInfo().offsetof_rsb_location_descriptors], loc_desc_reg);
code->mov(qword[r15 + index_reg * 8 + offsetof(JST, rsb_codeptrs)], rcx); code->mov(qword[r15 + index_reg * 8 + code->GetJitStateInfo().offsetof_rsb_codeptrs], rcx);
code->add(index_reg.cvt32(), 1); code->add(index_reg.cvt32(), 1);
code->and_(index_reg.cvt32(), u32(JST::RSBPtrMask)); code->and_(index_reg.cvt32(), u32(code->GetJitStateInfo().rsb_ptr_mask));
code->mov(dword[r15 + offsetof(JST, rsb_ptr)], index_reg.cvt32()); code->mov(dword[r15 + code->GetJitStateInfo().offsetof_rsb_ptr], index_reg.cvt32());
} }
template <typename JST> template <typename JST>
@ -146,7 +146,7 @@ void EmitX64<JST>::EmitGetNZCVFromOp(EmitContext& ctx, IR::Inst* inst) {
template <typename JST> template <typename JST>
void EmitX64<JST>::EmitAddCycles(size_t cycles) { void EmitX64<JST>::EmitAddCycles(size_t cycles) {
ASSERT(cycles < std::numeric_limits<u32>::max()); ASSERT(cycles < std::numeric_limits<u32>::max());
code->sub(qword[r15 + offsetof(JST, cycles_remaining)], static_cast<u32>(cycles)); code->sub(qword[r15 + code->GetJitStateInfo().offsetof_cycles_remaining], static_cast<u32>(cycles));
} }
template <typename JST> template <typename JST>
@ -154,7 +154,7 @@ Xbyak::Label EmitX64<JST>::EmitCond(IR::Cond cond) {
Xbyak::Label label; Xbyak::Label label;
const Xbyak::Reg32 cpsr = eax; const Xbyak::Reg32 cpsr = eax;
code->mov(cpsr, dword[r15 + offsetof(JST, CPSR_nzcv)]); code->mov(cpsr, dword[r15 + code->GetJitStateInfo().offsetof_CPSR_nzcv]);
constexpr size_t n_shift = 31; constexpr size_t n_shift = 31;
constexpr size_t z_shift = 30; constexpr size_t z_shift = 30;

View file

@ -115,7 +115,7 @@ static void EmitConditionalSelect(BlockOfCode* code, EmitContext& ctx, IR::Inst*
Xbyak::Reg then_ = ctx.reg_alloc.UseGpr(args[1]).changeBit(bitsize); Xbyak::Reg then_ = ctx.reg_alloc.UseGpr(args[1]).changeBit(bitsize);
Xbyak::Reg else_ = ctx.reg_alloc.UseScratchGpr(args[2]).changeBit(bitsize); Xbyak::Reg else_ = ctx.reg_alloc.UseScratchGpr(args[2]).changeBit(bitsize);
code->mov(nzcv, dword[r15 + offsetof(JST, CPSR_nzcv)]); code->mov(nzcv, dword[r15 + code->GetJitStateInfo().offsetof_CPSR_nzcv]);
// TODO: Flag optimization // TODO: Flag optimization
code->shr(nzcv, 28); code->shr(nzcv, 28);
code->imul(nzcv, nzcv, 0b00010000'10000001); code->imul(nzcv, nzcv, 0b00010000'10000001);

View file

@ -43,7 +43,7 @@ static void DenormalsAreZero32(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::R
code->cmp(gpr_scratch, u32(0x007FFFFE)); code->cmp(gpr_scratch, u32(0x007FFFFE));
code->ja(end); code->ja(end);
code->pxor(xmm_value, xmm_value); code->pxor(xmm_value, xmm_value);
code->mov(dword[r15 + offsetof(JST, FPSCR_IDC)], u32(1 << 7)); code->mov(dword[r15 + code->GetJitStateInfo().offsetof_FPSCR_IDC], u32(1 << 7));
code->L(end); code->L(end);
} }
@ -62,7 +62,7 @@ static void DenormalsAreZero64(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::R
code->cmp(gpr_scratch, penult_denormal); code->cmp(gpr_scratch, penult_denormal);
code->ja(end); code->ja(end);
code->pxor(xmm_value, xmm_value); code->pxor(xmm_value, xmm_value);
code->mov(dword[r15 + offsetof(JST, FPSCR_IDC)], u32(1 << 7)); code->mov(dword[r15 + code->GetJitStateInfo().offsetof_FPSCR_IDC], u32(1 << 7));
code->L(end); code->L(end);
} }
@ -76,7 +76,7 @@ static void FlushToZero32(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::Reg32
code->cmp(gpr_scratch, u32(0x007FFFFE)); code->cmp(gpr_scratch, u32(0x007FFFFE));
code->ja(end); code->ja(end);
code->pxor(xmm_value, xmm_value); code->pxor(xmm_value, xmm_value);
code->mov(dword[r15 + offsetof(JST, FPSCR_UFC)], u32(1 << 3)); code->mov(dword[r15 + code->GetJitStateInfo().offsetof_FPSCR_UFC], u32(1 << 3));
code->L(end); code->L(end);
} }
@ -95,7 +95,7 @@ static void FlushToZero64(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::Reg64
code->cmp(gpr_scratch, penult_denormal); code->cmp(gpr_scratch, penult_denormal);
code->ja(end); code->ja(end);
code->pxor(xmm_value, xmm_value); code->pxor(xmm_value, xmm_value);
code->mov(dword[r15 + offsetof(JST, FPSCR_UFC)], u32(1 << 3)); code->mov(dword[r15 + code->GetJitStateInfo().offsetof_FPSCR_UFC], u32(1 << 3));
code->L(end); code->L(end);
} }
@ -313,7 +313,7 @@ static void SetFpscrNzcvFromFlags(BlockOfCode* code, EmitContext& ctx) {
code->rcl(cl, 3); code->rcl(cl, 3);
code->shl(nzcv, cl); code->shl(nzcv, cl);
code->and_(nzcv, 0xF0000000); code->and_(nzcv, 0xF0000000);
code->mov(dword[r15 + offsetof(JST, FPSCR_nzcv)], nzcv); code->mov(dword[r15 + code->GetJitStateInfo().offsetof_FPSCR_nzcv], nzcv);
} }
template <typename JST> template <typename JST>

View file

@ -20,12 +20,28 @@ struct JitStateInfo {
, offsetof_cycles_to_run(offsetof(JitStateType, cycles_to_run)) , offsetof_cycles_to_run(offsetof(JitStateType, cycles_to_run))
, offsetof_save_host_MXCSR(offsetof(JitStateType, save_host_MXCSR)) , offsetof_save_host_MXCSR(offsetof(JitStateType, save_host_MXCSR))
, offsetof_guest_MXCSR(offsetof(JitStateType, guest_MXCSR)) , offsetof_guest_MXCSR(offsetof(JitStateType, guest_MXCSR))
, offsetof_rsb_ptr(offsetof(JitStateType, rsb_ptr))
, rsb_ptr_mask(JitStateType::RSBPtrMask)
, offsetof_rsb_location_descriptors(offsetof(JitStateType, rsb_location_descriptors))
, offsetof_rsb_codeptrs(offsetof(JitStateType, rsb_codeptrs))
, offsetof_CPSR_nzcv(offsetof(JitStateType, CPSR_nzcv))
, offsetof_FPSCR_nzcv(offsetof(JitStateType, FPSCR_nzcv))
, offsetof_FPSCR_IDC(offsetof(JitStateType, FPSCR_IDC))
, offsetof_FPSCR_UFC(offsetof(JitStateType, FPSCR_UFC))
{} {}
const size_t offsetof_cycles_remaining; const size_t offsetof_cycles_remaining;
const size_t offsetof_cycles_to_run; const size_t offsetof_cycles_to_run;
const size_t offsetof_save_host_MXCSR; const size_t offsetof_save_host_MXCSR;
const size_t offsetof_guest_MXCSR; const size_t offsetof_guest_MXCSR;
const size_t offsetof_rsb_ptr;
const size_t rsb_ptr_mask;
const size_t offsetof_rsb_location_descriptors;
const size_t offsetof_rsb_codeptrs;
const size_t offsetof_CPSR_nzcv;
const size_t offsetof_FPSCR_nzcv;
const size_t offsetof_FPSCR_IDC;
const size_t offsetof_FPSCR_UFC;
}; };
} // namespace BackendX64 } // namespace BackendX64