From f3f23f90a3432ea6847515b36df0a62ea7f6f703 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 11 Oct 2022 11:22:34 -0400 Subject: [PATCH] Consolidate repetition in CLR. --- .../Implementation/PerformImplementation.hpp | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 2de88e6ee..fd9b968be 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -88,10 +88,14 @@ static void add_sub(IntT source, IntT &destination, Status &status) { destination = result; } +/// @returns the name of the bit to be used as a mask for BCLR, BCHG, BSET or BTST for +/// @c instruction given @c source. inline uint32_t mask_bit(const Preinstruction &instruction, uint32_t source) { return source & (instruction.mode<1>() == AddressingMode::DataRegisterDirect ? 31 : 7); } +/// Performs a BCLR, BCHG or BSET as specified by @c operation and described by @c instruction, @c source and @c destination, updating @c destination and @c status. +/// Also makes an appropriate notification to the @c flow_controller. template void bit_manipulate(const Preinstruction &instruction, uint32_t source, uint32_t &destination, Status &status, FlowController &flow_controller) { static_assert(operation == Operation::BCLR || operation == Operation::BCHG || operation == Operation::BSET); @@ -106,6 +110,12 @@ void bit_manipulate(const Preinstruction &instruction, uint32_t source, uint32_t flow_controller.did_bit_op(int(bit)); } +/// Sets @c destination to 0, clears the overflow, carry and negative flags, sets the zero flag. +template void clear(IntT &destination, Status &status) { + destination = 0; + status.negative_flag = status.overflow_flag = status.carry_flag = status.zero_result = 0; +} + } template < @@ -229,20 +239,9 @@ template < CLRs: store 0 to the destination, set the zero flag, and clear negative, overflow and carry. */ - case Operation::CLRb: - src.b = 0; - status.negative_flag = status.overflow_flag = status.carry_flag = status.zero_result = 0; - break; - - case Operation::CLRw: - src.w = 0; - status.negative_flag = status.overflow_flag = status.carry_flag = status.zero_result = 0; - break; - - case Operation::CLRl: - src.l = 0; - status.negative_flag = status.overflow_flag = status.carry_flag = status.zero_result = 0; - break; + case Operation::CLRb: Primitive::clear(src.b, status); break; + case Operation::CLRw: Primitive::clear(src.w, status); break; + case Operation::CLRl: Primitive::clear(src.l, status); break; /* CMP.b, CMP.l and CMP.w: sets the condition flags (other than extend) based on a subtraction