Inline cc65 functions
Moderator: Moderators
Inline cc65 functions
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.
Re: Inline cc65 functions
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");
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
Re: Inline cc65 functions
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.
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.
- rainwarrior
- Posts: 8734
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Inline cc65 functions
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.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.
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.)
Re: Inline cc65 functions
That's exactly what I'm looking for! Thank you!backslash "\" for multi line macro, at the end of each line.
Yes, my intentions is about optimizations...thanks for sharing your project, I'll take a look to get some ideas.I used this to manually unroll some loops in my Giant Steps project
Thank you again guys, I'll try to be more clear next time including some examples...sorry about that.