Saturday, November 03, 2007

How to change the GCC-E optimization level to speed up your application

It is possible to change the default level of optimization used by GCC-E. This may result in code running up to three or four times as fast on the phone.

In the SDK, find the file epoc32\tools\compilation_config\GCCE.mk and edit it with a text editor.

Search for the lines:

#------------------------------------------------------------------------------------------------------------------------------
# Release Mode Options
#------------------------------------------------------------------------------------------------------------------------------

# Optimization Level in RELEASE mode
REL_OPTIMISATION=

Change the last line so that it reads:

REL_OPTIMISATION= -O2 -fno-unit-at-a-time

(You can find more information on the optimization options of GCC at http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Optimize-Options.html#Optimize-Options)

Once you have changed this file, go to your project. Type abld clean to ensure any existing object files are deleted, then build your project as usual.

Note 1: turning up the optimization level will make it more likely that your code makes assumptions which aren't honored by the compiler. If your code doesn't behave as it should, try setting back the optimization level to its initial setting.

Note 2: as explained in the GCC documentation, there are some compatibility issues with unit-at-a-time mode (enabled by -O2), hence the suggestion to disable it.

Note 3: a developer has reported getting the linker error: "undefined reference to `typeinfo for MTmTextLayoutForwarder'". This was solved by adding the following line to the mmp file: "LIBRARY form.lib tagma.lib".

No comments:

stats counter