From 7445c617bcfa13e3eb7adaabf81ee2926d1625e7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 9 May 2022 20:32:02 -0400 Subject: [PATCH] Start removing 68000-specific timing calculations. --- InstructionSets/M68k/Executor.hpp | 5 ++- .../Implementation/ExecutorImplementation.hpp | 3 +- .../Implementation/PerformImplementation.hpp | 31 ++++++------------- InstructionSets/M68k/Instruction.hpp | 3 +- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/InstructionSets/M68k/Executor.hpp b/InstructionSets/M68k/Executor.hpp index 25f83a0c8..2b52b5956 100644 --- a/InstructionSets/M68k/Executor.hpp +++ b/InstructionSets/M68k/Executor.hpp @@ -49,8 +49,11 @@ template class Executor { // Flow control. void consume_cycles(int) {} - void raise_exception(int, bool use_current_instruction_pc = true); + template void raise_exception(int); + void did_update_status(); + template void did_mulu(IntT) {} + template void did_muls(IntT) {} template void complete_bcc(bool matched_condition, IntT offset); void complete_dbcc(bool matched_condition, bool overflowed, int16_t offset); diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 6676c1beb..bcf61c4d1 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -332,7 +332,8 @@ void Executor::set_state(const Registers &state) { // MARK: - Flow Control. template -void Executor::raise_exception(int index, bool use_current_instruction_pc) { +template +void Executor::raise_exception(int index) { const uint32_t address = index << 2; // Grab the status to store, then switch into supervisor mode. diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 352887772..5286eb3c8 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -492,35 +492,22 @@ template < Multiplications. */ - case Operation::MULU: { + case Operation::MULU: dest.l = dest.w * src.w; status.carry_flag_ = status.overflow_flag_ = 0; status.zero_result_ = dest.l; status.negative_flag_ = status.zero_result_ & 0x80000000; + flow_controller.did_mulu(src.w); + break; - int number_of_ones = src.w; - convert_to_bit_count_16(number_of_ones); - - // Time taken = 38 cycles + 2 cycles for every 1 in the source. - flow_controller.consume_cycles(2 * number_of_ones + 34); - } break; - - case Operation::MULS: { + case Operation::MULS: dest.l = u_extend16(dest.w) * u_extend16(src.w); status.carry_flag_ = status.overflow_flag_ = 0; status.zero_result_ = dest.l; status.negative_flag_ = status.zero_result_ & 0x80000000; - - // Find the number of 01 or 10 pairs in the 17-bit number - // formed by the source value with a 0 suffix. - int number_of_pairs = src.w; - number_of_pairs = (number_of_pairs ^ (number_of_pairs << 1)) & 0xffff; - convert_to_bit_count_16(number_of_pairs); - - // Time taken = 38 cycles + 2 cycles per 1 in the source. - flow_controller.consume_cycles(2 * number_of_pairs + 34); - } break; + flow_controller.did_muls(src.w); + break; /* Divisions. @@ -651,12 +638,12 @@ template < // TRAP, which is a nicer form of ILLEGAL. case Operation::TRAP: - flow_controller.raise_exception(src.l + 32, false); + flow_controller.template raise_exception(src.l + 32); break; case Operation::TRAPV: { if(status.overflow_flag_) { - flow_controller.raise_exception(7, false); + flow_controller.template raise_exception(7); } } break; @@ -682,7 +669,7 @@ template < } else { flow_controller.consume_cycles(12); } - flow_controller.raise_exception(6, false); + flow_controller.template raise_exception(6); } } break; diff --git a/InstructionSets/M68k/Instruction.hpp b/InstructionSets/M68k/Instruction.hpp index 5753a483c..77e0ffed2 100644 --- a/InstructionSets/M68k/Instruction.hpp +++ b/InstructionSets/M68k/Instruction.hpp @@ -157,7 +157,8 @@ static constexpr uint8_t StoreOp2 = (1 << 3); /*! Provides a bitfield with a value in the range 0–15 indicating which of the provided operation's - operands are accessed via standard fetch and store cycles. + operands are accessed via standard fetch and store cycles; the bitfield is composted of + [Fetch/Store]Op[1/2] as defined above. Unusual bus sequences, such as TAS or MOVEM, are not described here. */