It is currently Fri Sep 22, 2017 11:59 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sun Aug 20, 2017 11:07 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1364
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.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Sun Aug 20, 2017 11:35 am 
Offline

Joined: Tue Oct 06, 2015 10:16 am
Posts: 521
No, that's not possible. The optimizer is part of the C compiler, the assembler has nothing of the sort.


Top
 Profile  
 
PostPosted: Sun Aug 20, 2017 11:50 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1364
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.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Mon Aug 21, 2017 1:55 am 
Offline

Joined: Tue Oct 06, 2015 10:16 am
Posts: 521
Is it useful though? Even a newbie to asm can easily write better code than what cc65 does.


Top
 Profile  
 
PostPosted: Mon Aug 21, 2017 3:11 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 240
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.


Top
 Profile  
 
PostPosted: Mon Aug 21, 2017 3:34 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1364
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.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Mon Aug 21, 2017 3:40 am 
Online
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 859
Location: Gothenburg, Sweden
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.

_________________
http://www.frankengraphics.com - personal NES blog


Top
 Profile  
 
PostPosted: Mon Aug 21, 2017 4:08 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 240
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bregalad and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group