From e8dd8215bab21a2057ee63fb57dc1541304c0cca Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 27 May 2022 15:37:40 -0400 Subject: [PATCH] Tweak per empirical results. --- .../Implementation/68000Mk2Implementation.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp index a9ddfb43e..c37276954 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp @@ -2576,22 +2576,26 @@ template void ProcessorBase::did_divs(int32_t dividend, int3 return; } - // It's either five or six microcycles to get into the main loop, depending + // It's either six or seven microcycles to get into the main loop, depending // on dividend sign. - dynamic_instruction_length_ = 5 + (dividend < 0); + dynamic_instruction_length_ = 6 + (dividend < 0); if(did_overflow) { return; } - // There's always a cost of four microcycles per bit, plus an additional - // one for each that is non-zero. + // There's a fixed cost per bit, plus an additional one for each that is zero. // - // The sign bit does not count here; it's the low fifteen bits that matter + // The sign bit does not count here; it's the high fifteen bits that matter // only, in the unsigned version of the result. - dynamic_instruction_length_ += 60; + // + // Disclaimer: per the flowchart it looks to me like this constant should be 60 + // rather than 49 — four microcycles per bit. But the number 49 makes this + // algorithm exactly fit the stated minimum and maximum costs. Possibly the + // undefined difference between a nop cycle an an idle wait is relevant here? + dynamic_instruction_length_ += 49; - int result_bits = abs(dividend / divisor) & 0x7fff; + int result_bits = ~abs(dividend / divisor) & 0xfffe; convert_to_bit_count_16(result_bits); dynamic_instruction_length_ += result_bits;