mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Eliminate nibble
macros.
This commit is contained in:
parent
95fac5dc13
commit
4838728521
@ -724,16 +724,15 @@ template <Operation operation> void Executor::perform(uint8_t *operand [[maybe_u
|
||||
uint16_t partials = 0;
|
||||
int result = carry_flag_;
|
||||
|
||||
#define nibble(mask, limit, adjustment, carry) \
|
||||
result += (a & mask) + (*operand & mask); \
|
||||
partials += result & mask; \
|
||||
if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry;
|
||||
const auto nibble = [&](uint16_t mask, uint16_t limit, uint16_t adjustment, uint16_t carry) {
|
||||
result += (a & mask) + (*operand & mask);
|
||||
partials += result & mask;
|
||||
if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry;
|
||||
};
|
||||
|
||||
nibble(0x000f, 0x000a, 0x0006, 0x00010);
|
||||
nibble(0x00f0, 0x00a0, 0x0060, 0x00100);
|
||||
|
||||
#undef nibble
|
||||
|
||||
overflow_result_ = uint8_t((partials ^ a) & (partials ^ *operand));
|
||||
set_nz(uint8_t(result));
|
||||
carry_flag_ = (result >> 8) & 1;
|
||||
@ -742,17 +741,16 @@ template <Operation operation> void Executor::perform(uint8_t *operand [[maybe_u
|
||||
unsigned int borrow = carry_flag_ ^ 1;
|
||||
const uint16_t decimal_result = uint16_t(a - *operand - borrow);
|
||||
|
||||
#define nibble(mask, adjustment, carry) \
|
||||
result += (a & mask) - (*operand & mask) - borrow; \
|
||||
if(result > mask) result -= adjustment; \
|
||||
borrow = (result > mask) ? carry : 0; \
|
||||
result &= (carry - 1);
|
||||
const auto nibble = [&](uint16_t mask, uint16_t adjustment, uint16_t carry) {
|
||||
result += (a & mask) - (*operand & mask) - borrow;
|
||||
if(result > mask) result -= adjustment;
|
||||
borrow = (result > mask) ? carry : 0;
|
||||
result &= (carry - 1);
|
||||
};
|
||||
|
||||
nibble(0x000f, 0x0006, 0x00010);
|
||||
nibble(0x00f0, 0x0060, 0x00100);
|
||||
|
||||
#undef nibble
|
||||
|
||||
overflow_result_ = uint8_t((decimal_result ^ a) & (~decimal_result ^ *operand));
|
||||
set_nz(uint8_t(result));
|
||||
carry_flag_ = ((borrow >> 8)&1)^1;
|
||||
|
Loading…
Reference in New Issue
Block a user