Yagarto & math.h

OP (Company: Noname) #2618247
Rate this post
• ▲ useful
▼ not useful
Hi.
I write programs for LPC Cortex-M0.
I need to use the cos and sqrt functions from math.

Program:
1
#include <math.h>
2
volatile float DeltaX=50, DeltaY=120, Angle=3.14/4;
3
volatile float Delta;
4
volatile unsigned char DistanceFlag;
5

6

7
void Func() {
8

9
    float dx=DeltaX, dy=DeltaY, angle=Angle, distance_delta;
10
    dx=dx*cos(angle);
11
    dx=dx*angle*3.14;
12
    distance_delta=dx*dx+dy*dy;
13
    distance_delta=sqrt(distance_delta);
14
    if (distance_delta>100)
15
      DistanceFlag=1;
16
    Delta=distance_delta;
17
  }
18
}
The size of the program increased on>~10kB. Optimization: -O3 or -Os.
How I can reduse code size?
(For this functions normal size must by 2-3kB).
Guest #2618529
Rate this post
• ▲ useful
▼ not useful
>   }
Error: no matching {

> (For this functions normal size must by 2-3kB).
OK.

On AVR-GCC 4.7.0 (i have no Yagarto installed):
.text (Code) size is 1462 Bytes (with minimal main()); .data size is 12 
Bytes and .bss is 5 Bytes
size of elf file is 18471 Bytes (with debug symbols, not stripped)
size of hex file is 4170 Bytes

> How I can reduse code size?
Analyze the output of the toolchain esp. the *.lss and *.map files.
Guest #2620010
Rate this post
• ▲ useful
▼ not useful
Attention: AVR-GCC
1
gcc version 4.7.0 20120217 - by SRMeister (GCC) 
2
COLLECT_GCC_OPTIONS='-mmcu=atmega16' '-I' '.' '-v' '-gdwarf-2' '-Os' '-funsigned-char' '-funsigned-bitfields' '-fpack-struct' '-fshort-enums' '-Wall' '-Wstrict-prototypes' '-std=gnu99' '-D' 'F_OSC=3686400' '-MD' '-MP' '-MF' '.dep/main.elf.d' '-o' 'main.elf'

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.