Do you have a question? Post it now! No Registration Necessary
- Posted on
- Space optimizing : C++, mega8, math.h
- Henning Mortensen
May 21, 2007, 7:24 pm
rate this thread
I'm having problems getting room for the code in my ATmega8. I found that
working with 32 bit int's wasn't enough, but now I changed et all to 64 bit
int's the code grew about 50% from about 80% of the mega8's space to about
I found that most of the space is lost in the following code where I use
fabs and sqrt. If I remove thoes lines the code is fills about 99%...
Anybody knows how to optimize the code to use less space, of a feature in
AVR studio (GCC) to optimize.
Speed is NOT important, space is.
"C:\WinAVR\bin\..\lib\gcc\avr.4.6\..\..\..\..\avr\bin\ld.exe: region text
is full (cnc.elf section .text)" :(
void moveto(uint64_t nyx,uint64_t nyy,uint64_t nyz)
long int dx;
long int dy;
long int dz;
dx = nyx - globalx;
dy = nyy - globaly;
dz = nyz - globalz;
Rho = sqrt((double)(dx * dx) + (double)(dy * dy) + (double)(dz * dz));
enX = (double)dx / Rho;
enY = (double)dy / Rho;
enZ = (double)dz / Rho;
int R = 0;
x += enX;
y += enY;
z += enZ;
if (fabs(x) >= 1)
if (fabs(y) >= 1)
if (fabs(z) >= 1)
Re: Space optimizing : C++, mega8, math.h
I found that if I remove the line
The size drops to about 34%??
But if I change the "for" to an infinate loop using goto, the size again
becomes over 100% ??
So it looks like the sqrt and fabs funktions aren't the problem after all..!
It isn't that big a funktion and it's not that complex, so what is
I'm at loss here!!! I cant see what the compiler is doing that takes up so
Hope someone out there has a good idear..
- » New(ish) assembler for PIC16 microcontrollers (asm1825)
- — Newest thread in » Microcontroller Discussions
- » (PDF) Essentials of Anatomy & Physiology 2nd Ed by Kenneth Saladin
- — The site's Newest Thread. Posted in » Electronics (Polish)