From cf16f4193976b57ce0e3fbdbebd5072d32bf11db Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 21 Dec 2019 20:58:37 -0500 Subject: [PATCH] Makes value8_high/low and value16 branchless. --- Processors/68000/68000.hpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Processors/68000/68000.hpp b/Processors/68000/68000.hpp index 8bd61227a..25fa263f1 100644 --- a/Processors/68000/68000.hpp +++ b/Processors/68000/68000.hpp @@ -53,7 +53,9 @@ struct Microcycle { /// which by inspecting the low bit of the provided address. The RW line indicates a read. static const int SelectByte = 1 << 0; // 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. static const int SelectWord = 1 << 1; @@ -223,8 +225,8 @@ struct Microcycle { this is a write cycle. */ forceinline uint16_t value16() const { - if(operation & SelectWord) return value->full; - return uint16_t((value->halves.low << 8) | value->halves.low); + const uint16_t values[] = { value->full, 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. */ forceinline uint8_t value8_high() const { - if(operation & SelectWord) { - return uint8_t(value->full >> 8); - } - - return value->halves.low; + const uint8_t values[] = { uint8_t(value->full >> 8), value->halves.low}; + return values[operation & SelectByte]; } /*! @@ -244,11 +243,8 @@ struct Microcycle { @c 0xff otherwise. Assumes this is a write cycle. */ forceinline uint8_t value8_low() const { - if(operation & SelectWord) { - return uint8_t(value->full); - } - - return value->halves.low; + const uint8_t values[] = { uint8_t(value->full), value->halves.low}; + return values[operation & SelectByte]; } /*!