View previous topic :: View next topic |
Author |
Message |
Code Ninja
Joined: 22 Sep 2010 Posts: 1 Location: Maryland
|
Optimizer weirdness |
Posted: Wed Sep 22, 2010 7:59 am |
|
|
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
|
|
Posted: Wed Sep 22, 2010 2:29 pm |
|
|
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: 19504
|
|
Posted: Wed Sep 22, 2010 2:49 pm |
|
|
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 |
|
|
|