what you are looking for is called "tail call optimization". the command
line switch in gcc is named "-foptimize-sibling-calls", it shoud be
enabled with "-O2", which you use. i don't know why it isn't working in
this particular case.
chris
http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Optimize-Options.html#Optimize%20Options
Marcos Vicente Cruz wrote:
Hi all,
I have spending my time optimizing the source code for my project and I
noticed that something could be better. Look at this example :
#include <io.h>
int f2(int y) {
return ++y;
}
void f1(int x) {
++x;
return f2(x);
}
main() {
f1(10);
}
Compilling it with the options "-mmcu=msp430x435 -O2 -Wall -ggdb3
-mendup-at=main -pipe" results on this .lst file :
--- cut ---
int f2(int y) {
return ++y;
c040: 1f 53 inc r15 ;
}
c042: 30 41 ret
0000c044 <f1>:
int f1(int x) {
++x;
c044: 1f 53 inc r15 ;
return f2(x);
c046: b0 12 40 c0 call #-16320 ;#0xc040
}
c04a: 30 41 ret
--- cut ---
The problem is the last "call" and "ret" instructions could turn into one
branch instruction. It could save some cycles and one stack position. I think
it will not be a great optimization but....
Marcos
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users