Go Down

Topic: Optimization flags arduino 1.6.5 (Read 8624 times) previous topic - next topic

Vindhyachal_Takniki

1. I have been reading this:
http://www.instructables.com/id/Arduino-IDE-16x-compiler-optimisations-faster-code/?ALLSTEPS

2. Page 6 states that platform.txt exist in:
C:\Users\XXXX\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.x\platform.txt

However I have found that inside mu PC;   C:\Users\XXXX\AppData\Roaming\Arduino15 , there is no folder name packages. I have searched in hidden files also.

3. However I have found platform.txt file in:
C:\Program Files\Arduino\hardware\arduino\avr

Not sure if I have to edit in this. I have attached a copy.

4. There are three places where -Os is found, line 23,26 & 30.
So should I change at these 3 places only depending on requirement:
No optimization: -O0
speed optimization: -O3
size optimization: -Os
balance optimization: -O2

PaulS

Quote
So should I change at these 3 places only depending on requirement:
No optimization: -O0
speed optimization: -O3
size optimization: -Os
balance optimization: -O2
Why do you think you need to change the optimization level?
The art of getting good answers lies in asking good questions.

jurs

3. However I have found platform.txt file in:
C:\Program Files\Arduino\hardware\arduino\avr

Not sure if I have to edit in this. I have attached a copy.
Yes, platform.txt is the place to edit the optimization level for Arduino IDE versions 1.6.x

Before doing changes, better keep a copy of the unmodified platform.txt file.

But why do you want to change that? Want to create bigger executables?

Vindhyachal_Takniki

1. Want to learn abt optimization & test the result, how it changes the time/size in arduino.
In final code, I may use default setting. But at learning stage I want to leran them.

2. Since I have multiple files in my code, so should I replace "-Os" with "-fwhole-program -O3"?

PaulS

Quote
2. Since I have multiple files in my code, so should I replace "-Os" with "-fwhole-program -O3"?
What happened when you did that?
The art of getting good answers lies in asking good questions.

jurs

#5
Aug 25, 2015, 12:03 pm Last Edit: Aug 25, 2015, 12:04 pm by jurs
2. Since I have multiple files in my code, so should I replace "-Os" with "-fwhole-program -O3"?
As far as I know you can replace the occurances of  "-Os" against "-O0" (no optimisation at all!), "-O1", "-O2" or "-O3".

But I never tried out.
And I know nothing about a "-fwhole-program" parameter.

Vindhyachal_Takniki

1. I have made 3 changes in platform.txt as present in: Line 23, 26 & 30.
i.e changed O0,Os & O3

Code: [Select]

compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD
# -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
# This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain
compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections
compiler.c.elf.cmd=avr-gcc
compiler.S.flags=-c -g -x assembler-with-cpp
compiler.cpp.cmd=avr-g++
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD



2. On new sketch (empty setup & loop), code builds without any warning on Os, O3. However when I changed it to O0 it shows warning in many compiled files. Why this error?
Code: [Select]

In file included from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\USBAPI.h:27:0,
                 from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Arduino.h:225,
                 from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial2.cpp:25:
c:\program files\arduino\hardware\tools\avr\avr\include\util\delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"



3. Also my code has multiple .ino & .h files. So will chnaging only these three opt flag will include all files or I have to do something else.


oqibidipo

i.e changed O0,Os & O3
LOL, I didn't know GCC has that option! :D

You can prevent that from happening by using [nobbc]...[/nobbc].

Vindhyachal_Takniki

#8
Sep 01, 2015, 09:37 am Last Edit: Sep 01, 2015, 09:37 am by Vindhyachal_Takniki
LOL, what had just happened O0, O0 , O0

Vindhyachal_Takniki

Final Code size by opt settings:

1. Default -Os
Sketch uses 22502 bytes (8%) of program storage space. Maximum is 253952 bytes.
Global variables use 674 bytes (8%) of dynamic memory, leaving 7518 bytes for local variables. Maximum is 8192 bytes.

2. Same code size generated for below thre options
    a) Replace -Os by -O3
    b) Replace -Os by -fwhole-program -O3
    c) Replace -Os by -flto -O3
Sketch uses 44858 bytes (17%) of program storage space. Maximum is 253952 bytes.
Global variables use 686 bytes (8%) of dynamic memory, leaving 7506 bytes for local variables. Maximum is 8192 bytes.


Havent tested on hardware yet. Will check. ordered new finger print module.

Go Up