c - icc -fast 标志的错误结果

标签 c optimization compilation compiler-optimization icc

现在我正在使用 icc 来编译和运行我的 ANSI C 代码。

当我打开-O2 优化时,一切正常。但是,当我更改为 -fast 时,结果会有所不同(有很多 nan)。

我搜索并尝试,发现错误存在于-xHOST in -fast 的原因。

我想知道 -xHOST 在编译时是如何工作的。以及如何在我的代码中避免这种错误?

最佳答案

-fast turns on many aggressive compiler options below is from the intel docs

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

关于c - icc -fast 标志的错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12701544/

相关文章:

c - 从 csv 文件读入二维数组并使用 c 对数组进行排序

c++ - msvcr100d.dll 中未处理的异常

c - 字符串打乱 - 替换无法正常工作的字符

c++ - 分支预测和分支目标预测优化

c++ - 大量警告会增加编译时间吗?

c - 通过在编译时替换静态符号来测试嵌入式代码

ios - Swift:奇怪的 XCode 行为在 NSArray 的子类中具有必需的初始化程序

c - 如何查找循环安装设备的文件?

mysql - 优化 MySQL 查询,耗时将近 20 秒!

c - 在 C 中,!~b 会比 b == 0xff 快吗?