From f385752705de73b04cbbda735a71f14c19e241a6 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Fri, 1 Feb 2013 00:33:30 -0500 Subject: memcpy vs memmove: memmove correctly handles overlapping source and destination memory buffers, but is slower than memcpy in many implementations. When memory buffers don't overlap, memcpy may be more efficient. The DS2 SDK is such an implementation, so change many memmoves into memcpys. --- source/apu.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source/apu.cpp') diff --git a/source/apu.cpp b/source/apu.cpp index 3c1a5d3..d60cc75 100644 --- a/source/apu.cpp +++ b/source/apu.cpp @@ -177,8 +177,12 @@ void S9xResetAPU () ZeroMemory (IAPU.CachedSamples, 0x40000); ZeroMemory (APU.OutPorts, 4); IAPU.DirectPage = IAPU.RAM; - memmove (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM)); - memmove (APU.ExtraRAM, APUROM, sizeof (APUROM)); + // memmove converted: Different mallocs [Neb] + // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb] + memcpy (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM)); + // memmove converted: Different mallocs [Neb] + // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb] + memcpy (APU.ExtraRAM, APUROM, sizeof (APUROM)); IAPU.PC = IAPU.RAM + IAPU.RAM [0xfffe] + (IAPU.RAM [0xffff] << 8); APU.Cycles = 0; IAPU.Registers.YA.W = 0; @@ -874,7 +878,9 @@ void S9xSetAPUControl (uint8 byte) { if (!APU.ShowROM) { - memmove (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM)); + // memmove converted: Different mallocs [Neb] + // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb] + memcpy (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM)); APU.ShowROM = TRUE; } } @@ -883,7 +889,9 @@ void S9xSetAPUControl (uint8 byte) if (APU.ShowROM) { APU.ShowROM = FALSE; - memmove (&IAPU.RAM [0xffc0], APU.ExtraRAM, sizeof (APUROM)); + // memmove converted: Different mallocs [Neb] + // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb] + memcpy (&IAPU.RAM [0xffc0], APU.ExtraRAM, sizeof (APUROM)); } } IAPU.RAM [0xf1] = byte; -- cgit v1.2.3 From 5e3426d0d26bb25810aca6593416ac0125ea6e8f Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Wed, 6 Feb 2013 19:07:39 -0500 Subject: Remove 320 KiB of memory allocations in APU emulation that were completely unused but constantly re-zeroed. Frees up 320 KiB for other uses, and saves ~4 milliseconds at emulator startup, when resetting the APU and when loading a new game. --- source/apu.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'source/apu.cpp') diff --git a/source/apu.cpp b/source/apu.cpp index d60cc75..769d2bc 100644 --- a/source/apu.cpp +++ b/source/apu.cpp @@ -116,18 +116,14 @@ void S9xTraceSoundDSP (const char *s, int i1 = 0, int i2 = 0, int i3 = 0, bool8 S9xInitAPU () { IAPU.RAM = (uint8 *) malloc (0x10000); - IAPU.ShadowRAM = (uint8 *) malloc (0x10000); - IAPU.CachedSamples = (uint8 *) malloc (0x40000); - if (!IAPU.RAM || !IAPU.ShadowRAM || !IAPU.CachedSamples) + if (!IAPU.RAM) { S9xDeinitAPU (); return (FALSE); } memset(IAPU.RAM, 0, 0x10000); - memset(IAPU.ShadowRAM, 0, 0x10000); - memset(IAPU.CachedSamples, 0, 0x40000); return (TRUE); } @@ -139,16 +135,6 @@ void S9xDeinitAPU () free ((char *) IAPU.RAM); IAPU.RAM = NULL; } - if (IAPU.ShadowRAM) - { - free ((char *) IAPU.ShadowRAM); - IAPU.ShadowRAM = NULL; - } - if (IAPU.CachedSamples) - { - free ((char *) IAPU.CachedSamples); - IAPU.CachedSamples = NULL; - } } EXTERN_C uint8 APUROM [64]; @@ -171,10 +157,7 @@ void S9xResetAPU () { memcpy(IAPU.RAM+(i<<8), IAPU.RAM, 0x100); } - - memcpy (IAPU.ShadowRAM, IAPU.RAM, 0x10000); - ZeroMemory (IAPU.CachedSamples, 0x40000); ZeroMemory (APU.OutPorts, 4); IAPU.DirectPage = IAPU.RAM; // memmove converted: Different mallocs [Neb] -- cgit v1.2.3