Specifications
Chapter 4 Troubleshooting and Portability Issues 49
Compiler Usage Guidelines for AMD64 Platforms
32035 Rev. 3.22 November 2007
within the declared range. The -fbounds-check switch is currently supported only by the Fortran 77
front-end, in which this option defaults to false.
Are you building a shared library?
Turn on the -fPIC switch if you need position-independent code suitable for use in a shared library.
4.8.4 Compiled and Linked Code Generates Unexpected Results
Does your program depend on precise floating-point behavior?
Experiment without the -ffast-math switch. When the -ffast-math is used, the compiler relaxes the
rules when optimizing floating-point operations. This mode allows the compiler to further optimize
floating-point code for speed, sometimes at the expense of floating-point accuracy. Do not use the
-ffast-math switch if precise floating-point behavior is required.
Does your program rely on x87 features?
The 32-bit GCC compiler emits SSE/SSE2 code with -mfpmath=sse, which can yield better
performance. SSE2 offers 64-bit precision, which is sufficient for most programs. If the results do not
match your expectations when using SSE2, the program may rely on some x87 features.
As a diagnostic step, try building the program using x87 operations for floating-point computations,
and see if the results are as expected. By omitting the -mfpmath=sse switch recommended in the
general performance guidelines, the compiler uses -mfpmath=387 by default.
Because omitting the -mfpmath=sse switch could lower performance, the user should investigate the
precision requirements of the program. If the user has access to the source code, it may be possible to
adapt the algorithm to SSE2.
4.8.5 Program Gives Unexpected Results or Exception Behavior
Does your code depend on exact implementation of IEEE rules or specifications for floating-point
behavior?
GCC provides switches, such as the -mieee-fp switch, to control whether or not the compiler uses
IEEE floating point comparisons.
The user should not use the -ffast-math optimization recommended in the general optimization
guidelines in this case. Using the -ffast-math switch results in a fast, but less predictable, floating-
point model. The user should also be careful to not use a switch that implies -ffast-math.
Does your code need C++ exception handling?
GCC generates the extra code needed to propagate exceptions with the -fexceptions switch. For some
targets, propagating exceptions implies that GCC generates frame unwind information for all
functions. Generating frame unwind information for all functions can produce significant data-size
overhead, although it does not affect the execution of a program.