snes-sdk code optimization

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
snes-sdk code optimization
by on (#60051)
I've been using the snes-sdk a lot lately, and it bugged me a bit that the assembly code generated by the C compiler is so inefficient. There's a Python script included with the snes-sdk that you can run on the generated assembly files to optimize them, but it doesn't go far enough IMO.

So I decided to put together my own optimizer, based on bunch of optimizers I had written several years ago for other processors (like 68000 and Z80). It's just a simple pattern-matching optimizer that scans the code repeatedly, trying to find known patterns that it can replace with shorter ones, until no more improvement is made. It targets common constructs, such as IF-statements and FOR/WHILE-loops among other things, so it's still fairly general.

The optimizer is meant to be placed after the Python script in the build chain. Something like this:

Code:
..\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


Currently there's a Windows version and a Linux version (both 32-bit), which both are included in the download. The source code is also included.

Download link: http://jiggawatt.org/badc0de/optimore-816r2.zip