From f83954f5b74af7604d04ab49f24e49f38eea1bd9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 13 May 2022 15:08:15 -0400 Subject: [PATCH] Switch to common bit-selection logic. --- .../Implementation/PerformImplementation.hpp | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 2f8934d88..66e9512e5 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -212,36 +212,43 @@ template < dest.l -= src.l; break; +#define get_mask() \ + const uint32_t mask_size = (instruction.mode<1>() == AddressingMode::DataRegisterDirect) ? 31 : 7; \ + const uint32_t bit_position = src.l & mask_size; \ + const uint32_t bit_mask = 1 << bit_position + // BTST/BCLR/etc: modulo for the mask depends on whether memory or a data register is the target. case Operation::BTST: { - const uint32_t mask = (instruction.mode<1>() == AddressingMode::DataRegisterDirect) ? 31 : 7; - status.zero_result = dest.l & (1 << (src.l & mask)); + get_mask(); + status.zero_result = dest.l & bit_mask; } break; case Operation::BCLR: { - const uint32_t mask = (instruction.mode<1>() == AddressingMode::DataRegisterDirect) ? 31 : 7; + get_mask(); - status.zero_result = dest.l & (1 << (src.l & mask)); - dest.l &= ~(1 << (src.l & mask)); - flow_controller.did_bit_op(src.l & mask); + status.zero_result = dest.l & bit_mask; + dest.l &= ~bit_mask; + flow_controller.did_bit_op(bit_position); } break; case Operation::BCHG: { - const uint32_t mask = (instruction.mode<1>() == AddressingMode::DataRegisterDirect) ? 31 : 7; + get_mask(); - status.zero_result = dest.l & (1 << (src.l & mask)); - dest.l ^= 1 << (src.l & mask); - flow_controller.did_bit_op(src.l & mask); + status.zero_result = dest.l & bit_mask; + dest.l ^= bit_mask; + flow_controller.did_bit_op(bit_position); } break; case Operation::BSET: { - const uint32_t mask = (instruction.mode<1>() == AddressingMode::DataRegisterDirect) ? 31 : 7; + get_mask(); - status.zero_result = dest.l & (1 << (src.l & mask)); - dest.l |= 1 << (src.l & mask); - flow_controller.did_bit_op(src.l & mask); + status.zero_result = dest.l & bit_mask; + dest.l |= bit_mask; + flow_controller.did_bit_op(bit_position); } break; +#undef get_mask + case Operation::Bccb: flow_controller.template complete_bcc( status.evaluate_condition(instruction.condition()),