From 36b3d515231725421cce03ac6e5be890b053075e Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 8 Jul 2021 17:53:01 +0200 Subject: [PATCH] JitArm64: Restructure the BackPatchInfo flags enum This makes it possible to construct flag combinations like "load 16 bits into an FPR". --- .../PowerPC/JitArm64/JitArm64_BackPatch.cpp | 20 ++++---- .../JitArm64/JitArm64_LoadStoreFloating.cpp | 46 +++++++++---------- .../JitArm64/JitArm64_LoadStorePaired.cpp | 6 +-- .../Core/PowerPC/JitArmCommon/BackPatch.h | 31 +++++++------ 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp index ef2ec7164d..cf5712eaab 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp @@ -58,14 +58,14 @@ void JitArm64::EmitBackpatchRoutine(u32 flags, bool fastmem, bool do_farcode, AR if (fastmem) { - if (flags & BackPatchInfo::FLAG_STORE && flags & BackPatchInfo::FLAG_MASK_FLOAT) + if ((flags & BackPatchInfo::FLAG_STORE) && (flags & BackPatchInfo::FLAG_FLOAT)) { - if (flags & BackPatchInfo::FLAG_SIZE_F32) + if ((flags & BackPatchInfo::FLAG_SIZE_32) && !(flags & BackPatchInfo::FLAG_PAIR)) { m_float_emit.REV32(8, ARM64Reg::D0, RS); m_float_emit.STR(32, ARM64Reg::D0, MEM_REG, addr); } - else if (flags & BackPatchInfo::FLAG_SIZE_F32X2) + else if ((flags & BackPatchInfo::FLAG_SIZE_32) && (flags & BackPatchInfo::FLAG_PAIR)) { m_float_emit.REV32(8, ARM64Reg::D0, RS); m_float_emit.STR(64, ARM64Reg::Q0, MEM_REG, addr); @@ -76,9 +76,9 @@ void JitArm64::EmitBackpatchRoutine(u32 flags, bool fastmem, bool do_farcode, AR m_float_emit.STR(64, ARM64Reg::Q0, MEM_REG, addr); } } - else if (flags & BackPatchInfo::FLAG_LOAD && flags & BackPatchInfo::FLAG_MASK_FLOAT) + else if ((flags & BackPatchInfo::FLAG_LOAD) && (flags & BackPatchInfo::FLAG_FLOAT)) { - if (flags & BackPatchInfo::FLAG_SIZE_F32) + if (flags & BackPatchInfo::FLAG_SIZE_32) { m_float_emit.LDR(32, EncodeRegToDouble(RS), MEM_REG, addr); m_float_emit.REV32(8, EncodeRegToDouble(RS), EncodeRegToDouble(RS)); @@ -158,15 +158,15 @@ void JitArm64::EmitBackpatchRoutine(u32 flags, bool fastmem, bool do_farcode, AR ABI_PushRegisters(gprs_to_push); m_float_emit.ABI_PushRegisters(fprs_to_push, ARM64Reg::X30); - if (flags & BackPatchInfo::FLAG_STORE && flags & BackPatchInfo::FLAG_MASK_FLOAT) + if ((flags & BackPatchInfo::FLAG_STORE) && (flags & BackPatchInfo::FLAG_FLOAT)) { - if (flags & BackPatchInfo::FLAG_SIZE_F32) + if ((flags & BackPatchInfo::FLAG_SIZE_32) && !(flags & BackPatchInfo::FLAG_PAIR)) { m_float_emit.UMOV(32, ARM64Reg::W0, RS, 0); MOVP2R(ARM64Reg::X8, &PowerPC::Write_U32); BLR(ARM64Reg::X8); } - else if (flags & BackPatchInfo::FLAG_SIZE_F32X2) + else if ((flags & BackPatchInfo::FLAG_SIZE_32) && (flags & BackPatchInfo::FLAG_PAIR)) { m_float_emit.UMOV(64, ARM64Reg::X0, RS, 0); MOVP2R(ARM64Reg::X8, &PowerPC::Write_U64); @@ -180,9 +180,9 @@ void JitArm64::EmitBackpatchRoutine(u32 flags, bool fastmem, bool do_farcode, AR BLR(ARM64Reg::X8); } } - else if (flags & BackPatchInfo::FLAG_LOAD && flags & BackPatchInfo::FLAG_MASK_FLOAT) + else if ((flags & BackPatchInfo::FLAG_LOAD) && (flags & BackPatchInfo::FLAG_FLOAT)) { - if (flags & BackPatchInfo::FLAG_SIZE_F32) + if (flags & BackPatchInfo::FLAG_SIZE_32) { MOVP2R(ARM64Reg::X8, &PowerPC::Read_U32); BLR(ARM64Reg::X8); diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStoreFloating.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStoreFloating.cpp index 727c0268e2..79add2f227 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStoreFloating.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStoreFloating.cpp @@ -26,7 +26,7 @@ void JitArm64::lfXX(UGeckoInstruction inst) u32 a = inst.RA, b = inst.RB; s32 offset = inst.SIMM_16; - u32 flags = BackPatchInfo::FLAG_LOAD; + u32 flags = BackPatchInfo::FLAG_LOAD | BackPatchInfo::FLAG_FLOAT; bool update = false; s32 offset_reg = -1; @@ -36,38 +36,38 @@ void JitArm64::lfXX(UGeckoInstruction inst) switch (inst.SUBOP10) { case 567: // lfsux - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; update = true; offset_reg = b; break; case 535: // lfsx - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; offset_reg = b; break; case 631: // lfdux - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; update = true; offset_reg = b; break; case 599: // lfdx - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; offset_reg = b; break; } break; case 49: // lfsu - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; update = true; break; case 48: // lfs - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; break; case 51: // lfdu - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; update = true; break; case 50: // lfd - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; break; } @@ -75,7 +75,7 @@ void JitArm64::lfXX(UGeckoInstruction inst) bool is_immediate = false; const RegType type = - (flags & BackPatchInfo::FLAG_SIZE_F64) != 0 ? RegType::LowerPair : RegType::DuplicatedSingle; + (flags & BackPatchInfo::FLAG_SIZE_64) != 0 ? RegType::LowerPair : RegType::DuplicatedSingle; gpr.Lock(ARM64Reg::W0, ARM64Reg::W30); fpr.Lock(ARM64Reg::Q0); @@ -190,7 +190,7 @@ void JitArm64::stfXX(UGeckoInstruction inst) bool want_single = false; s32 offset = inst.SIMM_16; - u32 flags = BackPatchInfo::FLAG_STORE; + u32 flags = BackPatchInfo::FLAG_STORE | BackPatchInfo::FLAG_FLOAT; bool update = false; s32 offset_reg = -1; @@ -201,46 +201,46 @@ void JitArm64::stfXX(UGeckoInstruction inst) { case 663: // stfsx want_single = true; - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; offset_reg = b; break; case 695: // stfsux want_single = true; - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; update = true; offset_reg = b; break; case 727: // stfdx - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; offset_reg = b; break; case 759: // stfdux - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; update = true; offset_reg = b; break; case 983: // stfiwx // This instruction writes the lower 32 bits of a double. want_single must be false - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; offset_reg = b; break; } break; case 53: // stfsu want_single = true; - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; update = true; break; case 52: // stfs want_single = true; - flags |= BackPatchInfo::FLAG_SIZE_F32; + flags |= BackPatchInfo::FLAG_SIZE_32; break; case 55: // stfdu - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; update = true; break; case 54: // stfd - flags |= BackPatchInfo::FLAG_SIZE_F64; + flags |= BackPatchInfo::FLAG_SIZE_64; break; } @@ -361,16 +361,16 @@ void JitArm64::stfXX(UGeckoInstruction inst) if (jo.optimizeGatherPipe && PowerPC::IsOptimizableGatherPipeWrite(imm_addr)) { int accessSize; - if (flags & BackPatchInfo::FLAG_SIZE_F64) + if (flags & BackPatchInfo::FLAG_SIZE_64) accessSize = 64; else accessSize = 32; LDR(IndexType::Unsigned, ARM64Reg::X0, PPC_REG, PPCSTATE_OFF(gather_pipe_ptr)); - if (flags & BackPatchInfo::FLAG_SIZE_F64) + if (flags & BackPatchInfo::FLAG_SIZE_64) m_float_emit.REV64(8, ARM64Reg::Q0, V0); - else if (flags & BackPatchInfo::FLAG_SIZE_F32) + else if (flags & BackPatchInfo::FLAG_SIZE_32) m_float_emit.REV32(8, ARM64Reg::D0, V0); m_float_emit.STR(accessSize, IndexType::Post, accessSize == 64 ? ARM64Reg::Q0 : ARM64Reg::D0, diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStorePaired.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStorePaired.cpp index aafda1845b..76d73edd50 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStorePaired.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStorePaired.cpp @@ -198,9 +198,9 @@ void JitArm64::psq_stXX(UGeckoInstruction inst) if (js.assumeNoPairedQuantize) { - u32 flags = BackPatchInfo::FLAG_STORE; - - flags |= (w ? BackPatchInfo::FLAG_SIZE_F32 : BackPatchInfo::FLAG_SIZE_F32X2); + u32 flags = BackPatchInfo::FLAG_STORE | BackPatchInfo::FLAG_FLOAT | BackPatchInfo::FLAG_SIZE_32; + if (!w) + flags |= BackPatchInfo::FLAG_PAIR; EmitBackpatchRoutine(flags, jo.fastmem, jo.fastmem, VS, EncodeRegTo64(addr_reg), gprs_in_use, fprs_in_use); diff --git a/Source/Core/Core/PowerPC/JitArmCommon/BackPatch.h b/Source/Core/Core/PowerPC/JitArmCommon/BackPatch.h index c1a4596500..0e42d2a9f9 100644 --- a/Source/Core/Core/PowerPC/JitArmCommon/BackPatch.h +++ b/Source/Core/Core/PowerPC/JitArmCommon/BackPatch.h @@ -13,31 +13,32 @@ struct BackPatchInfo FLAG_SIZE_8 = (1 << 2), FLAG_SIZE_16 = (1 << 3), FLAG_SIZE_32 = (1 << 4), - FLAG_SIZE_F32 = (1 << 5), - FLAG_SIZE_F32X2 = (1 << 6), - FLAG_SIZE_F64 = (1 << 7), + FLAG_SIZE_64 = (1 << 5), + FLAG_FLOAT = (1 << 6), + FLAG_PAIR = (1 << 7), FLAG_REVERSE = (1 << 8), FLAG_EXTEND = (1 << 9), FLAG_ZERO_256 = (1 << 10), - FLAG_MASK_FLOAT = FLAG_SIZE_F32 | FLAG_SIZE_F32X2 | FLAG_SIZE_F64, }; static u32 GetFlagSize(u32 flags) { + u32 size = 0; + if (flags & FLAG_SIZE_8) - return 8; + size = 8; if (flags & FLAG_SIZE_16) - return 16; + size = 16; if (flags & FLAG_SIZE_32) - return 32; - if (flags & FLAG_SIZE_F32) - return 32; - if (flags & FLAG_SIZE_F32X2) - return 64; - if (flags & FLAG_SIZE_F64) - return 64; + size = 32; + if (flags & FLAG_SIZE_64) + size = 64; if (flags & FLAG_ZERO_256) - return 256; - return 0; + size = 256; + + if (flags & FLAG_PAIR) + size *= 2; + + return size; } };