From bc9ddacb8db1361534541866d96431f25e715f3e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 19 Oct 2022 14:40:29 -0400 Subject: [PATCH] Improve commentary. --- .../M68k/Implementation/PerformImplementation.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 0dc00c7fb..6e38892c9 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -357,11 +357,13 @@ template void shif // result of 0, so overflow is set if any bit was originally set. status.overflow_flag = destination; } else { - // For a shift of n places, overflow will be set if the top n bits were not + // For a shift of n places, overflow will be set if the top n+1 bits were not // all the same value. const auto affected_bits = IntT( ~((top_bit() >> shift) - 1) - ); + ); // e.g. shift = 1 => ~((0x80 >> 1) - 1) = ~(0x40 - 1) = ~0x3f = 0xc0, i.e. if shift is + // 1 then the top two bits are relevant to whether there was overflow. If they have the + // same value, i.e. are both 0 or are both 1, then there wasn't. Otherwise there was. status.overflow_flag = (destination & affected_bits) && (destination & affected_bits) != affected_bits; } }