From bf601404fabd84dd54b1966de7fe6a4c376272c9 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Mon, 5 Oct 2020 23:19:00 -0700 Subject: [PATCH] Optimize cartridge Bus reads The `if let Some(gpio) = &self.gpio` causes a memory read of `self.gpio` for every Bus::read/write_16. It is better to reverse the order since `is_gpio_access` does not generate and memory reads and thus less costly. Former-commit-id: bcce7d9c3a2b159a7f6b291d7b08ccf9c4d0db14 Former-commit-id: 69c12db503c9e612faa7cd8a57f6d862694c8370 --- core/src/cartridge/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/cartridge/mod.rs b/core/src/cartridge/mod.rs index 13c5dc3..30ea04d 100644 --- a/core/src/cartridge/mod.rs +++ b/core/src/cartridge/mod.rs @@ -85,8 +85,8 @@ impl Bus for Cartridge { } fn read_16(&self, addr: u32) -> u16 { - if let Some(gpio) = &self.gpio { - if is_gpio_access(addr) { + if is_gpio_access(addr) { + if let Some(gpio) = &self.gpio { if !(gpio.is_readable()) { warn!("trying to read GPIO when reads are not allowed"); } @@ -116,8 +116,8 @@ impl Bus for Cartridge { } fn write_16(&mut self, addr: u32, value: u16) { - if let Some(gpio) = &mut self.gpio { - if is_gpio_access(addr) { + if is_gpio_access(addr) { + if let Some(gpio) = &mut self.gpio { gpio.write(addr & 0x1ff_ffff, value); return; }