From 3ca2c4377f97a84eaf30565e227268a7c1ad3058 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 25 Mar 2024 13:37:13 -0400 Subject: [PATCH] OpcodeDispatcher: rewrite AAA Signed-off-by: Alyssa Rosenzweig --- .../Interface/Core/OpcodeDispatcher.cpp | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp index cc8c364b2..ca5de861e 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp @@ -3224,40 +3224,26 @@ void OpDispatchBuilder::AAAOp(OpcodeArgs) { InvalidateDeferredFlags(); auto AF = LoadAF(); - auto AL = LoadGPRRegister(X86State::REG_RAX, 1); - auto AX = LoadGPRRegister(X86State::REG_RAX, 2); - auto Cond = _Or(OpSize::i64Bit, AF, _Select(FEXCore::IR::COND_UGT, _And(OpSize::i64Bit, AL, _Constant(0xF)), _Constant(9), _Constant(1), _Constant(0))); + auto A = LoadGPRRegister(X86State::REG_RAX); - auto FalseBlock = CreateNewCodeBlockAfter(GetCurrentBlock()); - auto TrueBlock = CreateNewCodeBlockAfter(FalseBlock); - auto EndBlock = CreateNewCodeBlockAfter(TrueBlock); - CondJump(Cond, TrueBlock, FalseBlock); + // AF |= ((AL & 0x0F) > 9); + AF = _Or(OpSize::i32Bit, AF, + _Select(FEXCore::IR::COND_UGT, _And(OpSize::i32Bit, A, _Constant(0xF)), _Constant(9), + _Constant(1), _Constant(0))); - SetCurrentCodeBlock(FalseBlock); - StartNewBlock(); - { - auto NewAX = _And(OpSize::i64Bit, AX, _Constant(0xFF0F)); - StoreGPRRegister(X86State::REG_RAX, NewAX, 2); - ZeroNZCV(); - SetAF(0); - CalculateDeferredFlags(); - Jump(EndBlock); - } - SetCurrentCodeBlock(TrueBlock); - StartNewBlock(); + // CF = AF, OF/SF/ZF/PF undefined + ZeroNZCV(); + SetRFLAG(AF); + SetAFAndFixup(AF); + CalculateDeferredFlags(); - { - auto NewAX = _Add(OpSize::i64Bit, AX, _Constant(0x106)); - auto Result = _And(OpSize::i64Bit, NewAX, _Constant(0xFF0F)); - StoreGPRRegister(X86State::REG_RAX, Result, 2); - ZeroNZCV(); - SetRFLAG(_Constant(1)); - SetAF(1); - CalculateDeferredFlags(); - Jump(EndBlock); - } - SetCurrentCodeBlock(EndBlock); - StartNewBlock(); + // AX = CF ? (AX + 0x106) : 0 + A = _NZCVSelect(OpSize::i32Bit, CondClassType{COND_UGE} /* CF = 1 */, + _Add(OpSize::i32Bit, A, _Constant(0x106)), A); + + // AL = AL & 0x0F + A = _And(OpSize::i32Bit, A, _Constant(0xFF0F)); + StoreGPRRegister(X86State::REG_RAX, A, 2); } void OpDispatchBuilder::AASOp(OpcodeArgs) {