??? 02/19/07 16:33 Read: times |
#133255 - Optimizing and Keil/SDCC/Raisonance Responding to: ???'s previous message |
With default compiler settings, the Keil compiler generates the following.
line level source 1 unsigned char idata * data a; 2 unsigned char idata * data b; 3 4 void Func0() 5 { 6 1 *a++ = *b++; 7 1 } 8 9 10 void Func1() 11 { 12 1 *a = *b; 13 1 ++a; 14 1 ++b; 15 1 } ASSEMBLY LISTING OF GENERATED OBJECT CODE ; FUNCTION Func0 (BEGIN) 0000 AF00 R MOV R7,b 0002 0500 R INC b 0004 A807 MOV R0,AR7 0006 E6 MOV A,@R0 0007 AE00 R MOV R6,a 0009 0500 R INC a 000B A806 MOV R0,AR6 000D F6 MOV @R0,A 000E 22 RET ; FUNCTION Func0 (END) ; FUNCTION Func1 (BEGIN) 0000 A800 R MOV R0,b 0002 E6 MOV A,@R0 0003 A800 R MOV R0,a 0005 F6 MOV @R0,A 0006 0500 R INC a 0008 0500 R INC b 000A 22 RET ; FUNCTION Func1 (END) Which is a far cry from the posted example. Of course, the code gets worse if you eliminate using absolute register addressing. But, who would disable that (or any other "standard" 8051 optimization) in a real application? Note that the SDCC compiler output given as a comparison uses absolute register addressing. So, comparing any compilers this way is not a legitimate comparison. None of the comparisons list code size (just the number of instructions), execution speed, or other things like the number of registers used (which is important for optimizing functions that call these "test" functions). I've done that in the following table (* denotes the best numbers). Thanks to Rob for the Raisonance numbers. *a++ = *b++; Keil SDCC Raisonance --------------------------------------------- Code Size 15 13* 15 Time 14 12* 14 Regs Used 3* 3* 4 *a=*b; a++; b++; Keil SDCC Raisonance --------------------------------------------- Code Size 11* 13 11* Time 10* 12 10* Regs Used 1* 3 2 Using a single, simple function to compare compiler output is fairly pointless. The optimizer in each of the compilers will do a better job on a larger application. And, at the end of the day, we're writing applications—not test cases. If you're trying to optimize part of an application, write it in C and get it to work. Then, use a performance analyzer to measure where the performance is going and work on optimizing that. The compiler is just a tool. It isn't a brain replacement (well, it's not supposed to be). Jon |