CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Optimizer weirdness

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Code Ninja



Joined: 22 Sep 2010
Posts: 1
Location: Maryland

View user's profile Send private message

Optimizer weirdness
PostPosted: Wed Sep 22, 2010 7:59 am     Reply with quote

First question, is there a way to specify to the compiler that I want to optimize for speed or code space or RAM usage, etc.? I know about the "#opt x" directive but that seems to only be an increasing scale of optimization and often optimizing for ROM space increases RAM usage, etc. Is one level better at size/speed/RAM/etc. than another?

My second question is more of a head-scratcher. I am writing for a VERY space constrained application on a custom PIC core running inside an FPGA (based off a vanilla 16F series). When I compile my code, with default (unspecified) optimization I get ROM usage of 3000 instructions. However I get some warnings that I have variables that are declared but never used. So I comment out the declaration lines to get rid of them, recompile, and... ROM usage is now 3029 instructions?!?!?

Best I can figure without going line by line in the assembly code is that somehow removing those few variables shifts others to be on a different bank of memory and so accessing them is a problem. But I would have thought that the CCS compiler would be smart enough to put declared variables into the banks that made things the most efficient. Is this not the case? Could there be another explanation?

-Will
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 2:29 pm     Reply with quote

CCS doesn't tell us their memory allocation strategy.

You can use #locate to place variables at specific RAM addresses.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 2:49 pm     Reply with quote

In general, their 'strategy', seems to be something on the lines of 'allocate RAM sequentially from the available space, as variables are declared, only moving stuff when it causes problems.....'.
As a result, the old advice was to put variables that are used together, together in the declarations. This then reduces bank switching, but gives problems when some are global, and others local....

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group