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 support@ccsinfo.com

? Optimization ?

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



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

? Optimization ?
PostPosted: Wed Mar 02, 2005 11:37 am     Reply with quote

While doing some changes to my code, I noticed this:

Code:
#opt 11
struct data_t {
   unsigned char active:1;
   unsigned long delay;
   unsigned long duration;
};

struct data_t a;
struct data_t b;

a = b;

0848:  CLRF   FSR0H
084A:  MOVLW  a
084C:  MOVWF  FSR0L
084E:  CLRF   FSR1H
0850:  MOVLW  b
0852:  MOVWF  FSR1L
0854:  MOVLW  06
0856:  MOVWF  @01
0858:  MOVFF  POSTINC1,POSTINC0
085C:  DECFSZ @01,F
085E:  BRA    0858



Is that correct? I think it should be 5 MOVFF's.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Mar 02, 2005 12:23 pm     Reply with quote

When you are making a copy of an array of bytes, the optimizer should switch to from using indirect addressing to direct memory addressing when the number of bytes copied is greater than 11. That is true for the example you posted at least. That will optimize for code size.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Wed Mar 02, 2005 6:59 pm     Reply with quote

But if 5 MOVFF's were used, the code would be faster/smaller, dont you think?
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Wed Mar 02, 2005 8:09 pm     Reply with quote

Future:

Grab any decent text on compiler design - you'll discover there's a HUGE distance between code optimized in an application specific environment by a professional assembly programmer and code from a generic set of statements fed to an optimizer that (obviously) must work after optimization - no matter how complex the (unknown to the compiler author) statements are!

CCS does an amazingly good job for a multi-hundred $$ compiler - we've used Greenhills in the past for 68xxx and it was better - but we paid a WHOLE lot more for that environment.

If you want "optimal" optimization, write the code in assembler. But remember, it'll probably take longer to write and debug, there's always one more byte that can be squeezed out by some wiseguy Cool

The real question to be asked is: does the code work under the conditions required? And did using the compiler get you there quicker than writing it in assembler? If both answers are yes, then mission accomplished.

Just my $0.02....
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Mar 03, 2005 2:52 am     Reply with quote

future wrote:
But if 5 MOVFF's were used, the code would be faster/smaller, dont you think?
Your example shows 24 bytes used. Using movff's is more efficient when copying up to 6 bytes. So yes, the compiler is not generating the most optimized code here.

CCS has improved the optimization a lot in v3.200, but there is always room for further improvement. Remember that the compiler is generating correct working code, optimization is just a nice bonus. That being said, it never hurts to send CCS a nice email pointing them at possible improvements, you may be lucky in the next release...
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