Neo TeAm Forum

The 9th. NEO Project for SNES => The 9th. NEO Project for SNES Dev kit. => SNES development section => Topic started by: mic_ on April 11, 2010, 07:16:47 PM

Title: 65816 code optimization
Post by: mic_ on April 11, 2010, 07:16:47 PM
Download link: http://jiggawatt.org/badc0de/optimore-816r1.zip

I wasn't quite happy with the way the 816-opt script that comes with SNESC was optimizing the code, because I felt that there was so much more it could do. So I put together my own optimizer based on a set of pattern matching-based code optimizers that I had written a few years ago.

The way you should use it is to put it after the Python script in the build chain. That is, something like this:

..\bin\816-tcc.exe -Wall -I../include -o main.ps -c main.c

..\bin\816-opt.py main.ps > main.s

optimore-816.exe main.s mainopt.s

..\bin\wla-65816.exe -io mainopt.s main.obj


It's Windows-only for the time being (sorry about that). Although the source code should run on Linux/BSD/OSX if you have the right tools installed.


Title: Re: 65816 code optimization
Post by: Dr.neo on April 11, 2010, 08:47:13 PM
mic_ you keep to did the great job always  ~sm-55.gif~.gif
Title: Re: 65816 code optimization
Post by: Conle on April 12, 2010, 12:27:25 AM
 :P .......... (http://www.neoflash.com/forum/Smileys/classic/rolleyes.gif)
Title: Re: 65816 code optimization
Post by: ChillyWilly on April 12, 2010, 01:38:34 AM
Maybe you could (eventually) work your optimizations into the python script. Then you could send the update back to the guy maintaining the snes-sdk. In any case, great work!  8)
Title: Re: 65816 code optimization
Post by: mic_ on April 12, 2010, 02:35:12 AM
I really don't know that much Python. It was much easier to re-use my old code and just add new patterns to it to fit the output from tcc-816. Anyway, I noticed a couple of small in bugs in my patterns (a few instructions were removed that shouldn't be removed). I'll hopefully have it fixed by the time I'm ready to release the C menu.
Title: Re: 65816 code optimization
Post by: mic_ on April 15, 2010, 07:52:31 PM
I've uploaded a slightly updated version (which is the one I used for the latest version of the Myth menu). This time I've also included a binary for Linux (32-bit).

Download link: http://jiggawatt.org/badc0de/optimore-816r2.zip
Title: Re: 65816 code optimization
Post by: AndiNo on June 23, 2010, 10:14:06 PM
Nice to see this! Are you using the SDK now, too?
Can you give some numbers by what amount your code optimizes better than the old?
Title: Re: 65816 code optimization
Post by: mic_ on June 24, 2010, 05:53:00 AM
Nice to see this! Are you using the SDK now, too?
Can you give some numbers by what amount your code optimizes better than the old?

Yeah I've been using the SNESSDK for a few months for writing the SNES Myth menu. Here are some optimization statistics from building menu:


C:\snesdev\SNES SDK r67 Win32\NeoMythMenu>tools\optimore-816 main.s mainopt.s
Done! 636 lines removed.

C:\snesdev\SNES SDK r67 Win32\NeoMythMenu>tools\optimore-816 navigation.s navigo
pt.s
Done! 1047 lines removed.

C:\snesdev\SNES SDK r67 Win32\NeoMythMenu>tools\optimore-816 game_genie.s ggopt.
s
Done! 70 lines removed.

C:\snesdev\SNES SDK r67 Win32\NeoMythMenu>tools\optimore-816 action_replay.s aro
pt.s
Done! 19 lines removed.

C:\snesdev\SNES SDK r67 Win32\NeoMythMenu>tools\optimore-816 ppuc.s ppucopt.s
Done! 47 lines removed.


I can't really give a comparison with the Python script that comes with the SNESSDK since my optimizer isn't meant to replace it; they're meant to be used together.
Title: Re: 65816 code optimization
Post by: AndiNo on June 24, 2010, 03:58:27 PM
This sounds really nice! Although I can't really understand why you use the SDK if you are so proficient with assembly :)
Title: Re: 65816 code optimization
Post by: mic_ on June 24, 2010, 04:07:36 PM
Mainly to make it easier to get the SD card access code into the menu. The speed-critical stuff is still written in assembly.
Title: Re: 65816 code optimization
Post by: ChillyWilly on June 25, 2010, 05:07:06 AM
Mainly to make it easier to get the SD card access code into the menu. The speed-critical stuff is still written in assembly.

Yeah... who wants to write a FAT32 with LFN filesystem completely in 65816 assembly?  ???

As I found on the MD version, the overhead of the filesystem on reading, even done in plain C, is pretty minimal... it adds less than a second to reading a 4MB file in 16KB chunks. The main thing to have in assembly is the SD sector data read loop, and use the READ_MULTIPLE_BLOCK SD command.
Title: Re: 65816 code optimization
Post by: Aaendi on July 13, 2010, 11:58:12 PM
How fast does it work in terms of stuff onscreen?
Title: Re: 65816 code optimization
Post by: Conle on July 14, 2010, 02:04:04 AM
How fast does it work in terms of stuff onscreen?

 ::sm-23.gif::
 ~sm-72.gif~.gif ..What do you mean exactly ?   ~sm-92.gif~.gif  ~sm-64.gif~.gif
..This is a compiler optimization script.   ~sm-73.gif~.gif  ~sm-75.gif~.gif   ~sm-79.gif~.gif
Title: Re: 65816 code optimization
Post by: Aaendi on July 14, 2010, 09:18:52 AM
How many goombas can you throw at the screen with playfield collision, with Python + 65816 optimization?
Title: Re: 65816 code optimization
Post by: ChillyWilly on July 14, 2010, 09:44:44 AM
How many goombas can you throw at the screen with playfield collision, with Python + 65816 optimization?

10,437,782.0597312... exactly.
 ~sm-46.gif~.gif
Title: Re: 65816 code optimization
Post by: Conle on July 14, 2010, 01:37:16 PM
How many goombas can you throw at the screen with playfield collision, with Python + 65816 optimization?

 ~sm-80.gif~.gif

Good question , but the answer is not easy.It depends on if you use sorting algorithms / lut tables and few other things , plus there is a chance that most part of the critical code can not be optimized much or not at all  :)