Allow me to resurrect this very interesting thread/topic.
I have been working on optimizing a demo effect written in C these past weeks/months (a few hours at a time) and I have reached a point where further optimizations of the C code do not produce the expected result.
=> The generated code ends up being slower or the same when it should definitely be faster (even accounting for the limited register set of the CPU).
Looking at the assembler output it is clear that the quality of the produced machine code is responsible for the algorithm optimizations not translating into actual results:
- the code shuffles data back and forth between zero-page-simulated-registers and memory, it looks like it spends more time doing that than actual useful work.
- the Y register is only used as an index, never as a temporary storage to avoid a Load/Store
- the X register is used only once in a blue moon and only when the wind blows to the South
- many successive operations are redundant and unnecessary (ex: LDA tmp0; STA tmp0 -> \(ToT)/ )
- as a consequence of the above the code is much larger than it needs to be
This leads me to think that the topic of switching compilers or enhancing the current one would be worth discussing again.
I see several avenues:
- Enhancing the current compiler. To some extent that can be done very cheaply by implementing a simple peephole optimizer, these are usually very simple to implement and there are multiple open source implementations to start from (ex: http://aminet.net/package/dev/asm/popt an m68k peephole optimizer written by a friend of mine when I was in College).
- Offering multiple compiler choice for the OSDK (after all, the current compiler works so there is no need to remove it) by allowing to work with ISS's version of CC65 (or whichever other one that works). (And http://www.6502.org/tools/asm/ lists a lot of possible alternatives, many likely are not maintained anymore though I suppose.)
@ISS, did your attempts to work with CC65 lead you to a result that can be integrated to the OSDK?
Obviously my memory is failing me because there is already a peephole optimizer available (cf viewtopic.php?t=1805#p17427
) but it is currently disabled because it is not 100% reliable.
I am updating to the latest OSDK (1.13) and will give a go at fixing it.