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

#TYPE ARG=Wx:Wy

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



Joined: 14 Dec 2008
Posts: 21

View user's profile Send private message

#TYPE ARG=Wx:Wy
PostPosted: Sat Oct 03, 2015 1:16 pm     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Sat Oct 03, 2015 1:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 04, 2015 11:16 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Sun Oct 04, 2015 12:01 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 04, 2015 4:37 pm     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Mon Oct 05, 2015 12:33 am     Reply with quote

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.
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