26.11.2012 Views

Compiler Usage Guidelines for 64-Bit Operating Systems on AMD64 ...

Compiler Usage Guidelines for 64-Bit Operating Systems on AMD64 ...

Compiler Usage Guidelines for 64-Bit Operating Systems on AMD64 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

32035 Rev. 3.22 November 2007<br />

4.2.2 Link-Time Errors<br />

Are you trying to link C and Fortran code?<br />

<str<strong>on</strong>g>Compiler</str<strong>on</strong>g> <str<strong>on</strong>g>Usage</str<strong>on</strong>g> <str<strong>on</strong>g>Guidelines</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> AMD<str<strong>on</strong>g>64</str<strong>on</strong>g> Plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms<br />

Turn <strong>on</strong> the -fno-f2c switch <str<strong>on</strong>g>for</str<strong>on</strong>g> compiling Fortran 77 modules with g77. Turning <strong>on</strong> the -fno-f2c<br />

switch prevents g77 from generating code designed to be compatible with code generated by f2c and<br />

uses the GNU calling c<strong>on</strong>venti<strong>on</strong>s instead.<br />

4.2.3 Run-Time Errors<br />

Is your code causing buffer overruns?<br />

Turn <strong>on</strong> the -fbounds-check switch. When the -fbounds-check switch is turned <strong>on</strong>, the GCC<br />

compiler generates additi<strong>on</strong>al code to check whether the indices used to access arrays are or are not<br />

within the declared range. The -fbounds-check switch is currently supported <strong>on</strong>ly by the Fortran 77<br />

fr<strong>on</strong>t-end, in which this opti<strong>on</strong> defaults to false.<br />

Are you building a shared library?<br />

Turn <strong>on</strong> the -fPIC switch if you need positi<strong>on</strong>-independent code suitable <str<strong>on</strong>g>for</str<strong>on</strong>g> use in a shared library.<br />

4.2.4 Compiled and Linked Code Generates Unexpected Results<br />

Does your program depend <strong>on</strong> precise floating point behavior?<br />

Do not use the -ffast-math switch. When the -ffast-math is used, the compiler relaxes the rules when<br />

optimizing floating-point operati<strong>on</strong>s. This mode allows the compiler to further optimize floatingpoint<br />

code <str<strong>on</strong>g>for</str<strong>on</strong>g> speed, sometimes at the expense of floating-point accuracy. Do not use the -ffast-math<br />

switch if precise floating-point behavior is required.<br />

Does your program rely <strong>on</strong> x87 features?<br />

The <str<strong>on</strong>g>64</str<strong>on</strong>g>-bit GCC compiler emits SSE/SSE2 code with -mfpmath=sse, which can yield better<br />

per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. SSE2 offers <str<strong>on</strong>g>64</str<strong>on</strong>g>-bit precisi<strong>on</strong>, which is sufficient <str<strong>on</strong>g>for</str<strong>on</strong>g> almost all programs. If the results<br />

do not match your expectati<strong>on</strong>s when using SSE2, the program may rely <strong>on</strong> some x87 features.<br />

As a diagnostic step, try building the program using x87 operati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> floating-point computati<strong>on</strong>s<br />

and see if the results are as expected. Do this by omitting the -mfpmath=sse switch recommended in<br />

the general per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance guidelines. By default the compiler uses -mfpmath=387.<br />

Because omitting the -mfpmath=sse switch could lower per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, the user should investigate the<br />

precisi<strong>on</strong> requirements of the program. If the user has access to the source code, it may be possible to<br />

adapt the algorithm to SSE2.<br />

4.2.5 Program Gives Unexpected Results or Excepti<strong>on</strong> Behavior<br />

Does your code depend <strong>on</strong> exact implementati<strong>on</strong> of IEEE rules or specificati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> floating-point<br />

behavior?<br />

Chapter 4 Troubleshooting and Portability Issues 45

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!