# Optimization

• -mfast-float

The switch, causes fast, non-ieee compliant versions of some of the optimized AVR 32-bit floating-point library functions to be used. This switch is by default enabled if the ‘-ffast-math’ switch is used.

• -funsafe-math-optimizations

Allow optimizations for floating-point arithmetic that (a) assume that arguments and results are valid and (b) may violate IEEE or ANSI standards. When used at link-time, it may include libraries or start-up files that change the default FPU control word or other similar optimizations. This option is not turned ON by any ‘-O’ option since it can result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rules/specifications for math functions. It may, however, yield faster code for programs that do not require the guarantees of these specifications. Enables ‘-fno-signed-zeros’, ‘-fno-trapping-math’, ‘-fassociative-math’ and ‘-freciprocal-math’.

• -ffast-math

This option causes the preprocessor macro __FAST_MATH__ to be defined. This option is not turned on by any ‘-O’ option since it can result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rules/specifications for math functions. It may, however, yield faster code for programs that do not require the guarantees of these specifications. It sets ‘-fno-math-errno’, ‘-funsafe-math-optimizations’, ‘-ffinite-math-only’, ‘-fno-rounding-math’, ‘-fno-signaling-nans’ and ‘-fcx-limited-range’.

• -fpic

Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that ‘-fpic’ does not work; in that case, recompile with ‘-fPIC’ instead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000. The 386 has no such limit.) Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent. When this flag is set, the macros __pic__ and __PIC__ are defined to 1.

• -mno-init-got

Do not initialize GOT register before using it when compiling PIC code.

• -masm-addr-pseudos

This option is enabled by default and causes GCC to output the pseudo instructions call and lda.w for calling direct functions and loading symbol addresses respectively. It can be turned OFF by specifying the switch ‘-mno-asm-addr-pseudos’. The advantage of using these pseudo-instructions is that the linker can optimize these instructions at link time if linker relaxing is enabled. The ‘-mrelax’ option can be passed to GCC to signal to the assembler that it should generate a relaxable object file.

• -mforce-double-align

Force double-word alignment for double-word memory accesses.

• -mimm-in-const-pool

When GCC needs to move immediate values not suitable for a single move instruction into a register, it has two possible choices; it can put the constant into the code somewhere near the current instruction (the constant pool) and then use a single load instruction to load the value or it can use two immediate instruction for loading the value directly without using a memory load. If a load from the code memory is faster than executing two simple one-cycle immediate instructions, then putting these immediate values into the constant pool will be most optimal for speed. This is often true for MCU architectures implementing an instruction cache, whereas architectures with code executing from the internal flash will probably need several cycles for loading values from code memory. By default, GCC will use the constant pool for AVR 32-bit products with an instruction cache and two immediate instructions for flash-based MCUs. This can be overridden by using the option ‘-mimm-in-const-pool’ or its negated option ‘-mno-imm-in-const-pool’.

• -muse-rodata-sections

By default GCC will output read-only data into the code (.text) section. If the code memory is slow it might be more optimal for performance to put read-only data into another faster memory, if available. This can be done by specifying the switch ‘-muse-rodata-section’, which makes GCC put read-only data into the .rodata section. Then the linker file can specify where the content of the .rodata section should be placed. For systems running code from flash, this might, however, mean that the read-only data must be placed in flash and then copied over to another memory at start-up, which means that extra memory usage is required with this scheme.