View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
? Optimization ? |
Posted: Wed Mar 02, 2005 11:37 am |
|
|
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
|
|
Posted: Wed Mar 02, 2005 12:23 pm |
|
|
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
|
|
Posted: Wed Mar 02, 2005 6:59 pm |
|
|
But if 5 MOVFF's were used, the code would be faster/smaller, dont you think? |
|
|
bluetooth
Joined: 08 Jan 2005 Posts: 74
|
|
Posted: Wed Mar 02, 2005 8:09 pm |
|
|
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
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
|
|
Posted: Thu Mar 03, 2005 2:52 am |
|
|
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... |
|
|
|