From f8e933438e97b8b197a12c1d59472f21a9e095fc Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 2 Jun 2022 12:26:25 -0400 Subject: [PATCH] Add missing tail cost. --- .../Implementation/68000Mk2Implementation.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp index bc067a8f6..e64edfa72 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp @@ -2547,7 +2547,7 @@ template void ProcessorBase::did_divu(uint32_t dividend, uin } if(did_overflow) { - dynamic_instruction_length_ = 3; // Just a quick nn n, and then on to prefetch. + dynamic_instruction_length_ = 3; // Covers the nn n to get into the loop. return; } @@ -2556,13 +2556,15 @@ template void ProcessorBase::did_divu(uint32_t dividend, uin // since this is a classic divide algorithm, but would rather that // errors produce incorrect timing only, not incorrect timing plus // incorrect results. - dynamic_instruction_length_ = 3; // Covers the nn n to get into the loop. + dynamic_instruction_length_ = + 3 + // nn n to get into the loop; + 30 + // nn per iteration of the loop below; + 3; // n nn upon completion of the loop. divisor <<= 16; for(int c = 0; c < 15; ++c) { - if(dividend & 0x80000000) { + if(dividend & 0x8000'0000) { dividend = (dividend << 1) - divisor; - dynamic_instruction_length_ += 2; // The fixed nn iteration cost. } else { dividend <<= 1; @@ -2570,9 +2572,9 @@ template void ProcessorBase::did_divu(uint32_t dividend, uin // and test the sign of the result, but this is easier to follow: if (dividend >= divisor) { dividend -= divisor; - dynamic_instruction_length_ += 3; // i.e. the original nn plus one further n before going down the MSB=0 route. + dynamic_instruction_length_ += 1; // i.e. the original nn plus one further n before going down the MSB=0 route. } else { - dynamic_instruction_length_ += 4; // The costliest path (since in real life it's a subtraction and then a step + dynamic_instruction_length_ += 2; // The costliest path (since in real life it's a subtraction and then a step // back from there) — all costs accrue. So the fixed nn loop plus another n, // plus another one. }