View previous topic :: View next topic |
Author |
Message |
arocholl
Joined: 14 Dec 2008 Posts: 21
|
#TYPE ARG=Wx:Wy |
Posted: Sat Oct 03, 2015 1:16 pm |
|
|
I saw this in PCD manual as a way to avoid using scratch RAM variables for function arguments. Inspecting the ASM code shows way more efficient and faster code, and of course using less RAM overall. This is actually how most C compilers work by default, using CPU registers first or STACK, not a scratch area as CCS does by default.
In large code I am getting >7% ROM savings and >4% RAM "worst case" savings.
So my question is why CCS doesn't have this enabled by default. What I am missing that may we prefer using RAM variables rather than CPU registers for function arguments by default? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sat Oct 03, 2015 1:36 pm |
|
|
Remember that CCS originated from the older PIC's. ON these, no data stack, and the only processor registers are themselves control registers, not for general storage.... |
|
|
arocholl
Joined: 14 Dec 2008 Posts: 21
|
|
Posted: Sun Oct 04, 2015 11:16 am |
|
|
Yes, I know. Still doesn't make sense to me is off by default in PCD which is specific for 16bits which does in fact support stack.
My fear is this mode may be way less tested and produce new compiler bugs... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sun Oct 04, 2015 12:01 pm |
|
|
CCS have kept to their defaults, even where tech has improved on the PIC's.
This has the advantage of compatibility, but in some cases is rather silly. There are a lot of examples where the default has to be changed/set to be 'sensible'. ERRORS in #use R232 for example. The actual stack size on the PIC24/30. The need to add pass_strings=IN_RAM to allow pointers to be passed to ROM, and ARG=Wx:Wy for examples.
The downside of this latter is that it increases the stack usage, so the saving in RAM may well be illusory as you then have to expand the stack....
However it should be better documented. |
|
|
arocholl
Joined: 14 Dec 2008 Posts: 21
|
|
Posted: Sun Oct 04, 2015 4:37 pm |
|
|
concerns confirmed: this feature is implemented in a way that cannot be used in any real program. Clearly didn't had it enabled by default because is extremely buggy.
The biggest problem: It does not save register in the stack if an intermediate function is using it. In other words, any function which call other function will change your registers and therefore will be different than you expect when are going to be used. It does not use more stack because makes no use of the stack at all...
The closest thing I saw working today is #SEPARATE ARG=Wx:Wy which makes the same thing but individually for functions. Therefore simple functions with parameters can be easily optimized one by one, and more complex functions where intermediate function calls can be either ignored or do your own PUSH/POP to prevent the unprotected code to damage you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Oct 05, 2015 12:33 am |
|
|
It is always worth treating 'new' features as if they are very suspect. If you pull any but the latest manual, the Wx:Wy feature does not exist. So you have CCS starting to work towards using the stack and extended W registers to improve efficiency, but at present only in a very limited way.
Using it locally for a single routine where optimisation is required, sounds a very good way to go. |
|
|
|