Specifications

Chapter 4 Troubleshooting and Portability Issues 45
Compiler Usage Guidelines for AMD64 Platforms
32035 Rev. 3.22 November 2007
4.2.2 Link-Time Errors
Are you trying to link C and Fortran code?
Turn on the -fno-f2c switch for compiling Fortran 77 modules with g77. Turning on the -fno-f2c
switch prevents g77 from generating code designed to be compatible with code generated by f2c and
uses the GNU calling conventions instead.
4.2.3 Run-Time Errors
Is your code causing buffer overruns?
Turn on the -fbounds-check switch. When the -fbounds-check switch is turned on, the GCC
compiler generates additional code to check whether the indices used to access arrays are or are not
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.2.4 Compiled and Linked Code Generates Unexpected Results
Does your program depend on precise floating point behavior?
Do not use 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 64-bit GCC compiler emits SSE/SSE2 code with -mfpmath=sse, which can yield better
performance. SSE2 offers 64-bit precision, which is sufficient for almost all 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. Do this by omitting the -mfpmath=sse switch recommended in
the general performance guidelines. By default the compiler uses -mfpmath=387.
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.2.5 Program Gives Unexpected Results or Exception Behavior
Does your code depend on exact implementation of IEEE rules or specifications for floating-point
behavior?