2012-10-03 65 views
1

現在我使用icc編譯並運行我的ANSI C代碼。錯誤的結果與icc -fast標誌

當我打開-O2優化時,一切正常。但是,當我改變爲快速時,結果會發生變化(有很多南)。

我用Google搜索並嘗試了一下,發現-xHOST在-fast中的錯誤原因。

我想知道-xHOST在編譯時如何工作。以及如何避免我的代碼中的這種錯誤?

+0

這聽起來像是優化混亂了你的浮點模式。 – Mysticial

+0

如果你的目標是準確的,你應該確保你的優化導致fp數學摺疊,這可能會歪曲結果 – Necrolis

回答

1

-fast打開許多侵略性的編譯器選項下面是來自英特爾文檔

Description 
This option maximizes speed across the entire program. It sets the following options: 
• On Itanium®-based systems: Windows: /O3 and /Qipo Linux: -ipo, -O3, and -static 
• On IA-32 and Intel® EM64T systems: 
Mac OS: -ipo, -O3, -no-prec-div, and -static 
Windows: /O3, /Qipo, /Qprec-div-, and /QxP 
Linux: -ipo, -O3, -no-prec-div, -static, and -xP 
Note that programs compiled with the -xP (Linux) or /QxP (Windows) option will detect non-compatible processors and generate an error message during execution. 
On IA-32 and Intel® EM64T systems, the -xP or /QxP option that is set by the fast option cannot be overridden by other command line options. If you specify the fast option and a different processor-specific option, such as -xN (Linux) or /QxN (Windows) 

其中作爲-xHost

Generates instruction sets up to the highest that is supported by the compilation host. On Intel processors, this corresponds to the most suitable /Qx (-x) option; on compatible, non-Intel processors, this corresponds to the most suitable of the /arch (-m) options IA32, SSE2 or SSE3. This option may result in additional optimizations for Intel microprocessors that are not 
performed for non-Intel microprocessors.‡ 

因此如果問題是-xHost看是否執行爲-march你的處理器正確的拱門類型修復了錯誤,或者只使用-O3

+0

-快速也會打開激進的FP優化選項 - 這會導致提問者正在尋找的浮點數瑕疵 – LThode