From 735f5b787a9bb6b69165e9749e33399ead9de1b0 Mon Sep 17 00:00:00 2001 From: Merry Date: Sat, 30 Jul 2022 19:10:50 +0100 Subject: [PATCH] emit_arm64_a32: Fix A32SetCpsrNZC for immediate carry --- src/dynarmic/backend/arm64/emit_arm64_a32.cpp | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/dynarmic/backend/arm64/emit_arm64_a32.cpp b/src/dynarmic/backend/arm64/emit_arm64_a32.cpp index 2a68d9b0..150927a0 100644 --- a/src/dynarmic/backend/arm64/emit_arm64_a32.cpp +++ b/src/dynarmic/backend/arm64/emit_arm64_a32.cpp @@ -313,17 +313,31 @@ template<> void EmitIR(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - auto Wnz = ctx.reg_alloc.ReadW(args[0]); - auto Wc = ctx.reg_alloc.ReadW(args[1]); - RegAlloc::Realize(Wnz, Wc); - // TODO: Track latent value - code.LDR(Wscratch0, Xstate, offsetof(A32JitState, cpsr_nzcv)); - code.AND(Wscratch0, Wscratch0, 0x10000000); - code.ORR(Wscratch0, Wscratch0, Wnz); - code.ORR(Wscratch0, Wscratch0, Wc); - code.STR(Wscratch0, Xstate, offsetof(A32JitState, cpsr_nzcv)); + if (args[1].IsImmediate()) { + const u32 carry = args[1].GetImmediateU1() ? 0x2000'0000 : 0; + auto Wnz = ctx.reg_alloc.ReadW(args[0]); + RegAlloc::Realize(Wnz); + + code.LDR(Wscratch0, Xstate, offsetof(A32JitState, cpsr_nzcv)); + code.AND(Wscratch0, Wscratch0, 0x10000000); + code.ORR(Wscratch0, Wscratch0, Wnz); + if (carry) { + code.ORR(Wscratch0, Wscratch0, carry); + } + code.STR(Wscratch0, Xstate, offsetof(A32JitState, cpsr_nzcv)); + } else { + auto Wnz = ctx.reg_alloc.ReadW(args[0]); + auto Wc = ctx.reg_alloc.ReadW(args[1]); + RegAlloc::Realize(Wnz, Wc); + + code.LDR(Wscratch0, Xstate, offsetof(A32JitState, cpsr_nzcv)); + code.AND(Wscratch0, Wscratch0, 0x10000000); + code.ORR(Wscratch0, Wscratch0, Wnz); + code.ORR(Wscratch0, Wscratch0, Wc); + code.STR(Wscratch0, Xstate, offsetof(A32JitState, cpsr_nzcv)); + } } template<>