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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

32035 Rev. 3.22 November 2007<br />

4.12.1 Run-Time Errors<br />

Is your code causing buffer overruns that violate security?<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 /GS switch. Turning <strong>on</strong> the /GS switch causes the Microsoft compiler to generate<br />

additi<strong>on</strong>al security code, such as bounds checking.<br />

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

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

Do not use the /fp:fast switch recommended in the general per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance guidelines. When the fp:fast<br />

mode is enabled, the compiler relaxes the rules that fp:precise uses when optimizing floating-point<br />

operati<strong>on</strong>s. This mode allows the compiler to further optimize floating-point code <str<strong>on</strong>g>for</str<strong>on</strong>g> speed at the<br />

expense of floating-point accuracy.<br />

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

The /arch:SSE2 switch instructs the compiler to use SSE2 registers and instructi<strong>on</strong>s. If the results do<br />

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. Omitting the /arch:SSE2 switch recommended in the general<br />

per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance guidelines causes the compiler to build the program using x87 operati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> floatingpoint<br />

computati<strong>on</strong>s.<br />

Because omitting the /arch:SSE2 switch could degrade 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.12.3 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 or ISO rules or specificati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> floatingpoint<br />

behavior?<br />

Do not use /fp:fast optimizati<strong>on</strong>, as recommended in the general per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance guidelines, in this case.<br />

The compiler uses /fp:precise by default if no /fp switch is specified.<br />

Does your code need structured and/or C++ excepti<strong>on</strong> handling?<br />

Enable C++ excepti<strong>on</strong> handling with the appropriate /EH switch.<br />

Are you to developing 32-bit code that you may eventually port to <str<strong>on</strong>g>64</str<strong>on</strong>g>-bit code, and you would like the<br />

code to remain compatible?<br />

Use /Wp<str<strong>on</strong>g>64</str<strong>on</strong>g> to detect <str<strong>on</strong>g>64</str<strong>on</strong>g>-bit porting problems. This switch can be used with both 32-bit and <str<strong>on</strong>g>64</str<strong>on</strong>g>-bit<br />

Microsoft compilers.<br />

On AMD<str<strong>on</strong>g>64</str<strong>on</strong>g> architecture-based systems running the Microsoft Windows operating system, both int<br />

and l<strong>on</strong>g are 32-bit, and pointers are <str<strong>on</strong>g>64</str<strong>on</strong>g>-bit (P<str<strong>on</strong>g>64</str<strong>on</strong>g>). Do not use int or l<strong>on</strong>g <str<strong>on</strong>g>for</str<strong>on</strong>g> type-casting pointers.<br />

Chapter 4 Troubleshooting and Portability Issues 53

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

Saved successfully!

Ooh no, something went wrong!