mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-16 18:30:32 +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;
|
uint16_t partials = 0;
|
||||||
int result = carry_flag_;
|
int result = carry_flag_;
|
||||||
|
|
||||||
#define nibble(mask, limit, adjustment, carry) \
|
const auto nibble = [&](uint16_t mask, uint16_t limit, uint16_t adjustment, uint16_t carry) {
|
||||||
result += (a & mask) + (*operand & mask); \
|
result += (a & mask) + (*operand & mask);
|
||||||
partials += result & mask; \
|
partials += result & mask;
|
||||||
if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry;
|
if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry;
|
||||||
|
};
|
||||||
|
|
||||||
nibble(0x000f, 0x000a, 0x0006, 0x00010);
|
nibble(0x000f, 0x000a, 0x0006, 0x00010);
|
||||||
nibble(0x00f0, 0x00a0, 0x0060, 0x00100);
|
nibble(0x00f0, 0x00a0, 0x0060, 0x00100);
|
||||||
|
|
||||||
#undef nibble
|
|
||||||
|
|
||||||
overflow_result_ = uint8_t((partials ^ a) & (partials ^ *operand));
|
overflow_result_ = uint8_t((partials ^ a) & (partials ^ *operand));
|
||||||
set_nz(uint8_t(result));
|
set_nz(uint8_t(result));
|
||||||
carry_flag_ = (result >> 8) & 1;
|
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;
|
unsigned int borrow = carry_flag_ ^ 1;
|
||||||
const uint16_t decimal_result = uint16_t(a - *operand - borrow);
|
const uint16_t decimal_result = uint16_t(a - *operand - borrow);
|
||||||
|
|
||||||
#define nibble(mask, adjustment, carry) \
|
const auto nibble = [&](uint16_t mask, uint16_t adjustment, uint16_t carry) {
|
||||||
result += (a & mask) - (*operand & mask) - borrow; \
|
result += (a & mask) - (*operand & mask) - borrow;
|
||||||
if(result > mask) result -= adjustment; \
|
if(result > mask) result -= adjustment;
|
||||||
borrow = (result > mask) ? carry : 0; \
|
borrow = (result > mask) ? carry : 0;
|
||||||
result &= (carry - 1);
|
result &= (carry - 1);
|
||||||
|
};
|
||||||
|
|
||||||
nibble(0x000f, 0x0006, 0x00010);
|
nibble(0x000f, 0x0006, 0x00010);
|
||||||
nibble(0x00f0, 0x0060, 0x00100);
|
nibble(0x00f0, 0x0060, 0x00100);
|
||||||
|
|
||||||
#undef nibble
|
|
||||||
|
|
||||||
overflow_result_ = uint8_t((decimal_result ^ a) & (~decimal_result ^ *operand));
|
overflow_result_ = uint8_t((decimal_result ^ a) & (~decimal_result ^ *operand));
|
||||||
set_nz(uint8_t(result));
|
set_nz(uint8_t(result));
|
||||||
carry_flag_ = ((borrow >> 8)&1)^1;
|
carry_flag_ = ((borrow >> 8)&1)^1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user