From bcebb2e52036bf4a69ceefb5b0d009066fb3c991 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 20 Oct 2023 17:08:11 -0400 Subject: [PATCH] Further reduce repetition overhead. --- .../Implementation/PerformImplementation.hpp | 55 ++++++------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/InstructionSets/x86/Implementation/PerformImplementation.hpp b/InstructionSets/x86/Implementation/PerformImplementation.hpp index 0a5297ac5..357be1fa7 100644 --- a/InstructionSets/x86/Implementation/PerformImplementation.hpp +++ b/InstructionSets/x86/Implementation/PerformImplementation.hpp @@ -1354,49 +1354,26 @@ void pushf(MemoryT &memory, RegistersT ®isters, Status &status) { push(value, memory, registers); } -template -bool repetition_over(const InstructionT &instruction, RegistersT ®isters) { - if(instruction.repetition() == Repetition::None) { - return false; - } - - if constexpr (std::is_same_v) { - return !registers.cx(); - } else { - return !registers.ecx(); - } +template +bool repetition_over(const InstructionT &instruction, AddressT &eCX) { + return instruction.repetition() != Repetition::None && !eCX; } -template -void repeat(const InstructionT &instruction, Status &status, RegistersT ®isters, FlowControllerT &flow_controller) { - if(instruction.repetition() == Repetition::None) { +template +void repeat(const InstructionT &instruction, Status &status, AddressT &eCX, FlowControllerT &flow_controller) { + if( + instruction.repetition() == Repetition::None || + !(--eCX) || + (instruction.repetition() == Repetition::RepNE) == status.flag() + ) { return; } - - bool count_exhausted = false; - - if constexpr (std::is_same_v) { - count_exhausted = !(--registers.cx()); - } else { - count_exhausted = !(--registers.ecx()); - } - - if(count_exhausted) { - return; - } - const bool zero = status.flag(); - if(instruction.repetition() == Repetition::RepE && !zero) { - return; - } else if(instruction.repetition() == Repetition::RepNE && zero) { - return; - } - flow_controller.repeat_last(); } -template -void cmps(const InstructionT &instruction, AddressT &eSI, AddressT &eDI, MemoryT &memory, RegistersT ®isters, Status &status, FlowControllerT &flow_controller) { - if(repetition_over(instruction, registers)) { +template +void cmps(const InstructionT &instruction, AddressT &eCX, AddressT &eSI, AddressT &eDI, MemoryT &memory, Status &status, FlowControllerT &flow_controller) { + if(repetition_over(instruction, eCX)) { return; } @@ -1410,7 +1387,7 @@ void cmps(const InstructionT &instruction, AddressT &eSI, AddressT &eDI, MemoryT Primitive::sub(lhs, rhs, status); - repeat(instruction, status, registers, flow_controller); + repeat(instruction, status, eCX, flow_controller); } } @@ -1630,7 +1607,7 @@ template < case Operation::XCHG: Primitive::xchg(destination(), source()); return; - case Operation::SALC: Primitive::salc(registers.al(), status); return; + case Operation::SALC: Primitive::salc(registers.al(), status); return; case Operation::SETMO: if constexpr (model == Model::i8086) { Primitive::setmo(destination(), status); @@ -1654,7 +1631,7 @@ template < case Operation::PUSHF: Primitive::pushf(memory, registers, status); break; case Operation::CMPS: - Primitive::cmps(instruction, eSI(), eDI(), memory, registers, status, flow_controller); + Primitive::cmps(instruction, eCX(), eSI(), eDI(), memory, status, flow_controller); break; }