inline function

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
3,356件の閲覧回数
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

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
2,940件の閲覧回数
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 件の賞賛
返信
6 返答(返信)
2,940件の閲覧回数
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 件の賞賛
返信
2,940件の閲覧回数
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 件の賞賛
返信
2,940件の閲覧回数
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 件の賞賛
返信
2,940件の閲覧回数
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 件の賞賛
返信
2,941件の閲覧回数
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 件の賞賛
返信
2,940件の閲覧回数
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 件の賞賛
返信