This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Optimization of assembly code of cc65 possible?

Optimization of assembly code of cc65 possible?
by on (#202852)
When I write inline assembly code in C with cc65 (__asm__("LDA %v", variable)), then the code will get optimized just like the rest of the C code and I can see the optimization in the generated .s file.

Is there a way to run the same optimizer over a hand-written .s file and to generate a second .s file out of it?

I know, I could simply turn the whole file into a C file with inline assembly. But is there also a simpler way? A way that allows me two write my assemy code in an actual *.s file, but where I can generate a copy of it that I then put into the compile process, so that the ROM always automatically has the optimized code.
Re: Optimization of assembly code of cc65 possible?
by on (#202853)
No, that's not possible. The optimizer is part of the C compiler, the assembler has nothing of the sort.
Re: Optimization of assembly code of cc65 possible?
by on (#202855)
Maybe this would be a good feature in the future. It shouldn't require that much programming logic: The assembler simply needs to convert the assembly file into a C file with inline assembly. And then, it lets the C compiler run over it to produce another assembly file.
Re: Optimization of assembly code of cc65 possible?
by on (#202900)
Is it useful though? Even a newbie to asm can easily write better code than what cc65 does.
Re: Optimization of assembly code of cc65 possible?
by on (#202906)
If you want an optimising assembler, tass64 has a build in optimiser, but it only provides you with hints on what can be optimised. As sometimes doing an optimisation will undo the ability to optimise. It won't rearrange your code, but it will find shortcuts and dead opcodes like doing a clc after a bcs for example.
Re: Optimization of assembly code of cc65 possible?
by on (#202909)
calima wrote:
Is it useful though? Even a newbie to asm can easily write better code than what cc65 does.

You can surely write better Assembly code than what the cc65 compiler turns into Assembly out of C.

But my idea is about writing hand-written Assembly code and getting that one optimized by the compiler.
I assume that hand-written assembly code is better than the same hand-written assembly code + optimizations on it, don't you?

Oziphantom wrote:
If you want an optimising assembler, tass64 has a build in optimiser

Can it work with the ca65 syntax? My idea was to check my existing code without much hazzle and with the same or better optimizing quality that cc65 uses for inline assembly blocks.
Re: Optimization of assembly code of cc65 possible?
by on (#202911)
That [tass64-style tips] would be an interesting feature for ca65. Maybe it could output all optimisation tips in a separate list; rather than cluttering the console (the cc65 suite already has all kinds of notes, warnings and error notices).

With 1)a command line option to activate optimisation tips, and 2) a directive to ignore generating tips for certain blocks, it'd be effective.
Re: Optimization of assembly code of cc65 possible?
by on (#202914)
DRW wrote:
Oziphantom wrote:
If you want an optimising assembler, tass64 has a build in optimiser

Can it work with the ca65 syntax? My idea was to check my existing code without much hazzle and with the same or better optimizing quality that cc65 uses for inline assembly blocks.


It depends on how deeply you use CA65s features, both use the dot directive format, so .byte .word .segment etc. Tass64 has a build in linker rather than an external one, so they conceptually do the same things, just with different levels of abstraction. The macro format is not compatible. A better question might be, What does CA65 do that you need, and can Tass64 do it as well? Then if it can/or you like the idea of the optimizer more, do a small test with the optimizer to see if it will does enough to switch.