1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-19 08:31:11 +00:00

Makes value8_high/low and value16 branchless.

This commit is contained in:
Thomas Harte 2019-12-21 20:58:37 -05:00
parent 08f2877382
commit cf16f41939

View File

@ -53,7 +53,9 @@ struct Microcycle {
/// which by inspecting the low bit of the provided address. The RW line indicates a read. /// which by inspecting the low bit of the provided address. The RW line indicates a read.
static const int SelectByte = 1 << 0; static const int SelectByte = 1 << 0;
// Maintenance note: this is bit 0 to reduce the cost of getting a host-endian // Maintenance note: this is bit 0 to reduce the cost of getting a host-endian
// bytewise address. See implementation of host_endian_byte_address(). // bytewise address. The assumption that it is bit 0 is also used for branchless
// selection in a few places. See implementation of host_endian_byte_address(),
// value8_high(), value8_low() and value16().
/// Indicates that the address and both data select strobes are active. /// Indicates that the address and both data select strobes are active.
static const int SelectWord = 1 << 1; static const int SelectWord = 1 << 1;
@ -223,8 +225,8 @@ struct Microcycle {
this is a write cycle. this is a write cycle.
*/ */
forceinline uint16_t value16() const { forceinline uint16_t value16() const {
if(operation & SelectWord) return value->full; const uint16_t values[] = { value->full, uint16_t((value->halves.low << 8) | value->halves.low) };
return uint16_t((value->halves.low << 8) | value->halves.low); return values[operation & SelectByte];
} }
/*! /*!
@ -232,11 +234,8 @@ struct Microcycle {
@c 0xff otherwise. Assumes this is a write cycle. @c 0xff otherwise. Assumes this is a write cycle.
*/ */
forceinline uint8_t value8_high() const { forceinline uint8_t value8_high() const {
if(operation & SelectWord) { const uint8_t values[] = { uint8_t(value->full >> 8), value->halves.low};
return uint8_t(value->full >> 8); return values[operation & SelectByte];
}
return value->halves.low;
} }
/*! /*!
@ -244,11 +243,8 @@ struct Microcycle {
@c 0xff otherwise. Assumes this is a write cycle. @c 0xff otherwise. Assumes this is a write cycle.
*/ */
forceinline uint8_t value8_low() const { forceinline uint8_t value8_low() const {
if(operation & SelectWord) { const uint8_t values[] = { uint8_t(value->full), value->halves.low};
return uint8_t(value->full); return values[operation & SelectByte];
}
return value->halves.low;
} }
/*! /*!