From e46e42d89653a7e3b23b96f24322347d9e3378c3 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 9 Oct 2023 16:47:02 -0400 Subject: [PATCH] This is the same test either way around. --- .../Implementation/PerformImplementation.hpp | 8 +-- Numeric/Carry.hpp | 25 +++---- OSBindings/Mac/Clock SignalTests/8088Tests.mm | 70 +++++++++---------- .../Implementation/6502Implementation.hpp | 4 +- 4 files changed, 50 insertions(+), 57 deletions(-) diff --git a/InstructionSets/x86/Implementation/PerformImplementation.hpp b/InstructionSets/x86/Implementation/PerformImplementation.hpp index 1978a54a0..655a9aef2 100644 --- a/InstructionSets/x86/Implementation/PerformImplementation.hpp +++ b/InstructionSets/x86/Implementation/PerformImplementation.hpp @@ -409,7 +409,7 @@ void adc(IntT &destination, IntT source, Status &status) { const IntT result = destination + source + status.carry_bit(); status.carry = Numeric::carried_out() - 1>(destination, source, result); - status.auxiliary_carry = Numeric::carried_in(destination, source, result); + status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result); status.sign = result & top_bit(); status.zero = status.parity = result; status.overflow = overflow(destination, source, result); @@ -428,7 +428,7 @@ void add(IntT &destination, IntT source, Status &status) { const IntT result = destination + source; status.carry = Numeric::carried_out() - 1>(destination, source, result); - status.auxiliary_carry = Numeric::carried_in(destination, source, result); + status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result); status.sign = result & top_bit(); status.zero = status.parity = result; status.overflow = overflow(destination, source, result); @@ -447,7 +447,7 @@ void sbb(IntT &destination, IntT source, Status &status) { const IntT result = destination - source - status.carry_bit(); status.carry = Numeric::carried_out() - 1>(destination, source, result); - status.auxiliary_carry = Numeric::carried_in(destination, source, result); + status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result); status.sign = result & top_bit(); status.zero = status.parity = result; status.overflow = overflow(destination, source, result); @@ -466,7 +466,7 @@ void sub(IntT &destination, IntT source, Status &status) { const IntT result = destination - source; status.carry = Numeric::carried_out() - 1>(destination, source, result); - status.auxiliary_carry = Numeric::carried_in(destination, source, result); + status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result); status.sign = result & top_bit(); status.zero = status.parity = result; status.overflow = overflow(destination, source, result); diff --git a/Numeric/Carry.hpp b/Numeric/Carry.hpp index 4896220b9..2dbf86e54 100644 --- a/Numeric/Carry.hpp +++ b/Numeric/Carry.hpp @@ -11,7 +11,7 @@ namespace Numeric { -/// @returns @c true if there, from @c bit there was +/// @returns @c true if from @c bit there was: /// • carry after calculating @c lhs + @c rhs if @c is_add is true; or /// • borrow after calculating @c lhs - @c rhs if @c is_add is false; /// producing @c result. @@ -30,21 +30,14 @@ template bool carried_out(IntT lhs, IntT r } } -// ~carried_out<>(d, ~s, r) - -/// @returns @c true if there was carry into @c bit when @c source1 and @c source2 were added, producing @c result. -template bool carried_in(IntT lhs, IntT rhs, IntT result) { - // 0 and 0 or 1 and 1 => did if 1 - // 0 and 1 or 1 and 0 => did if 0 - if constexpr (!is_add) { - rhs = ~rhs; - } - const bool carry = IntT(1 << bit) & (lhs ^ rhs ^ result); - if constexpr (!is_add) { - return !carry; - } else { - return carry; - } +/// @returns @c true if there was carry into @c bit when computing either: +/// • @c lhs + @c rhs; or +/// • @c lhs - @c rhs; +/// producing @c result. +template bool carried_in(IntT lhs, IntT rhs, IntT result) { + // 0 and 0 or 1 and 1 => did if 1. + // 0 and 1 or 1 and 0 => did if 0. + return IntT(1 << bit) & (lhs ^ rhs ^ result); } } diff --git a/OSBindings/Mac/Clock SignalTests/8088Tests.mm b/OSBindings/Mac/Clock SignalTests/8088Tests.mm index aa2bb61de..00ab3b4b8 100644 --- a/OSBindings/Mac/Clock SignalTests/8088Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/8088Tests.mm @@ -278,30 +278,30 @@ struct FailedExecution { - (NSArray *)testFiles { NSString *path = [NSString stringWithUTF8String:TestSuiteHome]; NSSet *allowList = [NSSet setWithArray:@[ - @"37.json.gz", // AAA - @"3F.json.gz", // AAS - @"D4.json.gz", // AAM - @"D5.json.gz", // AAD - @"27.json.gz", // DAA - @"2F.json.gz", // DAS - - @"98.json.gz", // CBW - @"99.json.gz", // CWD - - // ESC - @"D8.json.gz", @"D9.json.gz", @"DA.json.gz", @"DB.json.gz", - @"DC.json.gz", @"DD.json.gz", @"DE.json.gz", @"DE.json.gz", - - // NOP - @"90.json.gz", - - // ADC - @"10.json.gz", @"11.json.gz", @"12.json.gz", @"13.json.gz", @"14.json.gz", @"15.json.gz", - @"80.2.json.gz", @"81.2.json.gz", @"83.2.json.gz", - - // ADD - @"00.json.gz", @"01.json.gz", @"02.json.gz", @"03.json.gz", @"04.json.gz", @"05.json.gz", - @"80.0.json.gz", @"81.0.json.gz", @"83.0.json.gz", +// @"37.json.gz", // AAA +// @"3F.json.gz", // AAS +// @"D4.json.gz", // AAM +// @"D5.json.gz", // AAD +// @"27.json.gz", // DAA +// @"2F.json.gz", // DAS +// +// @"98.json.gz", // CBW +// @"99.json.gz", // CWD +// +// // ESC +// @"D8.json.gz", @"D9.json.gz", @"DA.json.gz", @"DB.json.gz", +// @"DC.json.gz", @"DD.json.gz", @"DE.json.gz", @"DE.json.gz", +// +// // NOP +// @"90.json.gz", +// +// // ADC +// @"10.json.gz", @"11.json.gz", @"12.json.gz", @"13.json.gz", @"14.json.gz", @"15.json.gz", +// @"80.2.json.gz", @"81.2.json.gz", @"83.2.json.gz", +// +// // ADD +// @"00.json.gz", @"01.json.gz", @"02.json.gz", @"03.json.gz", @"04.json.gz", @"05.json.gz", +// @"80.0.json.gz", @"81.0.json.gz", @"83.0.json.gz", // SBB @"18.json.gz", @"19.json.gz", @"1A.json.gz", @"1B.json.gz", @"1C.json.gz", @"1D.json.gz", @@ -312,17 +312,17 @@ struct FailedExecution { @"80.5.json.gz", @"81.5.json.gz", @"83.5.json.gz", // AND - @"20.json.gz", @"21.json.gz", @"22.json.gz", @"23.json.gz", @"24.json.gz", @"25.json.gz", - @"80.4.json.gz", @"81.4.json.gz", @"83.4.json.gz", - - // CALL - @"E8.json.gz", @"FF.2.json.gz", - @"9A.json.gz", @"FF.3.json.gz", - - @"F8.json.gz", // CLC - @"FC.json.gz", // CLD - @"FA.json.gz", // CLI - @"F5.json.gz", // CMC +// @"20.json.gz", @"21.json.gz", @"22.json.gz", @"23.json.gz", @"24.json.gz", @"25.json.gz", +// @"80.4.json.gz", @"81.4.json.gz", @"83.4.json.gz", +// +// // CALL +// @"E8.json.gz", @"FF.2.json.gz", +// @"9A.json.gz", @"FF.3.json.gz", +// +// @"F8.json.gz", // CLC +// @"FC.json.gz", // CLD +// @"FA.json.gz", // CLI +// @"F5.json.gz", // CMC ]]; NSSet *ignoreList = nil; diff --git a/Processors/6502/Implementation/6502Implementation.hpp b/Processors/6502/Implementation/6502Implementation.hpp index caa9c71e5..b55b3596f 100644 --- a/Processors/6502/Implementation/6502Implementation.hpp +++ b/Processors/6502/Implementation/6502Implementation.hpp @@ -343,7 +343,7 @@ template void Proces // on a 6502 additional borrow isn't propagated but on a 65C02 it is. // This difference affects invalid BCD numbers only — valid numbers will // never be less than -9 so adding 10 will always generate carry. - if(!Numeric::carried_in(a_, operand_, result)) { + if(!Numeric::carried_in<4>(a_, operand_, result)) { if constexpr (is_65c02(personality)) { result += 0xfa; } else { @@ -390,7 +390,7 @@ template void Proces // // So if that carry already happened, fix up the bottom without permitting another; // otherwise permit the carry to happen (and check whether carry then rippled out of bit 7). - if(Numeric::carried_in(a_, operand_, result)) { + if(Numeric::carried_in<4>(a_, operand_, result)) { result = (result & 0xf0) | ((result + 0x06) & 0x0f); } else if((result & 0xf) > 0x9) { flags_.carry |= result >= 0x100 - 0x6;