Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Oct. 27, 2005 20:19:12

Marcos V.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Better optimization


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

Offline

#2 Oct. 28, 2005 03:01:44

Chris L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Better optimization


what you are looking for is called "tail call optimization". the commandline switch in gcc is named "-foptimize-sibling-calls", it shoud beenabled with "-O2", which you use. i don't know why it isn't working inthis particular case.chrishttp://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Optimize-Options.html#Optimize%20OptionsMarcos Vicente Cruz wrote:Hi all,I have spending my time optimizing the source code for my project and Inoticed 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 onebranch instruction. It could save some cycles and one stack position. I thinkit 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
Visithttp://www.jboss.com/services/certificationfor more information
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/mspgcc-users

Offline

#3 Oct. 31, 2005 15:16:02

Marcos V.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Better optimization


Hi,

One more thing: I've obtained these results using mspgcc 3.2.3 on
Gentoo and
on Windows98SE using mspgcc-20051026 package.


Marcos

Em Friday 28 October 2005 00:01, Chris Liechti escreveu:
> 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

Offline

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support