From 693d86dd675aab51a9a55a58b57afffdb111032c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 25 Mar 2024 12:59:19 -0400 Subject: [PATCH] OpcodeDispatcher: add SetAFAndFixup helper Signed-off-by: Alyssa Rosenzweig --- FEXCore/Source/Interface/Core/OpcodeDispatcher.h | 1 + .../Interface/Core/OpcodeDispatcher/Flags.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.h b/FEXCore/Source/Interface/Core/OpcodeDispatcher.h index 167ecb2a2..360bdf323 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.h +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.h @@ -1764,6 +1764,7 @@ private: OrderedNode *LoadPFRaw(); OrderedNode *LoadAF(); void FixupAF(); + void SetAFAndFixup(OrderedNode *AF); void CalculatePF(OrderedNode *Res); void CalculateAF(OrderedNode *Src1, OrderedNode *Src2); diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher/Flags.cpp b/FEXCore/Source/Interface/Core/OpcodeDispatcher/Flags.cpp index 67e51966d..b8aa8371f 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher/Flags.cpp +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher/Flags.cpp @@ -277,6 +277,19 @@ void OpDispatchBuilder::FixupAF() { SetRFLAG(XorRes); } +void OpDispatchBuilder::SetAFAndFixup(OrderedNode *AF) { + // We have a value of AF, we shift into AF[4]. We need to fixup AF[4] so that + // we get the right value when we XOR in PF[4] later. The easiest solution is + // to XOR by PF[4], since: + // + // (AF[4] ^ PF[4]) ^ PF[4] = AF[4] + + auto PFRaw = GetRFLAG(FEXCore::X86State::RFLAG_PF_RAW_LOC); + + OrderedNode *XorRes = _XorShift(OpSize::i32Bit, PFRaw, AF, ShiftType::LSL, 4); + SetRFLAG(XorRes); +} + void OpDispatchBuilder::CalculatePF(OrderedNode *Res) { // Calculation is entirely deferred until load, just store the 8-bit result. SetRFLAG(Res);