Inline cc65 functions

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
NOOPr
Posts: 75
Joined: Tue Feb 27, 2018 10:41 am
Location: Brazil
Contact:

Inline cc65 functions

Post by NOOPr »

It's possible to force a function to be inlined in cc65? I know that's possible with a #define, but I need a multi-line macro. I unsuccessfully tried to define a macro in assembler and then call it on the C code direct or via define.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Inline cc65 functions

Post by dougeff »

backslash "\" for multi line macro, at the end of each line.

I have written macros in assembly. It can be done. Perhaps you could post code.


Example...
#define fast_pal_col(a, b) \
__asm__ ("lda #%b", b); \
__asm__ ("ldx #%b", a); \
__asm__ ("sta $1c0, x");
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Inline cc65 functions

Post by Banshaku »

I did read the documentation and there is no way to tell the C compiler to have a C function code inlined. The only way seems to be with macro, like you are trying right now.

for multi-line, like dougeff said, \ at the end, nothing else to add. Except that in some case I had issues with structs were it didn't want to access parameters and I couldn't find the cause. I may ask someday on nesdev about it with some sample code but for now just be careful about those.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Inline cc65 functions

Post by rainwarrior »

NOOPr wrote:It's possible to force a function to be inlined in cc65? I know that's possible with a #define, but I need a multi-line macro. I unsuccessfully tried to define a macro in assembler and then call it on the C code direct or via define.
CC65 doesn't have much effective optimization, and it doesn't implement inline functions. Even if it could inline them the advantage is gone because it isn't really capable of optimizing through them either.

As stated above, you can make a multi-line define with a \ to continue the line. That's not just for inline assembly, you can put C code in there too. I think the suggestion for inline assembly was just assuming you were trying to optimize more (which generally requires doing it "by hand" in assembly).

I used this to manually unroll some loops in my Giant Steps project, which was a big optimization by itself, despite not using any inline assembly. (See coltrane.c, look for RING_BUFFER_SWAP.)
User avatar
NOOPr
Posts: 75
Joined: Tue Feb 27, 2018 10:41 am
Location: Brazil
Contact:

Re: Inline cc65 functions

Post by NOOPr »

backslash "\" for multi line macro, at the end of each line.
That's exactly what I'm looking for! Thank you!
I used this to manually unroll some loops in my Giant Steps project
Yes, my intentions is about optimizations...thanks for sharing your project, I'll take a look to get some ideas.

Thank you again guys, I'll try to be more clear next time including some examples...sorry about that.
Post Reply