Emulator in flash using Alchemy; needs optimisation...

The Uzebox now have a fully functional emulator! Download and discuss it here.
lightfoot256
Posts: 119
Joined: Wed Jun 10, 2009 2:53 pm
Location: South Yorkshire, England
Contact:

Re: Emulator in flash using Alchemy; needs optimisation...

Post by lightfoot256 »

nebososo wrote:That's quite interesting ;) . Do you think any of those changes could be used on the C version as well? It runs like a slideshow on my netbook.
In preparation for working on sonic again I had fun getting the emulator to compile on OSX; seems the biggest hurdle is the way SDL has been designed to work on OSX with this whole SDLmain thing. Anyway I got it running and started looking at the optimisations I made to the flash version; I mainly just in-lined all the highly called methods and moved the while(100,000,000) loop into the exec function via a cycles argument to avoid all the fuction calls to exec (I did try inlining it but the linker whines :-p). Overall the cpu usage on my mac went from 110% down to 85-90% just from the inlines :-D.

When working on the flash version I wrote a script to convert the case statement in avr8 to a huge 65,536 switch statement with a case entry for each instruction and each instruction optimised to be as simple as possible; The alchemy compiler didn't like this at all and gave me lots of issues with memory leaks (the compiler was crashing :-p) but I haven't yet tried this on the original emulator.

Essentially my script (written in php :-p) created a tree of the switch statements and then basically ran through all 65536 instructions navigating the tree to find the lines of code that would be executed and then at the end constructed a huge switch statement is constructed with all of those lines; basically duplicating lots and lots of code. However...

After that it starts expanding lots of the macros in the emulator and replaces the "insn" value with the actual instruction value; from there soooo many optimisations can occur dropping things from a bunch of lines to r16 for example. If the switch statement doesn't work I'll just use a hard coded jump table; I just hope this version of gcc can cope with it... I think this will dramatically improve the performance of the emulator without really changing anything...
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Emulator in flash using Alchemy; needs optimisation...

Post by uze6666 »

Overall the cpu usage on my mac went from 110% down to 85-90% just from the inlines :-D.
Hi Chris, wow that 25% gain is really awesome. I would add this to the current emulator right away since this is quite significant.

-Uze
lightfoot256
Posts: 119
Joined: Wed Jun 10, 2009 2:53 pm
Location: South Yorkshire, England
Contact:

Re: Emulator in flash using Alchemy; needs optimisation...

Post by lightfoot256 »

I was under the impression -O3 did this automatically -- guess not;

I"ve worked with so many different compilers; quite amusing how different two binaries can be that came from the same source but ran through different compilers (gcc vs intel's for example);

I tend to inline all my methods out of habbit; speed always wins over space on todays machines (not on uzebox though :-p)
Post Reply