VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

Is it even feasable to combine dynamic recompiling with cycle-accuracy? As there needs to be a high amount of synchronization with hardware, dynamic recompiling in that case(as it deals with blocks of code) is probably pretty much impossible? Since the accuracy of the hardware has the effect of destroying any efficiency gain by blocks of code being recompiled?

Are there any good sources on optimizing x86 interpreting cycle-accurate CPU emulators? Afaik atm the heaviest part is mostly the many protection&debugging checks that are checked for each byte fetched/accessed from memory?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 4, by kode54

User metadata
Rank Member
Rank
Member

It should be possible. You just need to keep a note of the cycles elapsed by each compiled opcode. This need only be synchronized every branch or every hardware interaction. The cycle counting will be compiled into the dynamic code, just like the rest of the code.

Reply 2 of 4, by reenigne

User metadata
Rank Oldbie
Rank
Oldbie

I'm a little more sceptical than kode54. A given piece of code may take a different number of cycles to run depending on things like the phases of various clocks and counters, the state of the prefetch queue and bus when it starts, and even the values the code is operating on. So just keeping a count of elapsed cycles isn't enough. Not saying it's impossible but it's going to be really difficult.

Reply 3 of 4, by kode54

User metadata
Rank Member
Rank
Member

Well, I only mentioned keeping counts, because most N64 emulators around now use counters even in their recompiler mode, so they can keep accurate timers, since they need timers for interrupts and video frame timing. The only real thing in N64 emulation that's kind of wonky, and is better handled by some emulators, is RSP timing, since many of them just execute a whole RSP task list instantly instead of attempting to cycle time the RSP opcodes.

Reply 4 of 4, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie

I do not think it is do-able, in the sense that you will not really end up with both a faster emulator and a cycle-accurate one. At least not in the way other emulators use recompilation.

I took at stab at it too in CAPE. The best I could think of is to have DYNAREC for microcode (NOT 8086 instructions), which is what CAPE breaks down all instruction into. There is microcode for other parts of the CPU not just instructions like EA, BIU etc. All those "microcode" steps can be dynamically recompiled. However I am doubtful that the effort put in (which is considerable) would yield that much faster emulator.

That being said, it would be fun to try.

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/