From 3bd01e211e4252a1b6ae2728c6c8579fa18a5995 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Tue, 9 Jan 2018 23:30:51 +0000 Subject: [PATCH] Try to avoid so many virtual calls in the Z80 by hanging onto AF a little longer. Signed-off-by: Adrian Conlon --- Z80/inc/Z80.h | 6 +++--- Z80/src/Z80.cpp | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 63d7edc..a07dd23 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -302,9 +302,9 @@ namespace EightBit { static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0); - void executeCB(int x, int y, int z); - void executeED(int x, int y, int z, int p, int q); - void executeOther(int x, int y, int z, int p, int q); + void executeCB(uint8_t& a, uint8_t& f, int x, int y, int z); + void executeED(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q); + void executeOther(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q); static void increment(uint8_t& f, uint8_t& operand); static void decrement(uint8_t& f, uint8_t& operand); diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 7cf39d1..7791d5e 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -710,14 +710,18 @@ int EightBit::Z80::execute(const uint8_t opcode) { const auto p = decoded.p; const auto q = decoded.q; + auto& af = AF(); + auto& a = af.high; + auto& f = af.low; + auto prefixed = m_prefixCB || m_prefixED; if (LIKELY(!prefixed)) { - executeOther(x, y, z, p, q); + executeOther(a, f, x, y, z, p, q); } else { if (m_prefixCB) - executeCB(x, y, z); + executeCB(a, f, x, y, z); else if (m_prefixED) - executeED(x, y, z, p, q); + executeED(a, f, x, y, z, p, q); else UNREACHABLE; } @@ -728,9 +732,7 @@ int EightBit::Z80::execute(const uint8_t opcode) { return cycles(); } -void EightBit::Z80::executeCB(const int x, const int y, const int z) { - auto& a = A(); - auto& f = F(); +void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, const int z) { switch (x) { case 0: { // rot[y] r[z] auto operand = LIKELY(!m_displaced) ? R(z, a) : getByte(displacedAddress()); @@ -824,9 +826,7 @@ void EightBit::Z80::executeCB(const int x, const int y, const int z) { } } -void EightBit::Z80::executeED(const int x, const int y, const int z, const int p, const int q) { - auto& a = A(); - auto& f = F(); +void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, const int z, const int p, const int q) { switch (x) { case 0: case 3: // Invalid instruction, equivalent to NONI followed by NOP @@ -1060,9 +1060,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p } } -void EightBit::Z80::executeOther(const int x, const int y, const int z, const int p, const int q) { - auto& a = A(); - auto& f = F(); +void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int y, const int z, const int p, const int q) { switch (x) { case 0: switch (z) {