Skip to content

Commit

Permalink
invalidate JIT blocks in ARM7 WVRAM when it's remapped
Browse files Browse the repository at this point in the history
  • Loading branch information
RSDuck committed Aug 21, 2022
1 parent d56219c commit 32609bb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/ARMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,34 @@ void InvalidateByAddr(u32 localAddr)

void CheckAndInvalidateITCM()
{
for (u32 i = 0; i < ITCMPhysicalSize; i+=16)
for (u32 i = 0; i < ITCMPhysicalSize; i+=512)
{
if (CodeIndexITCM[i / 512].Code & (1 << ((i & 0x1FF) / 16)))
if (CodeIndexITCM[i / 512].Code)
{
InvalidateByAddr(i | (ARMJIT_Memory::memregion_ITCM << 27));
// maybe using bitscan would be better here?
// The thing is that in densely populated sets
// The old fashioned way can actually be faster
for (u32 j = 0; j < 512; j += 16)
{
if (CodeIndexITCM[i / 512].Code & (1 << ((j & 0x1FF) / 16)))
InvalidateByAddr((i+j) | (ARMJIT_Memory::memregion_ITCM << 27));
}
}
}
}

void CheckAndInvalidateWVRAM(int bank)
{
u32 start = bank == 1 ? 0x20000 : 0;
for (u32 i = start; i < start+0x20000; i+=512)
{
if (CodeIndexARM7WVRAM[i / 512].Code)
{
for (u32 j = 0; j < 512; j += 16)
{
if (CodeIndexARM7WVRAM[i / 512].Code & (1 << ((j & 0x1FF) / 16)))
InvalidateByAddr((i+j) | (ARMJIT_Memory::memregion_VWRAM << 27));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ARMJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void DeInit();
void Reset();

void CheckAndInvalidateITCM();
void CheckAndInvalidateWVRAM(int bank);

void InvalidateByAddr(u32 pseudoPhysical);

Expand Down
3 changes: 3 additions & 0 deletions src/CP15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ void ARMv5::UpdateITCMSetting()
if (CP15Control & (1<<18))
{
ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F);
#ifdef JIT_ENABLED
FastBlockLookupSize = 0;
#endif
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string.h>
#include "NDS.h"
#include "GPU.h"
#include "ARMJIT.h"

#include "GPU2D_Soft.h"

Expand Down Expand Up @@ -653,6 +654,7 @@ void MapVRAM_CD(u32 bank, u8 cnt)
VRAMMap_ARM7[ofs] |= bankmask;
memset(VRAMDirty[bank].Data, 0xFF, sizeof(VRAMDirty[bank].Data));
VRAMSTAT |= (1 << (bank-2));
ARMJIT::CheckAndInvalidateWVRAM(ofs);
break;

case 3: // texture
Expand Down

0 comments on commit 32609bb

Please sign in to comment.