From aa74a8130b64a7194f2e3072dc97149dc034b8da Mon Sep 17 00:00:00 2001 From: MerryMage Date: Fri, 12 Jan 2018 17:31:21 +0000 Subject: [PATCH] Misc. fixups of MSVC build --- src/backend_x64/a64_emit_x64.cpp | 20 +++++++++---------- src/backend_x64/a64_interface.cpp | 10 +++------- src/backend_x64/devirtualize.h | 16 ++++++++------- src/backend_x64/emit_x64.cpp | 6 +++--- src/frontend/A64/translate/impl/branch.cpp | 4 ++-- src/frontend/A64/translate/impl/impl.cpp | 2 +- .../impl/load_store_register_pair.cpp | 2 -- 7 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/backend_x64/a64_emit_x64.cpp b/src/backend_x64/a64_emit_x64.cpp index 766f19ad..faa284b8 100644 --- a/src/backend_x64/a64_emit_x64.cpp +++ b/src/backend_x64/a64_emit_x64.cpp @@ -223,13 +223,13 @@ void A64EmitX64::EmitA64CallSupervisor(A64EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); ASSERT(args[0].IsImmediate()); u32 imm = args[0].GetImmediateU32(); - Devirtualize<&A64::UserCallbacks::CallSVC>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 param1) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::CallSVC).EmitCall(code, [&](Xbyak::Reg64 param1) { code->mov(param1.cvt32(), imm); }); } void A64EmitX64::EmitA64ReadMemory8(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryRead8>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryRead8).EmitCall(code, [&](Xbyak::Reg64 vaddr) { ASSERT(vaddr == code->ABI_PARAM2); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(inst, {}, args[0]); @@ -237,7 +237,7 @@ void A64EmitX64::EmitA64ReadMemory8(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64ReadMemory16(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryRead16>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryRead16).EmitCall(code, [&](Xbyak::Reg64 vaddr) { ASSERT(vaddr == code->ABI_PARAM2); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(inst, {}, args[0]); @@ -245,7 +245,7 @@ void A64EmitX64::EmitA64ReadMemory16(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64ReadMemory32(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryRead32>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryRead32).EmitCall(code, [&](Xbyak::Reg64 vaddr) { ASSERT(vaddr == code->ABI_PARAM2); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(inst, {}, args[0]); @@ -253,7 +253,7 @@ void A64EmitX64::EmitA64ReadMemory32(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64ReadMemory64(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryRead64>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryRead64).EmitCall(code, [&](Xbyak::Reg64 vaddr) { ASSERT(vaddr == code->ABI_PARAM2); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(inst, {}, args[0]); @@ -261,7 +261,7 @@ void A64EmitX64::EmitA64ReadMemory64(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64WriteMemory8(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryWrite8>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryWrite8).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { ASSERT(vaddr == code->ABI_PARAM2 && value == code->ABI_PARAM3); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(nullptr, {}, args[0], args[1]); @@ -269,7 +269,7 @@ void A64EmitX64::EmitA64WriteMemory8(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64WriteMemory16(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryWrite16>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryWrite16).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { ASSERT(vaddr == code->ABI_PARAM2 && value == code->ABI_PARAM3); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(nullptr, {}, args[0], args[1]); @@ -277,7 +277,7 @@ void A64EmitX64::EmitA64WriteMemory16(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64WriteMemory32(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryWrite32>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryWrite32).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { ASSERT(vaddr == code->ABI_PARAM2 && value == code->ABI_PARAM3); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(nullptr, {}, args[0], args[1]); @@ -285,7 +285,7 @@ void A64EmitX64::EmitA64WriteMemory32(A64EmitContext& ctx, IR::Inst* inst) { } void A64EmitX64::EmitA64WriteMemory64(A64EmitContext& ctx, IR::Inst* inst) { - Devirtualize<&A64::UserCallbacks::MemoryWrite64>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::MemoryWrite64).EmitCall(code, [&](Xbyak::Reg64 vaddr, Xbyak::Reg64 value) { ASSERT(vaddr == code->ABI_PARAM2 && value == code->ABI_PARAM3); auto args = ctx.reg_alloc.GetArgumentInfo(inst); ctx.reg_alloc.HostCall(nullptr, {}, args[0], args[1]); @@ -294,7 +294,7 @@ void A64EmitX64::EmitA64WriteMemory64(A64EmitContext& ctx, IR::Inst* inst) { void A64EmitX64::EmitTerminalImpl(IR::Term::Interpret terminal, IR::LocationDescriptor) { code->SwitchMxcsrOnExit(); - Devirtualize<&A64::UserCallbacks::InterpreterFallback>(conf.callbacks).EmitCall(code, [&](Xbyak::Reg64 param1, Xbyak::Reg64 param2) { + DEVIRT(conf.callbacks, &A64::UserCallbacks::InterpreterFallback).EmitCall(code, [&](Xbyak::Reg64 param1, Xbyak::Reg64 param2) { code->mov(param1, A64::LocationDescriptor{terminal.next}.PC()); code->mov(qword[r15 + offsetof(A64JitState, pc)], param1); code->mov(param2.cvt32(), 1); diff --git a/src/backend_x64/a64_interface.cpp b/src/backend_x64/a64_interface.cpp index 68823abb..01b82651 100644 --- a/src/backend_x64/a64_interface.cpp +++ b/src/backend_x64/a64_interface.cpp @@ -12,6 +12,7 @@ #include "backend_x64/a64_emit_x64.h" #include "backend_x64/a64_jitstate.h" #include "backend_x64/block_of_code.h" +#include "backend_x64/devirtualize.h" #include "backend_x64/jitstate_info.h" #include "common/assert.h" #include "common/scope_exit.h" @@ -25,16 +26,11 @@ namespace A64 { using namespace BackendX64; -template -static Ret Thunk(A64::UserCallbacks* cb, Args... args) { - return (cb->*fn)(std::forward(args)...); -} - static RunCodeCallbacks GenRunCodeCallbacks(A64::UserCallbacks* cb, CodePtr (*LookupBlock)(void* lookup_block_arg), void* arg) { return RunCodeCallbacks{ std::make_unique(LookupBlock, reinterpret_cast(arg)), - std::make_unique(&Thunk<&A64::UserCallbacks::AddTicks, void, u64>, reinterpret_cast(cb)), - std::make_unique(&Thunk<&A64::UserCallbacks::GetTicksRemaining, u64>, reinterpret_cast(cb)), + std::make_unique(DEVIRT(cb, &A64::UserCallbacks::AddTicks)), + std::make_unique(DEVIRT(cb, &A64::UserCallbacks::GetTicksRemaining)), }; } diff --git a/src/backend_x64/devirtualize.h b/src/backend_x64/devirtualize.h index 78e27df7..9c405571 100644 --- a/src/backend_x64/devirtualize.h +++ b/src/backend_x64/devirtualize.h @@ -17,22 +17,24 @@ namespace BackendX64 { namespace impl { -template +template struct ThunkBuilder; -template -struct ThunkBuilder { +template +struct ThunkBuilder { static R Thunk(C* this_, Args... args) { - return (this_->*fn)(std::forward(args)...); + return (this_->*mfp)(std::forward(args)...); } }; } // namespace impl -template -ArgCallback Devirtualize(mp::class_type_t* this_) { - return ArgCallback{&impl::ThunkBuilder::Thunk, reinterpret_cast(this_)}; +template +ArgCallback Devirtualize(mp::class_type_t* this_) { + return ArgCallback{&impl::ThunkBuilder::Thunk, reinterpret_cast(this_)}; } +#define DEVIRT(this_, mfp) Dynarmic::BackendX64::Devirtualize(this_) + } // namespace BackendX64 } // namespace Dynarmic diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp index b4fa7c7a..0cf2b1ec 100644 --- a/src/backend_x64/emit_x64.cpp +++ b/src/backend_x64/emit_x64.cpp @@ -135,7 +135,7 @@ template void EmitX64::EmitGetNZCVFromOp(EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - const size_t bitsize = [&]{ + const int bitsize = [&]{ switch (args[0].GetType()) { case IR::Type::U8: return 8; @@ -786,7 +786,7 @@ static Xbyak::Reg64 DoNZCV(BlockOfCode* code, RegAlloc& reg_alloc, IR::Inst* nzc return nzcv; } -static void EmitAdd(BlockOfCode* code, EmitContext& ctx, IR::Inst* inst, size_t bitsize) { +static void EmitAdd(BlockOfCode* code, EmitContext& ctx, IR::Inst* inst, int bitsize) { auto carry_inst = inst->GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp); auto overflow_inst = inst->GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp); auto nzcv_inst = inst->GetAssociatedPseudoOperation(IR::Opcode::GetNZCVFromOp); @@ -860,7 +860,7 @@ void EmitX64::EmitAdd64(EmitContext& ctx, IR::Inst* inst) { EmitAdd(code, ctx, inst, 64); } -static void EmitSub(BlockOfCode* code, EmitContext& ctx, IR::Inst* inst, size_t bitsize) { +static void EmitSub(BlockOfCode* code, EmitContext& ctx, IR::Inst* inst, int bitsize) { auto carry_inst = inst->GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp); auto overflow_inst = inst->GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp); auto nzcv_inst = inst->GetAssociatedPseudoOperation(IR::Opcode::GetNZCVFromOp); diff --git a/src/frontend/A64/translate/impl/branch.cpp b/src/frontend/A64/translate/impl/branch.cpp index c3e89a1f..8592d9fe 100644 --- a/src/frontend/A64/translate/impl/branch.cpp +++ b/src/frontend/A64/translate/impl/branch.cpp @@ -94,7 +94,7 @@ bool TranslatorVisitor::CBNZ(bool sf, Imm<19> imm19, Reg Rt) { bool TranslatorVisitor::TBZ(Imm<1> b5, Imm<5> b40, Imm<14> imm14, Reg Rt) { size_t datasize = b5 == 1 ? 64 : 32; - size_t bit_pos = concatenate(b5, b40).ZeroExtend(); + u8 bit_pos = concatenate(b5, b40).ZeroExtend(); s64 offset = concatenate(imm14, Imm<2>{0}).SignExtend(); auto operand = X(datasize, Rt); @@ -110,7 +110,7 @@ bool TranslatorVisitor::TBZ(Imm<1> b5, Imm<5> b40, Imm<14> imm14, Reg Rt) { bool TranslatorVisitor::TBNZ(Imm<1> b5, Imm<5> b40, Imm<14> imm14, Reg Rt) { size_t datasize = b5 == 1 ? 64 : 32; - size_t bit_pos = concatenate(b5, b40).ZeroExtend(); + u8 bit_pos = concatenate(b5, b40).ZeroExtend(); s64 offset = concatenate(imm14, Imm<2>{0}).SignExtend(); auto operand = X(datasize, Rt); diff --git a/src/frontend/A64/translate/impl/impl.cpp b/src/frontend/A64/translate/impl/impl.cpp index 0c932803..57f8fdb2 100644 --- a/src/frontend/A64/translate/impl/impl.cpp +++ b/src/frontend/A64/translate/impl/impl.cpp @@ -45,7 +45,7 @@ boost::optional TranslatorVisitor::DecodeBitMasks(b s32 R = s32(immr.ZeroExtend() & levels); u64 d = u64(S - R) & levels; - size_t esize = 1 << len; + size_t esize = static_cast(1) << len; u64 welem = Common::Ones(S + 1); u64 telem = Common::Ones(d + 1); u64 wmask = Common::RotateRight(Common::Replicate(welem, esize), R); diff --git a/src/frontend/A64/translate/impl/load_store_register_pair.cpp b/src/frontend/A64/translate/impl/load_store_register_pair.cpp index 6283aa0f..666ebc46 100644 --- a/src/frontend/A64/translate/impl/load_store_register_pair.cpp +++ b/src/frontend/A64/translate/impl/load_store_register_pair.cpp @@ -28,8 +28,6 @@ bool TranslatorVisitor::STP_LDP_gen(Imm<2> opc, bool not_postindex, bool wback, return UnpredictableInstruction(); IR::U64 address; - IR::U32U64 data1; - IR::U32U64 data2; const size_t dbytes = datasize / 8; if (Rn == Reg::SP)