66
Avoid Recursive Functions
AMD Athlon™ Processor x86 Code Optimization
22007E/0—November 1999
Avoid Recursive Functions
Avoid recursive functions due to the danger of overflowing the
return address stack. Convert end-recursive functions to
iterative code. An end-recursive function is when the function
call to itself is at the end of the code.
Example 1 (Avoid):
long fac(long a)
{
if (a==0) {
return (1);
} else {
return (a*fac(a–1));
}
return (t);
}
Example 2 (Preferred):
long fac(long a)
{
long t=1;
while (a > 0) {
t *= a;
a--;
}
return (t);
}
Summary of Contents for Athlon Processor x86
Page 1: ...AMD Athlon Processor x86 Code Optimization Guide TM...
Page 12: ...xii List of Figures AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 16: ...xvi Revision History AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 202: ...186 Page Attribute Table PAT AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 252: ...236 VectorPath Instructions AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 256: ...240 Index AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...