From 58c4a25527f1697bc5acefcfef8a96793eac5635 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 23 Jan 2018 18:47:10 +0000 Subject: [PATCH] emit_x64: Use JitStateInfo --- src/backend_x64/block_of_code.h | 2 ++ src/backend_x64/emit_x64.cpp | 14 +++++++------- src/backend_x64/emit_x64_data_processing.cpp | 2 +- src/backend_x64/emit_x64_floating_point.cpp | 10 +++++----- src/backend_x64/jitstate_info.h | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/backend_x64/block_of_code.h b/src/backend_x64/block_of_code.h index a7853ad7..f5a47c2a 100644 --- a/src/backend_x64/block_of_code.h +++ b/src/backend_x64/block_of_code.h @@ -104,6 +104,8 @@ public: bool DoesCpuSupport(Xbyak::util::Cpu::Type type) const; + JitStateInfo GetJitStateInfo() const { return jsi; } + private: RunCodeCallbacks cb; JitStateInfo jsi; diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp index c925a23b..1be47d9e 100644 --- a/src/backend_x64/emit_x64.cpp +++ b/src/backend_x64/emit_x64.cpp @@ -72,19 +72,19 @@ void EmitX64::PushRSBHelper(Xbyak::Reg64 loc_desc_reg, Xbyak::Reg64 index_r ? iter->second.entrypoint : 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()); patch_information[target].mov_rcx.emplace_back(code->getCurr()); 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 + offsetof(JST, rsb_codeptrs)], rcx); + code->mov(qword[r15 + index_reg * 8 + code->GetJitStateInfo().offsetof_rsb_location_descriptors], loc_desc_reg); + code->mov(qword[r15 + index_reg * 8 + code->GetJitStateInfo().offsetof_rsb_codeptrs], rcx); code->add(index_reg.cvt32(), 1); - code->and_(index_reg.cvt32(), u32(JST::RSBPtrMask)); - code->mov(dword[r15 + offsetof(JST, rsb_ptr)], index_reg.cvt32()); + code->and_(index_reg.cvt32(), u32(code->GetJitStateInfo().rsb_ptr_mask)); + code->mov(dword[r15 + code->GetJitStateInfo().offsetof_rsb_ptr], index_reg.cvt32()); } template @@ -146,7 +146,7 @@ void EmitX64::EmitGetNZCVFromOp(EmitContext& ctx, IR::Inst* inst) { template void EmitX64::EmitAddCycles(size_t cycles) { ASSERT(cycles < std::numeric_limits::max()); - code->sub(qword[r15 + offsetof(JST, cycles_remaining)], static_cast(cycles)); + code->sub(qword[r15 + code->GetJitStateInfo().offsetof_cycles_remaining], static_cast(cycles)); } template @@ -154,7 +154,7 @@ Xbyak::Label EmitX64::EmitCond(IR::Cond cond) { Xbyak::Label label; 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 z_shift = 30; diff --git a/src/backend_x64/emit_x64_data_processing.cpp b/src/backend_x64/emit_x64_data_processing.cpp index 57963971..ba1e7e6e 100644 --- a/src/backend_x64/emit_x64_data_processing.cpp +++ b/src/backend_x64/emit_x64_data_processing.cpp @@ -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 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 code->shr(nzcv, 28); code->imul(nzcv, nzcv, 0b00010000'10000001); diff --git a/src/backend_x64/emit_x64_floating_point.cpp b/src/backend_x64/emit_x64_floating_point.cpp index 25fe489f..eada0ff2 100644 --- a/src/backend_x64/emit_x64_floating_point.cpp +++ b/src/backend_x64/emit_x64_floating_point.cpp @@ -43,7 +43,7 @@ static void DenormalsAreZero32(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::R code->cmp(gpr_scratch, u32(0x007FFFFE)); code->ja(end); 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); } @@ -62,7 +62,7 @@ static void DenormalsAreZero64(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::R code->cmp(gpr_scratch, penult_denormal); code->ja(end); 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); } @@ -76,7 +76,7 @@ static void FlushToZero32(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::Reg32 code->cmp(gpr_scratch, u32(0x007FFFFE)); code->ja(end); 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); } @@ -95,7 +95,7 @@ static void FlushToZero64(BlockOfCode* code, Xbyak::Xmm xmm_value, Xbyak::Reg64 code->cmp(gpr_scratch, penult_denormal); code->ja(end); 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); } @@ -313,7 +313,7 @@ static void SetFpscrNzcvFromFlags(BlockOfCode* code, EmitContext& ctx) { code->rcl(cl, 3); code->shl(nzcv, cl); code->and_(nzcv, 0xF0000000); - code->mov(dword[r15 + offsetof(JST, FPSCR_nzcv)], nzcv); + code->mov(dword[r15 + code->GetJitStateInfo().offsetof_FPSCR_nzcv], nzcv); } template diff --git a/src/backend_x64/jitstate_info.h b/src/backend_x64/jitstate_info.h index 232e37eb..7295a3d9 100644 --- a/src/backend_x64/jitstate_info.h +++ b/src/backend_x64/jitstate_info.h @@ -20,12 +20,28 @@ struct JitStateInfo { , offsetof_cycles_to_run(offsetof(JitStateType, cycles_to_run)) , offsetof_save_host_MXCSR(offsetof(JitStateType, save_host_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_to_run; const size_t offsetof_save_host_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