mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Reduce ADD/ADC/SUB/SBB repetition.
This commit is contained in:
parent
7753497a93
commit
4a803e2d43
@ -400,34 +400,15 @@ inline void das(uint8_t &al, Status &status) {
|
||||
status.zero = status.parity = al;
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
void adc(IntT &destination, IntT source, Status &status) {
|
||||
/*
|
||||
DEST ← DEST + SRC + CF;
|
||||
*/
|
||||
/*
|
||||
The OF, SF, ZF, AF, CF, and PF flags are set according to the result.
|
||||
*/
|
||||
const IntT result = destination + source + status.carry_bit<IntT>();
|
||||
|
||||
status.carry = Numeric::carried_out<true, bit_size<IntT>() - 1>(destination, source, result);
|
||||
status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result);
|
||||
status.sign = result & top_bit<IntT>();
|
||||
status.zero = status.parity = result;
|
||||
status.overflow = overflow<true, IntT>(destination, source, result);
|
||||
|
||||
destination = result;
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
template <bool with_carry, typename IntT>
|
||||
void add(IntT &destination, IntT source, Status &status) {
|
||||
/*
|
||||
DEST ← DEST + SRC;
|
||||
DEST ← DEST + SRC [+ CF];
|
||||
*/
|
||||
/*
|
||||
The OF, SF, ZF, AF, CF, and PF flags are set according to the result.
|
||||
*/
|
||||
const IntT result = destination + source;
|
||||
const IntT result = destination + source + (with_carry ? status.carry_bit<IntT>() : 0);
|
||||
|
||||
status.carry = Numeric::carried_out<true, bit_size<IntT>() - 1>(destination, source, result);
|
||||
status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result);
|
||||
@ -438,34 +419,15 @@ void add(IntT &destination, IntT source, Status &status) {
|
||||
destination = result;
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
void sbb(IntT &destination, IntT source, Status &status) {
|
||||
/*
|
||||
DEST ← DEST - (SRC + CF);
|
||||
*/
|
||||
/*
|
||||
The OF, SF, ZF, AF, CF, and PF flags are set according to the result.
|
||||
*/
|
||||
const IntT result = destination - source - status.carry_bit<IntT>();
|
||||
|
||||
status.carry = Numeric::carried_out<false, bit_size<IntT>() - 1>(destination, source, result);
|
||||
status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result);
|
||||
status.sign = result & top_bit<IntT>();
|
||||
status.zero = status.parity = result;
|
||||
status.overflow = overflow<false, IntT>(destination, source, result);
|
||||
|
||||
destination = result;
|
||||
}
|
||||
|
||||
template <bool write_back, typename IntT>
|
||||
template <bool with_borrow, bool write_back, typename IntT>
|
||||
void sub(IntT &destination, IntT source, Status &status) {
|
||||
/*
|
||||
DEST ← DEST - SRC;
|
||||
DEST ← DEST - (SRC [+ CF]);
|
||||
*/
|
||||
/*
|
||||
The OF, SF, ZF, AF, CF, and PF flags are set according to the result.
|
||||
*/
|
||||
const IntT result = destination - source;
|
||||
const IntT result = destination - source - (with_borrow ? status.carry_bit<IntT>() : 0);
|
||||
|
||||
status.carry = Numeric::carried_out<false, bit_size<IntT>() - 1>(destination, source, result);
|
||||
status.auxiliary_carry = Numeric::carried_in<4>(destination, source, result);
|
||||
@ -971,12 +933,12 @@ template <
|
||||
case Operation::HLT: flow_controller.halt(); return;
|
||||
case Operation::WAIT: flow_controller.wait(); return;
|
||||
|
||||
case Operation::ADC: Primitive::adc(destination(), source(), status); break;
|
||||
case Operation::ADD: Primitive::add(destination(), source(), status); break;
|
||||
case Operation::SBB: Primitive::sbb(destination(), source(), status); break;
|
||||
case Operation::SUB: Primitive::sub<true>(destination(), source(), status); break;
|
||||
case Operation::CMP: Primitive::sub<false>(destination(), source(), status); break;
|
||||
case Operation::TEST: Primitive::test(destination(), source(), status); break;
|
||||
case Operation::ADC: Primitive::add<true>(destination(), source(), status); break;
|
||||
case Operation::ADD: Primitive::add<false>(destination(), source(), status); break;
|
||||
case Operation::SBB: Primitive::sub<true, true>(destination(), source(), status); break;
|
||||
case Operation::SUB: Primitive::sub<false, true>(destination(), source(), status); break;
|
||||
case Operation::CMP: Primitive::sub<false, false>(destination(), source(), status); break;
|
||||
case Operation::TEST: Primitive::test(destination(), source(), status); break;
|
||||
|
||||
// TODO: all the below could call a common registers getter?
|
||||
case Operation::MUL:
|
||||
|
@ -297,7 +297,7 @@ struct FailedExecution {
|
||||
@"DC.json.gz", @"DD.json.gz", @"DE.json.gz", @"DE.json.gz",
|
||||
|
||||
// Untested: HLT, WAIT
|
||||
|
||||
*/
|
||||
// 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",
|
||||
@ -313,7 +313,7 @@ struct FailedExecution {
|
||||
// SUB
|
||||
@"28.json.gz", @"29.json.gz", @"2A.json.gz", @"2B.json.gz", @"2C.json.gz", @"2D.json.gz",
|
||||
@"80.5.json.gz", @"81.5.json.gz", @"83.5.json.gz",
|
||||
|
||||
/*
|
||||
// MUL
|
||||
@"F6.4.json.gz", @"F7.4.json.gz",
|
||||
|
||||
@ -413,9 +413,9 @@ struct FailedExecution {
|
||||
*/
|
||||
|
||||
// CMP
|
||||
// @"38.json.gz", @"39.json.gz", @"3A.json.gz",
|
||||
// @"3B.json.gz", @"3C.json.gz", @"3D.json.gz",
|
||||
// @"80.7.json.gz", @"81.7.json.gz", @"83.7.json.gz",
|
||||
@"38.json.gz", @"39.json.gz", @"3A.json.gz",
|
||||
@"3B.json.gz", @"3C.json.gz", @"3D.json.gz",
|
||||
@"80.7.json.gz", @"81.7.json.gz", @"83.7.json.gz",
|
||||
|
||||
// TEST
|
||||
// @"84.json.gz", @"85.json.gz",
|
||||
@ -423,9 +423,9 @@ struct FailedExecution {
|
||||
// @"F6.0.json.gz", @"F7.0.json.gz",
|
||||
|
||||
// XCHG
|
||||
@"86.json.gz", @"87.json.gz",
|
||||
@"91.json.gz", @"92.json.gz", @"93.json.gz", @"94.json.gz",
|
||||
@"95.json.gz", @"96.json.gz", @"97.json.gz",
|
||||
// @"86.json.gz", @"87.json.gz",
|
||||
// @"91.json.gz", @"92.json.gz", @"93.json.gz", @"94.json.gz",
|
||||
// @"95.json.gz", @"96.json.gz", @"97.json.gz",
|
||||
|
||||
// TODO: XLAT
|
||||
// TODO: SALC, SETMO, SETMOC
|
||||
|
Loading…
Reference in New Issue
Block a user