The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.
So far in May, you have voted 0 times ou of a total of 20 votes by the community.
Please help us clean the archives from unuseful discussion threads by using the voting system! Details here.
Is this thread worth a thumbs up?
TAIL CALL - B - Sep 16 23:43:10 2012
DOES IAR COMPILE TAIL CALLS CORRECTLY??
I TRIED EVERYTHING AN I COULDN'T BUT MAYBE I AM DOING SOMETHING WRONG.
THANKS
B
(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: TAIL CALL - lslonim2 - Sep 17 8:30:23 2012
I don't understand the question, what is a tail call?
--- In m..., B
wrote:
>
> DOES IAR COMPILE TAIL CALLS CORRECTLY??
> I TRIED EVERYTHING AN I COULDN'T BUT MAYBE I AM DOING SOMETHING WRONG.
>
> THANKS
> B
>

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: TAIL CALL - Peter Johansson - Sep 17 9:40:09 2012
On Mon, Sep 17, 2012 at 8:30 AM, lslonim2
wrote:
> I don't understand the question, what is a tail
call?
A "tail call" is the condition of a recursive function where the
recursive call is the return value. It is important because tail
calls (or tail recursion) can always be implemented as iteration, that
is, without adding a stack frame on the call stack.
The simple answer would be to look at the machine code generated by
your compiler. I'm sure there are some uC developers who would say
to ignore the elegance of the recursive function and simply re-write
the function iteratively. There is a chance this could optimize even
better, and you are certainly not going to get burned if you switch to
a different compiler that does not optimize tail recursion.
-p.

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: TAIL CALL - bookitoo - Sep 17 12:01:12 2012
--- In m..., Peter Johansson
wrote:
>
> On Mon, Sep 17, 2012 at 8:30 AM, lslonim2 wrote:
>
> > I don't understand the question, what is a tail call?
>
> A "tail call" is the condition of a recursive function where the
> recursive call is the return value. It is important because tail
> calls (or tail recursion) can always be implemented as iteration, that
> is, without adding a stack frame on the call stack.
>
> The simple answer would be to look at the machine code generated by
> your compiler. I'm sure there are some uC developers who would say
> to ignore the elegance of the recursive function and simply re-write
> the function iteratively. There is a chance this could optimize even
> better, and you are certainly not going to get burned if you switch to
> a different compiler that does not optimize tail recursion.
>
> -p.
>
Exactly. I have checked the asm generated by the compiler, and I couldn't make
the compiler use tail recursion. Maybe it is not implemented. So, I did it
iteratively.
B

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com ) Re: TAIL CALL - David Brown - Sep 20 13:20:34 2012
On 17/09/12 15:40, Peter Johansson wrote:
> On Mon, Sep 17, 2012 at 8:30 AM, lslonim2
> > wrote:
>
> > I don't understand the question, what is a tail call?
>
> A "tail call" is the condition of a recursive function where the
> recursive call is the return value. It is important because tail
> calls (or tail recursion) can always be implemented as iteration, that
> is, without adding a stack frame on the call stack.
>
> The simple answer would be to look at the machine code generated by
> your compiler. I'm sure there are some uC developers who would say
> to ignore the elegance of the recursive function and simply re-write
> the function iteratively. There is a chance this could optimize even
> better, and you are certainly not going to get burned if you switch to
> a different compiler that does not optimize tail recursion.
>
> -p.
>
You don't have to use recursion to get tail call optimisation - it is a
common optimisation whenever a function ends with a call to another
function.
Turning a true recursive function into an iterative one is far from a
trivial optimisation, and is often not possible even in theory. So
don't expect a compiler to do it automatically in many cases.
(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: TAIL CALL - old_cow_yellow - Sep 20 20:35:18 2012
Don't know if this is "tail call" or "tail branch". But using IAR, if I have:
{
...
return sub(...);
}
The compiler will not generate code to "call sub();" and return what sub();
returns. It does simply "br sub();" instead.
(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: TAIL CALL - David Brown - Sep 21 17:13:06 2012
On 21/09/12 02:35, old_cow_yellow wrote:
> Don't know if this is "tail call" or "tail branch".
But using IAR, if I
> have:
>
> {
> ...
> return sub(...);
> }
>
> The compiler will not generate code to "call sub();" and return what
> sub(); returns. It does simply "br sub();" instead.
>
That is tail call optimisation, and it's quite common in compilers (at
least in simple cases when a stack frame is not needed).
(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )