From 4386509f018f2dff87364e2fe9fa88372b3e11d4 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 21 Apr 2020 09:18:05 -0500 Subject: [PATCH] NesHawk - about a 5-10% speedp by using AggressiveInlining. Performance sensitive methods were analyzed, and I only added it to methods that failed inlining only due to the 32 IL byte limit but still reasonably sized. This attribute only lifts the 32 byte limit, it's important to do this analysis and not just apply this attribute with research. --- BizHawk.Emulation.Cores/CPUs/MOS 6502X/Execute.cs | 5 ++++- BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs | 6 ++++++ BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs | 4 ++++ BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/CPUs/MOS 6502X/Execute.cs b/BizHawk.Emulation.Cores/CPUs/MOS 6502X/Execute.cs index c2b2dfe528..0b545341be 100644 --- a/BizHawk.Emulation.Cores/CPUs/MOS 6502X/Execute.cs +++ b/BizHawk.Emulation.Cores/CPUs/MOS 6502X/Execute.cs @@ -1,6 +1,7 @@ //http://nesdev.parodius.com/6502_cpu.txt using System; +using System.Runtime.CompilerServices; using BizHawk.Common.NumberExtensions; using BizHawk.Emulation.Common; @@ -2708,6 +2709,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502 rdy_freeze = true; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] void ExecuteOneRetry() { //don't know whether this system is any faster. hard to get benchmarks someone else try it? @@ -2965,6 +2967,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502 } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ExecuteOne() { // total cycles now increments every time a cycle is called to accurately count during RDY @@ -2977,7 +2980,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502 if (!rdy_freeze) mi++; - } //ExecuteOne + } public bool AtInstructionStart() { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs index ab7a45787a..4f2fcf2dac 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs @@ -11,6 +11,7 @@ // TODO - refactor length counter to be separate component using System; +using System.Runtime.CompilerServices; using BizHawk.Common; using BizHawk.Common.NumberExtensions; @@ -258,6 +259,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Run() { if (env_constant == 1) @@ -458,6 +460,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES len_cnt--; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Run() { if (env_constant == 1) @@ -584,6 +587,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public int Debug_PeriodValue => timer_cnt; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Run() { // when clocked by timer, seq steps forward @@ -705,6 +709,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.EndSection(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Run() { if (timer > 0) timer--; @@ -1215,6 +1220,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES int pending_length_change; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunOneFirst() { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs index 20ec85a9a0..dc70bb86ad 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs @@ -7,6 +7,7 @@ //}; using System; +using System.Runtime.CompilerServices; using BizHawk.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES @@ -184,11 +185,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES v &= 1; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int get_ntread() { return 0x2000 | (v << 0xB) | (h << 0xA) | (vt << 5) | ht; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int get_2007access() { return ((fv & 3) << 0xC) | (v << 0xB) | (h << 0xA) | (vt << 5) | ht; @@ -200,6 +203,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES //are used in the diagram to represent the right-shift position amount to //apply to the data read from the attribute data (a is always 0). This is why //you only see bits 0 and 1 used off the read attribute data in the diagram. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int get_atread() { return 0x2000 | (v << 0xB) | (h << 0xA) | 0x3C0 | ((vt & 0x1C) << 1) | ((ht & 0x1C) >> 2); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs index 0a0c8c07d6..4e9a3a988e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs @@ -2,6 +2,7 @@ using BizHawk.Common; using BizHawk.Common.NumberExtensions; +using System.Runtime.CompilerServices; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -78,12 +79,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } //address line 3 relates to the pattern table fetch occuring (the PPU always makes them in pairs). + [MethodImpl(MethodImplOptions.AggressiveInlining)] private int get_ptread(int par) { int hi = reg_2000.bg_pattern_hi; return (hi << 0xC) | (par << 0x4) | ppur.fv; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] void Read_bgdata(int cycle, int i) { switch (cycle)