Next Generation Emulation banner

1 - 4 of 4 Posts

·
Registered
Joined
·
59 Posts
Discussion Starter #1 (Edited)
clockTicks calculation in latest version arm-new.h consume too much CPU power?

I didn't have experiences in emulator programming, so my question may be wrong or even don't make sense. But some point in arm cpu emulation confuse me a lot, so I post this question.

In comparison with v1.72, the major enhancement of latest version "arm-new.h" is instruction prefetch and more accurate clock ticks calculation (even includes clocks used by instruction fetch and data fetch).

My questions are:

(1) The inline functions to calcuate clocks used by instruction fetch and data feth are sort of complex in comparison with the instruction emulation it self. Almost every instruction need call once even twice one of the following functions.

Doesn't this a little too expensive?

inline int codeTicksAccessSeq32(u32 address) // ARM SEQ
{
int addr = (address>>24)&15;

if ((addr>=0x08) && (addr<=0x0D))
{
if ((!(busPrefetch)) && (busPrefetchEnable) && (busPrefetchCount))
{
busPrefetchCount-=1;
return 0;
}
else if (busPrefetch)
{
busPrefetchCount-=2;
return 0;
}
else
return memoryWaitSeq32[addr];
}
else if (addr!=2)
{
return memoryWaitSeq32[addr];
}
else
{
return memoryWaitSeq32[addr] + 4;
}
}
inline int dataTicksAccessSeq32(u32 address)// DATA 32bits SEQ
{
int addr = (address>>24)&15;
int value = memoryWaitSeq32[addr]+1;

if ((addr>=0x08) && (addr<=0x0E))
{
busPrefetchCount=0;
busPrefetch=false;
}
else
{
// if ((addr>=0x05) && (addr<=0x07))
// {
// bool blank = (((DISPSTAT | (DISPSTAT>>1))&1==1) ? true : false);
// bool pixelDrawing = (((lcdTicks+40-clockTicks) & 3) == 0 ? true : false);
// value += ((!blank && pixelDrawing) ? videoMemoryWait[addr] : 0);
// }
busPrefetchCount+= value+1;
}

return value;
}
(2) Most CPU hardware has an internal instruction queue and prefetch instructions is done by hardware circuit to increase CPU speed. But in emulated CPU, no matter prefetched instruction hit or not, instruction prefetch mechanism only add loading to PC's CPU. Why bother to emulated this hardware feature?

(3) If my first question stands, then are prefetch mechanism and clock calculation the major reasons to make latest version VBA much slower than VBA 1.72?

(4) What's the major differences due to these enhancements when running GBA games?
 

·
Registered
Joined
·
50 Posts
As I'm the person who added the bus prefetch emulation to VBA, I'll try to answer correctly ;)

(1) : Yes, the inline function are quite big & 'complex' now (even worse to look at with my latest changes, not uploaded to CVS yet)... But I've found no other way to emulate the bus prefetch properly :/

(2) & (4) : you'll be surprised to see the number of games that 'need' this feature to be emulated correctly. 2 cases where you can see its effects on games :
-Wai Wai Racing intro. Depending of your clockticks settings, the intro gfx will run faster or slower. Without the bus prefetch buffer (ie. on 1.7.2), the whole intro is like 5~10 seconds slower on VBA than on the GBA. With it, it's like 1~2 second slower...
- Advance Wars 2 (& Hamtaro & Oojisama Tennis 2003 & Breath of Fire 3...) : they are the main reason I added bus prefetch buffer actually. Hamtaro would not run correctly is the clockticks are too low, and AW2 and Oojisama 2003 would not run correctly if they are too big. Also, BoF3 would have some underwater gfx bug if the clockticks are too high. So the only way I found to make everything work is to add bus prefetch emulation. Without it, I'll had to put strange (=totaly unacurrate) clockticks settings, which might have broken other things, and which would have in any cases not given a 'accurate' emulation. With an 'accurate' bus prefetch setting emulation, I'm almost certain I have a correct fix for all these games (which are actually fixed now).

(3) : I don't think they are the main reason of the slowdown. I'm saying that because, when I added the bus prefetch emulation, I also made some changes to 'simplify' cpuLoop, and I ended overloading it too much (I kinda suck in programming) :/
Yesterday I made some new changes, to simplify cpuLoop (back to the level it was in 1.7.2), and the emu speed seems to be back to a good level.

I'll upload my latest changes to CVS when some of the dev team has reviewed them, so you'll be able to see speed issues should be gone ;)
 

·
Registered
Joined
·
59 Posts
Discussion Starter #3
pokemonhacker_ said:
As I'm the person who added the bus prefetch emulation to VBA, I'll try to answer correctly ;)
......
Thanks for your answer and can't wait to see your latest progress.

best regards,
Suanyuan
 
1 - 4 of 4 Posts
Top