Welcome! Log In Create A New Profile

Advanced

Compile for execution speed rather than size ?

Posted by Pippy 
Compile for execution speed rather than size ?
February 12, 2019 05:50AM
Hello,

I notice that the Arduino IDE compiles Marlin (and any AVR code really) with 'size' optimization (-Os) set. Has anyone ever tried compiling Marlin for execution speed (-O2) instead ?

If so, did you notice any undue side effects ?

I've not tried running it on the board as yet as I'm still waiting for the controller board to arrive, but it strikes me that it's a much wanted change to make given the lack of desired MCU clock speed.


The location of the compiler optimization settings are in the file (in my case) is ..

C:\Program Files (x86)\Arduino\hardware\arduino\avr\platform.txt ... depends where you installed the IDE.

The two lines that I've changed to compile for execution speed are ..

compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects

and

compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto

I've replaced the two -Os with -O2. It still compiles just fine, but that of cause doesn't mean it'll run fine - learn't this over many years of programming, sometimes it's fine, sometimes the odd routine in your code throws a wobberley with this setting (but can normally be overcome with slight coding adjustments).

If it runs OK, we may gain a good percentage increase in firmware execution speed (depends where the coding bottle necks are), then again, maybe not.

Pip
Sorry, only registered users may post in this forum.

Click here to login