Let the compiler decide what to inline

This commit is contained in:
Kevin Hamacher 2020-02-20 19:52:26 +01:00
parent 26f28cdb48
commit 76059f1e85
3 changed files with 1 additions and 55 deletions

View File

@ -15,7 +15,7 @@ const REG_N_L: usize = 5;
const REG_N_HL: usize = 6; const REG_N_HL: usize = 6;
const REG_N_A: usize = 7; const REG_N_A: usize = 7;
const REG_N_F: usize = 8; const REG_N_F: usize = 8;
const REG_NAMES: [&'static str; 9] = ["B", "C", "D", "E", "H", "L", "(HL)", "A", "F"]; const REG_NAMES: [&str; 9] = ["B", "C", "D", "E", "H", "L", "(HL)", "A", "F"];
const FLAG_Z: u8 = 1 << 7; const FLAG_Z: u8 = 1 << 7;
const FLAG_N: u8 = 1 << 6; const FLAG_N: u8 = 1 << 6;
@ -88,12 +88,10 @@ impl CPU {
} }
} }
#[inline]
fn read_byte(&self, addr: u16) -> u8 { fn read_byte(&self, addr: u16) -> u8 {
self.interconnect.read_byte(addr) self.interconnect.read_byte(addr)
} }
#[inline]
fn load_args(&mut self, num_args: u8) -> Args { fn load_args(&mut self, num_args: u8) -> Args {
match num_args { match num_args {
1 => { 1 => {
@ -112,7 +110,6 @@ impl CPU {
} }
} }
#[inline]
fn set_8bit_reg(&mut self, reg_id: usize, value: u8) { fn set_8bit_reg(&mut self, reg_id: usize, value: u8) {
// Make sure that we skip the (HL) part. // Make sure that we skip the (HL) part.
if reg_id == REG_N_A { if reg_id == REG_N_A {
@ -127,7 +124,6 @@ impl CPU {
} }
} }
#[inline]
fn get_8bit_reg(&self, reg_id: usize) -> u8 { fn get_8bit_reg(&self, reg_id: usize) -> u8 {
// Make sure that we skip the (HL) part. // Make sure that we skip the (HL) part.
if reg_id == REG_N_A { if reg_id == REG_N_A {
@ -142,7 +138,6 @@ impl CPU {
} }
} }
#[inline]
fn adc_r(&mut self, val: u8) { fn adc_r(&mut self, val: u8) {
let old: u8 = self.regs[REG_A]; let old: u8 = self.regs[REG_A];
let mut new: u8 = old; let mut new: u8 = old;
@ -162,7 +157,6 @@ impl CPU {
self.set_clear_flag(FLAG_H, ((old & 0x0F) + (val & 0x0F) + c) > 0x0F); self.set_clear_flag(FLAG_H, ((old & 0x0F) + (val & 0x0F) + c) > 0x0F);
} }
#[inline]
fn add_r(&mut self, val: u8) { fn add_r(&mut self, val: u8) {
let old: u8 = self.regs[REG_A]; let old: u8 = self.regs[REG_A];
let new: u8 = old.wrapping_add(val); let new: u8 = old.wrapping_add(val);
@ -175,7 +169,6 @@ impl CPU {
self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10); self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10);
} }
#[inline]
fn sbc_r(&mut self, val: u8) { fn sbc_r(&mut self, val: u8) {
let old: u8 = self.regs[REG_A]; let old: u8 = self.regs[REG_A];
let mut new: u8 = old as u8; let mut new: u8 = old as u8;
@ -199,7 +192,6 @@ impl CPU {
); );
} }
#[inline]
fn sub_r(&mut self, val: u8) { fn sub_r(&mut self, val: u8) {
let old: u8 = self.regs[REG_A]; let old: u8 = self.regs[REG_A];
let new: u8 = old.wrapping_sub(val); let new: u8 = old.wrapping_sub(val);
@ -212,7 +204,6 @@ impl CPU {
self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10); self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10);
} }
#[inline]
fn cp_r(&mut self, val: u8) { fn cp_r(&mut self, val: u8) {
let old: u8 = self.regs[REG_A]; let old: u8 = self.regs[REG_A];
let new: u8 = old.wrapping_sub(val); let new: u8 = old.wrapping_sub(val);
@ -224,7 +215,6 @@ impl CPU {
self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10); self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10);
} }
#[inline]
fn run_prefix_instruction(&mut self) { fn run_prefix_instruction(&mut self) {
let instruction = self.read_byte(self.ip); let instruction = self.read_byte(self.ip);
self.ip += 1; self.ip += 1;
@ -595,18 +585,15 @@ impl CPU {
} }
} }
#[inline]
fn get_pair_value(&self, a: usize, b: usize) -> u16 { fn get_pair_value(&self, a: usize, b: usize) -> u16 {
(self.get_8bit_reg(a) as u16) << 8 | self.get_8bit_reg(b) as u16 (self.get_8bit_reg(a) as u16) << 8 | self.get_8bit_reg(b) as u16
} }
#[inline]
fn set_pair_value(&mut self, a: usize, b: usize, value: u16) { fn set_pair_value(&mut self, a: usize, b: usize, value: u16) {
self.set_8bit_reg(a, (value >> 8) as u8); self.set_8bit_reg(a, (value >> 8) as u8);
self.set_8bit_reg(b, value as u8); self.set_8bit_reg(b, value as u8);
} }
#[inline]
fn call(&mut self, dst: u16) { fn call(&mut self, dst: u16) {
let ip = self.ip; let ip = self.ip;
self.push(ip); self.push(ip);
@ -614,7 +601,6 @@ impl CPU {
self.ip = dst; self.ip = dst;
} }
#[inline]
fn call_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { fn call_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 {
let dst = u16::try_from(self.load_args(2)).unwrap(); let dst = u16::try_from(self.load_args(2)).unwrap();
if self.debug { if self.debug {
@ -628,7 +614,6 @@ impl CPU {
} }
} }
#[inline]
fn ret_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { fn ret_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 {
if self.debug { if self.debug {
println!("RET {}", cond_str); println!("RET {}", cond_str);
@ -641,7 +626,6 @@ impl CPU {
} }
} }
#[inline]
fn jmp_r(&mut self, addr: u8) { fn jmp_r(&mut self, addr: u8) {
let off: i8 = addr as i8; let off: i8 = addr as i8;
if off < 0 { if off < 0 {
@ -651,7 +635,6 @@ impl CPU {
} }
} }
#[inline]
fn jmp_r_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { fn jmp_r_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 {
let t = u8::try_from(self.load_args(1)).unwrap(); let t = u8::try_from(self.load_args(1)).unwrap();
if self.debug { if self.debug {
@ -665,12 +648,10 @@ impl CPU {
} }
} }
#[inline]
fn jmp_p(&mut self, addr: u16) { fn jmp_p(&mut self, addr: u16) {
self.ip = addr; self.ip = addr;
} }
#[inline]
fn jmp_p_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { fn jmp_p_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 {
let t = u16::try_from(self.load_args(2)).unwrap(); let t = u16::try_from(self.load_args(2)).unwrap();
if self.debug { if self.debug {
@ -684,7 +665,6 @@ impl CPU {
} }
} }
#[inline]
fn rst(&mut self, val: u8) -> u8 { fn rst(&mut self, val: u8) -> u8 {
// Make sure this is correct. // Make sure this is correct.
if self.debug { if self.debug {
@ -694,7 +674,6 @@ impl CPU {
16 16
} }
#[inline]
fn pop_rr(&mut self, r1: usize, r2: usize) -> u8 { fn pop_rr(&mut self, r1: usize, r2: usize) -> u8 {
if self.debug { if self.debug {
println!("POP {}{}", REG_NAMES[r1], REG_NAMES[r2]); println!("POP {}{}", REG_NAMES[r1], REG_NAMES[r2]);
@ -704,7 +683,6 @@ impl CPU {
12 12
} }
#[inline]
fn push_rr(&mut self, r1: usize, r2: usize) -> u8 { fn push_rr(&mut self, r1: usize, r2: usize) -> u8 {
if self.debug { if self.debug {
println!("PUSH {}{}", REG_NAMES[r1], REG_NAMES[r2]); println!("PUSH {}{}", REG_NAMES[r1], REG_NAMES[r2]);
@ -714,7 +692,6 @@ impl CPU {
16 16
} }
#[inline]
fn dec_rr(&mut self, r1: usize, r2: usize) -> u8 { fn dec_rr(&mut self, r1: usize, r2: usize) -> u8 {
if self.debug { if self.debug {
println!("DEC {}{}", REG_NAMES[r1], REG_NAMES[r2]); println!("DEC {}{}", REG_NAMES[r1], REG_NAMES[r2]);
@ -725,7 +702,6 @@ impl CPU {
8 8
} }
#[inline]
fn inc_rr(&mut self, r1: usize, r2: usize) -> u8 { fn inc_rr(&mut self, r1: usize, r2: usize) -> u8 {
if self.debug { if self.debug {
println!("INC {}{}", REG_NAMES[r1], REG_NAMES[r2]); println!("INC {}{}", REG_NAMES[r1], REG_NAMES[r2]);
@ -736,20 +712,17 @@ impl CPU {
8 8
} }
#[inline]
fn push(&mut self, val: u16) { fn push(&mut self, val: u16) {
self.interconnect.write_word(self.sp - 2, val); self.interconnect.write_word(self.sp - 2, val);
self.sp -= 2; self.sp -= 2;
} }
#[inline]
fn pop(&mut self) -> u16 { fn pop(&mut self) -> u16 {
let v: u16 = self.interconnect.read_word(self.sp); let v: u16 = self.interconnect.read_word(self.sp);
self.sp += 2; self.sp += 2;
v v
} }
#[inline]
fn ld_r_r(&mut self, reg_dst: usize, reg_src: usize) -> u8 { fn ld_r_r(&mut self, reg_dst: usize, reg_src: usize) -> u8 {
if self.debug { if self.debug {
println!("LD {}, {}", REG_NAMES[reg_dst], REG_NAMES[reg_src]) println!("LD {}, {}", REG_NAMES[reg_dst], REG_NAMES[reg_src])
@ -763,7 +736,6 @@ impl CPU {
} }
} }
#[inline]
fn ld_r_v(&mut self, r: usize) -> u8 { fn ld_r_v(&mut self, r: usize) -> u8 {
let val = u8::try_from(self.load_args(1)).unwrap(); let val = u8::try_from(self.load_args(1)).unwrap();
if self.debug { if self.debug {
@ -777,7 +749,6 @@ impl CPU {
} }
} }
#[inline]
fn ld_rr_vv(&mut self, r1: usize, r2: usize) -> u8 { fn ld_rr_vv(&mut self, r1: usize, r2: usize) -> u8 {
let val = u16::try_from(self.load_args(2)).unwrap(); let val = u16::try_from(self.load_args(2)).unwrap();
if self.debug { if self.debug {
@ -787,7 +758,6 @@ impl CPU {
12 12
} }
#[inline]
fn reg_inc(&mut self, reg_id: usize) -> u8 { fn reg_inc(&mut self, reg_id: usize) -> u8 {
if self.debug { if self.debug {
println!("INC {}", REG_NAMES[reg_id]); println!("INC {}", REG_NAMES[reg_id]);
@ -801,7 +771,6 @@ impl CPU {
4 4
} }
#[inline]
fn add_rr_rr(&mut self, r1: usize, r2: usize, r3: usize, r4: usize) -> u8 { fn add_rr_rr(&mut self, r1: usize, r2: usize, r3: usize, r4: usize) -> u8 {
if self.debug { if self.debug {
println!( println!(
@ -824,7 +793,6 @@ impl CPU {
8 8
} }
#[inline]
fn reg_dec(&mut self, reg_id: usize) -> u8 { fn reg_dec(&mut self, reg_id: usize) -> u8 {
if self.debug { if self.debug {
println!("DEC {}", REG_NAMES[reg_id]); println!("DEC {}", REG_NAMES[reg_id]);
@ -840,7 +808,6 @@ impl CPU {
4 4
} }
#[inline]
fn ld_dref_rr_a(&mut self, r1: usize, r2: usize) -> u8 { fn ld_dref_rr_a(&mut self, r1: usize, r2: usize) -> u8 {
if self.debug { if self.debug {
println!("LD ({}{}), A", REG_NAMES[r1], REG_NAMES[r2]); println!("LD ({}{}), A", REG_NAMES[r1], REG_NAMES[r2]);
@ -851,17 +818,14 @@ impl CPU {
8 8
} }
#[inline]
fn set_flag(&mut self, flag: u8) { fn set_flag(&mut self, flag: u8) {
self.flags |= flag; self.flags |= flag;
} }
#[inline]
fn clear_flag(&mut self, flag: u8) { fn clear_flag(&mut self, flag: u8) {
self.flags &= !flag; self.flags &= !flag;
} }
#[inline]
fn set_clear_flag(&mut self, flag: u8, dep: bool) { fn set_clear_flag(&mut self, flag: u8, dep: bool) {
if dep { if dep {
self.set_flag(flag); self.set_flag(flag);
@ -870,7 +834,6 @@ impl CPU {
} }
} }
#[inline]
fn int_(&mut self, val: u8) { fn int_(&mut self, val: u8) {
if self.debug { if self.debug {
println!("INT {:02X}", val); println!("INT {:02X}", val);
@ -880,21 +843,18 @@ impl CPU {
self.call(val as u16); self.call(val as u16);
} }
#[inline]
fn ret(&mut self) { fn ret(&mut self) {
let new_ip: u16 = self.pop(); let new_ip: u16 = self.pop();
//self.dump_stack(); //self.dump_stack();
self.ip = new_ip; self.ip = new_ip;
} }
#[inline]
fn reti(&mut self) -> u8 { fn reti(&mut self) -> u8 {
self.ret(); self.ret();
self.ime = true; self.ime = true;
16 16
} }
#[inline]
fn handle_interrupt(&mut self, offset: u8, flag: u8) { fn handle_interrupt(&mut self, offset: u8, flag: u8) {
// Remove interrupt requested flag // Remove interrupt requested flag
let new_flag = self.interconnect.read_byte(0xFF0F) & !flag; let new_flag = self.interconnect.read_byte(0xFF0F) & !flag;

View File

@ -281,14 +281,12 @@ impl Display {
} }
} }
#[inline]
fn set_pixel(&mut self, x: u8, y: u8, color: sdl2::pixels::Color, origin: PixelOrigin) { fn set_pixel(&mut self, x: u8, y: u8, color: sdl2::pixels::Color, origin: PixelOrigin) {
let p = &mut self.pixels[(x as usize) + (y as usize) * GB_PIXELS_X]; let p = &mut self.pixels[(x as usize) + (y as usize) * GB_PIXELS_X];
p.color = color; p.color = color;
p.origin = origin; p.origin = origin;
} }
#[inline]
fn get_pixel_origin(&self, x: u8, y: u8) -> PixelOrigin { fn get_pixel_origin(&self, x: u8, y: u8) -> PixelOrigin {
self.pixels[(x as usize) + (y as usize) * GB_PIXELS_X].origin self.pixels[(x as usize) + (y as usize) * GB_PIXELS_X].origin
} }
@ -324,7 +322,6 @@ impl Display {
.expect("Rendering failed"); .expect("Rendering failed");
} }
#[inline]
pub fn vblank_interrupt(&mut self) -> bool { pub fn vblank_interrupt(&mut self) -> bool {
// Returns whether or not a vblank interrupt should be done // Returns whether or not a vblank interrupt should be done
// Yes, this is polling, and yes, this sucks. // Yes, this is polling, and yes, this sucks.
@ -336,7 +333,6 @@ impl Display {
} }
} }
#[inline]
pub fn stat_interrupt(&mut self) -> bool { pub fn stat_interrupt(&mut self) -> bool {
if self.stat_interrupt { if self.stat_interrupt {
self.stat_interrupt = false; self.stat_interrupt = false;
@ -346,7 +342,6 @@ impl Display {
} }
} }
#[inline]
pub fn write_byte(&mut self, addr: u16, val: u8) { pub fn write_byte(&mut self, addr: u16, val: u8) {
match addr { match addr {
0x8000..=0x9FFF => { 0x8000..=0x9FFF => {
@ -415,7 +410,6 @@ impl Display {
} }
} }
#[inline]
pub fn read_byte(&self, addr: u16) -> u8 { pub fn read_byte(&self, addr: u16) -> u8 {
match addr { match addr {
0x8000..=0x9FFF => { 0x8000..=0x9FFF => {
@ -467,7 +461,6 @@ impl Display {
BgMapAttributes(self.vram1[vram_offset]) BgMapAttributes(self.vram1[vram_offset])
} }
#[inline]
pub fn tick(&mut self, ticks: u16) { pub fn tick(&mut self, ticks: u16) {
self.status &= 0xFC; self.status &= 0xFC;
if self.control & CTRL_LCD_DISPLAY_ENABLE == 0 { if self.control & CTRL_LCD_DISPLAY_ENABLE == 0 {
@ -685,7 +678,6 @@ impl Display {
} }
} }
#[inline]
fn get_bg_window_tile_addr(&self, tile_id: u8) -> usize { fn get_bg_window_tile_addr(&self, tile_id: u8) -> usize {
if (self.control & CTRL_BG_WINDOW_TILE_DATA_SELECT) == CTRL_BG_WINDOW_TILE_DATA_SELECT { if (self.control & CTRL_BG_WINDOW_TILE_DATA_SELECT) == CTRL_BG_WINDOW_TILE_DATA_SELECT {
let base_addr = 0x0000; let base_addr = 0x0000;
@ -708,7 +700,6 @@ impl Display {
.unwrap(); .unwrap();
} }
#[inline]
fn renderscan(&mut self) { fn renderscan(&mut self) {
// Points to the background map offset to use. // Points to the background map offset to use.
let background_map: usize; let background_map: usize;

View File

@ -251,12 +251,10 @@ impl Interconnect {
TickResult::Continue TickResult::Continue
} }
#[inline]
pub fn is_boot_rom(&self) -> bool { pub fn is_boot_rom(&self) -> bool {
self.disable_bootrom == 0 self.disable_bootrom == 0
} }
#[inline]
pub fn read_byte(&self, addr: u16) -> u8 { pub fn read_byte(&self, addr: u16) -> u8 {
// TODO: Make this more beautiful. // TODO: Make this more beautiful.
// TODO: if some flag set, use bios, otherwise only use rom // TODO: if some flag set, use bios, otherwise only use rom
@ -315,7 +313,6 @@ impl Interconnect {
} }
} }
#[inline]
pub fn write_byte(&mut self, addr: u16, val: u8) { pub fn write_byte(&mut self, addr: u16, val: u8) {
// TODO: Make this more beautful // TODO: Make this more beautful
/* /*
@ -440,13 +437,11 @@ impl Interconnect {
} }
} }
#[inline]
pub fn write_word(&mut self, addr: u16, val: u16) { pub fn write_word(&mut self, addr: u16, val: u16) {
self.write_byte(addr, val as u8); self.write_byte(addr, val as u8);
self.write_byte(addr + 1, (val >> 8) as u8); self.write_byte(addr + 1, (val >> 8) as u8);
} }
#[inline]
pub fn read_word(&self, addr: u16) -> u16 { pub fn read_word(&self, addr: u16) -> u16 {
self.read_byte(addr) as u16 | (self.read_byte(addr + 1) as u16) << 8 self.read_byte(addr) as u16 | (self.read_byte(addr + 1) as u16) << 8
// (self.read_byte(addr) as u16) << 8 | (self.read_byte(addr + 1) as u16) // (self.read_byte(addr) as u16) << 8 | (self.read_byte(addr + 1) as u16)