Issue arising with optimizations: Codewarrior 10.7 with MCF51JM

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

Issue arising with optimizations: Codewarrior 10.7 with MCF51JM

1,538 Views
venuss
Contributor I

Hello!

 

I have installed Codewarrior for MCU 10.7 on Windows 10 x64 for use with the MCF51JM series of microprocessors. 

The problem arises with the following configuration:

Optimization Level: 1

Speed vs. Size: Size

Peephole: on

 

We are currently using Codewarrior 6.2 (but hoping to move everyone up to 10.7), and this was the configuration we used with the classic IDE with no issue.

 

The disassembly shows that the problematic line of code uses register A7 instead of the expected A5 for access to a global variable. I checked the indexing on A7 in case it would refer to the correct address, but it doesn't. I am performing the same operation on this variable several times throughout the function, which is why I don't understand why only this line uses the wrong register/address. 

 

I don't encounter this problem with either optimization level 0 or peephole optimization turned off, but we need to save on code space.

 

I'm quite new to this sort of development, so please let me know if I didn't provide enough information! Any ideas about what I should do? 

 

Thanks!

Labels (1)
0 Kudos
10 Replies

1,284 Views
venuss
Contributor I

Hi!

I'm not allowed to upload the project, but I'll try to present the situation.

Here is the line that behaves incorrectly.

C:

if(myGlobalVariable & 0x0010)

Disassembly:

btst       #4, 35(a7)

bne.w    *+176

All other lines similar in structure but work correctly look like this.

C:

if(myGlobalVariable & 0x0002)

Disassembly:

btst       #1, _myGlobalVariable+3(a5)

beq.s    *+68

In the btst instruction, we expect the destination operand to be _myGlobalVariable+3(a5). The line that behaves incorrectly uses a7 as the destination operand. I checked the value in a7 with the index of 35, and the address still does not point to myGlobalVariable.

0 Kudos

1,284 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

thanks.

well to verify if this is a defect or a user error, we need reproduce then problem

if you can not send the project, can you please create a demo code. thus we can check the problem directly.


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,284 Views
venuss
Contributor I

I've put together some demo code that showcases the issue. The problematic line is in MyUtils.c in the function myCalculations() with a comment next to it. 

Thank you for your help!

0 Kudos

1,284 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Sorry for the late, I was on vacation and country holiday and just back office.

I opened your project with CW10.7, build the project but many errors. can it pass build on your side? or could you  test this problem on another computer, can it pass build?


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,283 Views
venuss
Contributor I

For me, I was able to get rid of the errors by updating the paths in Paths and Symbols > Includes for Assembly Source File, GNU C, GNU C++, and Object File.

0 Kudos

1,284 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Thanks for your reply.

I reproduced your original issue. I wonder the problem is due to optimization. define problematicVariable with keyword "volatile" may fix the issue.

volatile uint32_t problematicVariable;

thus we can get disassemble code as below

;
;   75:     if((problematicVariable & 0x00000010) == 0){ // Note: problematic line
;
0x0000018A  0x202D0000               move.l   _problematicVariable(a5),d0
0x0000018E  0x08000004               btst     #4,d0
0x00000192  0x660C                   bne.s    *+14                  ; 0x000001a0
;

see my video attached.


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,284 Views
venuss
Contributor I

Declaring our global variables volatile is our current workaround.

What feels odd to me is that in the demo code, problematicVariable is not being changed anywhere else such as an interrupt. In performCalculations(), problematicVariable is set to 0xFFFFFFFF before myCalculations() is called. Yet when I run the code, (problematicVariable & 0x00000010) == 0 evaluates to true. With optimizations, I would expect maybe problematicVariable to not be reloaded. I have looked through the disassembly, and I don't understand the optimization result. For all other uses of problematicVariable, the correct address register was used. If I add lines that use problematicVariable after the problematic line, the disassembly shows usage of the correct register. Why is only this one line referring to a completely irrelevant address register?

0 Kudos

1,284 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

This is a compiler issue inside.

I suggest you create a case here

https://community.nxp.com/docs/DOC-329745 

thus our support team can create a internal ticket to DevTech team. Thanks!

Have a great day,
Jennie Zhang

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,284 Views
venuss
Contributor I

Oh, it's okay! I hope your vacation was pleasant. 

It passed build if I chose Clean and Build from the Project tab. I was able to reproduce those errors you see by right-clicking the project and choosing Clean and Build from those context menus. I'm trying to figure out the errors now, but do you know why those errors did not show up earlier for me?

0 Kudos

1,284 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

what's the exact problem when you modified the optimization level to  to Level 1?

Can you please upload your project to showcase your problem?


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos