Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > Variable Optimization

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Variable Optimization
Moderator:
JFMD

Post Reply
Follow this topic



Variable Optimization

kingneb posted on 31 Jan 2013 11:38 AM PST
Member
7 Forum Posts

Hello,

PSoc creator has an issue where so-called unused variables are optimized out despite the fact they are written to more than once. C compilers are not supposed to do this. Is there something I can do without having to turn off optimization?




Re: Variable Optimization

kingneb posted on 31 Jan 2013 11:49 AM PST
Member
7 Forum Posts

A further note, making the variable volatile does not help, weird.



Re: Variable Optimization

hli posted on 31 Jan 2013 01:02 PM PST
Top Contributor
675 Forum Posts

It doesn't matter how often you write to a variable - when you never read from it, it is unused and compiler can optimize if. The same is true for all writes except the last one - they are useless and will be optimized out.

So when you want to see, during debugging, the value, make sure you use the variable somewhere later on.



Re: Variable Optimization

Bob Marlowe posted on 31 Jan 2013 01:37 PM PST
Top Contributor
1768 Forum Posts

In Creator under

Project -> Build Settings -> Compiler

you'll find options to set optimization levels depending on the chip you use PSoC3 or 5. I would suggest to minimize the optimization for the debugging build and maximize them for the release.

 

Bob

 



Re: Variable Optimization

danaaknight posted on 31 Jan 2013 03:17 PM PST
Top Contributor
1773 Forum Posts

Precaution, keep in mind SW based timing loops can be affected by

optimization settings, so be diligent. At minimum look at .lst file before

and after. Or convert them to HW, or hard code them in ASM if in doubt.

 

Regards, Dana.



Re: Variable Optimization

PSoC Rocks posted on 03 Feb 2013 06:17 AM PST
Top Contributor
128 Forum Posts

 As per KEIL's KB article on various Optimization levels, unused code fragments are getting eliminated if set to level 1 or above. So, if you really want to keep a variable undeleted eventhough you are not going to use it anywhere, you might want to set the Optimization level to 0 and try it out.



Re: Variable Optimization

PSoC Rocks posted on 03 Feb 2013 06:19 AM PST
Top Contributor
128 Forum Posts

 Moreover, you might want to take a look at this Application Note on PSoC 3 - 8051 code Optimization.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20