inline function

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

inline function

Jump to solution
1,799 Views
markuskandler
Contributor I

Hello,

 

I'm trying to inline this Little function but the Compiler (S12ZCPU) refuses to do that. Is there any Limitation I violated?

 

__inline__ void FunctionToInline(uint16 *current_ptr)

{

    current_ptr[0] -= Adc0Offset;

    current_ptr[1] -= Adc1Offset;

}

 

With another function that staturates a value, inlining worked well.

 

Thanks for your help

Labels (1)
Tags (1)
0 Kudos
1 Solution
1,383 Views
MJW
NXP Employee
NXP Employee

Hello Markus,

I tried to include similar code into one of my projects.

I found that I had to enable both "optimize for speed" and "Bottom-Up Inlining", in order for this function to be inlined. I left "inline level" at the default ("smart").

Hope that helps.

MJW

View solution in original post

0 Kudos
6 Replies
1,383 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Markus,

Are you getting the compilation error? If yes, what is the error?

Which version of CodeWarrior you are using?

I am able to compile this function.

Even, if I disassemble the file, I can see the difference with the use of "__inline__" and without it.

I have checked on CW10.6

-Arpita

0 Kudos
1,383 Views
markuskandler
Contributor I

Hi,

thanks for your answer.

I get no compilation error but a warning, that the function cannot be inlined.

I'm using CW 10.5

In my compilation output I see no difference if inline is used or not

0 Kudos
1,383 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello,

See below the basic code which I have developed:

********************************************************************

int a[2], Adc0Offset, Adc1Offset;

__inline__  void FunctionToInline(int *current_ptr)

{

    current_ptr[0] -= Adc0Offset;

    current_ptr[1] -= Adc1Offset;

}

void main(void)

{

  Adc1Offset=10;

  Adc0Offset=8;

  EnableInterrupts;

  /* include your code here */

  FunctionToInline(a);

  for(;;) {

    __RESET_WATCHDOG(); /* feeds the dog */

   

  } /* loop forever */

}

*********************************************************************

Right click on the file and select Disassemble option.

With inline, I can see that the function has not allocated a memory space and main() starts at 0x00, while if I remove "__inline__", main() starts at 0000001F, and function is treated as a subroutine.

I am not sure why it is not working in your code? Are you using code optimization?

Can you share your code so that issue can be replicated at our end and then we can find the cause.

-Arpita

0 Kudos
1,383 Views
markuskandler
Contributor I

Thanks for your answer.

The original code where the inline function is called looks like this:

InlineFunction.png

The inline function itself is defined in the module header:

InlineFunction_Header.png

Project Compiler Settings:

InlineFunction_CompilerSettings.png

I've already tried various compiler settings (especially inline and optimization level).

Regards

Markus

0 Kudos
1,384 Views
MJW
NXP Employee
NXP Employee

Hello Markus,

I tried to include similar code into one of my projects.

I found that I had to enable both "optimize for speed" and "Bottom-Up Inlining", in order for this function to be inlined. I left "inline level" at the default ("smart").

Hope that helps.

MJW

0 Kudos
1,383 Views
markuskandler
Contributor I

Hi,

thanks for your answer. I tried your suggested Settings but with my Project it make no difference. I still got the warning that the function cannot be inlined.

I've also tried to setup a new project, but that didn't change anything.

0 Kudos