How do I force functions to be inline functions?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I force functions to be inline functions?

6,878 Views
admin
Specialist II
Using CodeWarrior 6.2 for a ColdFire processor.
 
I can force a VERY small function to be inline (Iff it is in the same file as the calling function).
But the compiler ignores #pragma inline and compiler settings for other functions in the file.
 

On the C/C++ languange tab there are the following controls, that seem to have little effect on the inlining
 
Auto-Inline
Botom-up Inline 
Inline depth?
 
How are these controls intended to control the inlining of functions?
 
Labels (1)
0 Kudos
Reply
7 Replies

2,848 Views
CrasyCat
Specialist III
Hello
 
There is a section around that in the {Install}\Help\PDF\ColdFire_Build_Tools_Reference.pdf manual.
 
Look at chapter "Intermediate Optimizations" section "Inlining"
This should provide you with all you need to know around inlinng.
 
CrasyCat
0 Kudos
Reply

2,848 Views
admin
Specialist II
>There is a section around that in the {Install}\Help\PDF\ColdFire_Build_Tools_Reference.pdf manual.
 
This chapter is full of information  about inlining functions but was not all that helpful.
 
In one place it says the maximum value for INLINE_MAX_TOTAL_SIZE  is 7000 and in another place it says the default value is 10000. Either of these values should be big enough to force my 100line function to inline.  But adding this pragma  did not force my inline function to be inlined.
 
I had tried enabling IPA, but it causes compiler errors in my inline assembly code. (!?)
 
It turns out I was declaring the function using "inline" instead of "__inline"
 
The keyword "inline" compiles fine but does nothing.
But,  "__inline" works without any pragmas, etc.
 
0 Kudos
Reply

2,848 Views
CrasyCat
Specialist III
Hello
 
I did some test with CodeWarrior for Coldfire V6.4.
 
I did write following source code:
 
Code:
inline void foo(int tst ){     asm      {      NOP      NOP      NOP     }}void foo2(int tst){     asm      {      NOP      NOP      NOP NOP NOP NOP     }}int main(void){ foo(pp);  foo2(pp);   while(1) {  }}

I then got following disassembled code:

Code:
;   37: int main(void) ;   38: { ;   39:   ;0x00000000                    _main:;                             main:0x00000000  0x4E560000               link     a6,#00x00000004  0x518F                   subq.l   #8,a7;;   40:  foo(pp); ;   41:   ;0x00000006  0x7002                   moveq    #2,d00x00000008  0x2D40FFFC               move.l   d0,-4(a6)0x0000000C  0x4E71                   nop      0x0000000E  0x4E71                   nop      0x00000010  0x4E71                   nop      ;;   42:  foo2(pp); ;   43:   ;0x00000012  0x7002                   moveq    #2,d00x00000014  0x2E80                   move.l   d0,(a7)0x00000016  0x4EB900000000           jsr      _foo2
So keyword inline seems to tell the compiler to inline a function.
CrasyCat
0 Kudos
Reply

2,848 Views
admin
Specialist II
I'm using 6.2 for coldfirel v1. I think it is  the latest. 
I checked to make sure that
    
             #define inline
 
wasn't anywhere in the include chain.  I hadn't thought of that.
 
 
I also discovered that on "global optimization" tab, I  MUST  select
  optimize  for "faster execution"     rather than     " smaller code size"
[ Which makes sense -- I'm inlining  for faster execution]
 
But this  is true, even  I've selected "optimizations off" from the  slider on that tab .
 
 
 
 
 
0 Kudos
Reply

2,848 Views
FridgeFreezer
Senior Contributor I

Thought I'd post here rather than start a new thread - I'm having trouble making CW use inline functions, using CW7.2 for MCF52259.

 

In the Freescale includes we have mcf5xxx.c/.h which define the following functions:

// Modified to return the previous IPL
uint8 mcf5xxx_irq_enable (void)
{
    return(asm_set_ipl(0));
}
uint8 mcf5xxx_irq_disable (void)
{
    return(asm_set_ipl(7));
}

 

Which are used in our interrupt routines etc. to prevent spurious interrupts when twiddling the IMRx registers. As such, we're trying to make the code a bit faster by inlining some functions, but cannot make CW inline these.

 

In the global optimisations I have it set to "faster code". I have tried setting IPA to "File" and "Program", I have tried turning auto-inline on/off, and tried redeclaring functions as "inline uint8 mcf5xxx_irq_disable (void)" or "__inline uint8 mcf5xxx_irq_disable (void)" but the compiler then throws link errors saying "Undefined: mcf5xxx_irq_disable".

 

Is this because the function is using asm_set_ipl() and this must also somehow be inlined?

 

0 Kudos
Reply

2,848 Views
CompilerGuru
NXP Employee
NXP Employee
As inline is not a standard C keyword I saw in the past defines which map inline to nothing, so the code compiles.
Is there such a "#define inline" in the OP's code?
That would explain why __inline works fine.

Daniel
0 Kudos
Reply

2,848 Views
CompilerGuru
NXP Employee
NXP Employee
More recent versions of the tools (7.X) also offer to optimize (including inline) across files with the IPA switch in the C/C++ Language panel. Don't think 6.2 had that.

Daniel
0 Kudos
Reply