Author Topic: 65816 code optimization  (Read 7895 times)

0 Members and 1 Guest are viewing this topic.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
65816 code optimization
« 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.



Offline Dr.neo

  • Administrator
  • Hero Member
  • *****
  • Posts: 3826
Re: 65816 code optimization
« Reply #1 on: April 11, 2010, 08:47:13 PM »
mic_ you keep to did the great job always  ~sm-55.gif~.gif
In my world,have 0 and 1 only ......Matrix World......

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: 65816 code optimization
« Reply #2 on: April 12, 2010, 12:27:25 AM »
 :P ..........

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: 65816 code optimization
« Reply #3 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)

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: 65816 code optimization
« Reply #4 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.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: 65816 code optimization
« Reply #5 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

Offline AndiNo

  • Newbie
  • *
  • Posts: 17
  • NEO newbie
Re: 65816 code optimization
« Reply #6 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?

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: 65816 code optimization
« Reply #7 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.

Offline AndiNo

  • Newbie
  • *
  • Posts: 17
  • NEO newbie
Re: 65816 code optimization
« Reply #8 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 :)

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: 65816 code optimization
« Reply #9 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.

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: 65816 code optimization
« Reply #10 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.

Offline Aaendi

  • Newbie
  • *
  • Posts: 25
Re: 65816 code optimization
« Reply #11 on: July 13, 2010, 11:58:12 PM »
How fast does it work in terms of stuff onscreen?

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: 65816 code optimization
« Reply #12 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

Offline Aaendi

  • Newbie
  • *
  • Posts: 25
Re: 65816 code optimization
« Reply #13 on: July 14, 2010, 09:18:52 AM »
How many goombas can you throw at the screen with playfield collision, with Python + 65816 optimization?

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: 65816 code optimization
« Reply #14 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