- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <cstdio>
int main(void)
{
int val = 500;
printf("%d\n", (int)((long double)val / 500));
printf("%d\n", (int)((long double)500 / 500));
}
显然它应该输出1 1
。但是如果用-Ofast
编译,会输出0 1
,为什么?
而如果你把500
改成其他值(比如400
),用-Ofast
编译,还是会输出 1 1
。
带有 -Ofast
的编译器资源管理器:https://gcc.godbolt.org/z/YkX7fB
似乎这一行导致了问题。
最佳答案
-Ofast
Disregard strict standards compliance.
-Ofast
enables all-O3
optimizations. It also enables optimizations that are not valid for all standard-compliant programs. It turns on-ffast-math
,-fallow-store-data-races
and the Fortran-specific [...]
-ffast-math
Sets the options
-fno-math-errno
,-funsafe-math-optimizations
,-ffinite-math-only
,-fno-rounding-math
,-fno-signaling-nans
,-fcx-limited-range
and-fexcess-precision=fast
.This option causes the preprocessor macro
__FAST_MATH__
to be defined.This option is not turned on by any
-O
option besides-Ofast
since it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/specifications for math functions. It may, however, yield faster code for programs that do not require the guarantees of these specifications.
结论:不要使用-ffast-math
,除非你愿意得到像现在这样的惊喜。
关于c++ - -Ofast 在使用 long double 时产生不正确的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62173863/
我正在优化一个简单的遗传算法和神经网络,我正在 GCC 中摆弄一些选项以生成更快的可执行文件。 在我的代码中,我有一些断言,例如 mat mat_add(mat a, mat b) { ass
我在我的程序中使用 -Ofast gcc 选项导致延迟要求。我写了一个简单的测试程序: #include #include static double quiet_NaN = std::numer
我有一个关于最新 GCC 编译器(版本 >= 5)的问题,代码如下: #include void test_nan ( const float * const __restrict__ in
考虑以下测试程序: # include # include using namespace std; int main() { double y = 50.2944, yc = 63.2128
我在 Swift 中使用 Dictionary 实现本质上是缓存。性能远低于我的预期。我读过其他一些问题,例如 this one about array sorting这似乎表明 -Ofast 是答案
在 g++ 4.6(或更高版本)中,除了 -ffast-math 之外,-Ofast 还启用了哪些额外优化? 手册页说此选项“还启用了并非对所有符合标准的程序都有效的优化”。我在哪里可以找到有关这是否
重新编译旧程序使其输出错误结果。 我想知道为什么 . 我知道-Ofast可能“无视严格的标准合规性”,但我很好奇引擎盖下会发生什么。 我将程序简化为这个 最小示例 foo1.c : #include
我只是在阅读 gcc 手册以找出 -O3 之间的区别和 -Ofast . 对于 -O3 -O3 Optimize yet more. -O3 turns on all optimizations sp
在 xcode 5 中,优化级别引入了一个名为 -Ofast 的新级别。 (最快,积极的优化)。我应该何时以及如何使用此级别? 最佳答案 在 GCC 中,-Ofast 表示允许编译器忽略浮点数的有限精
#include int main(void) { int val = 500; printf("%d\n", (int)((long double)val / 500));
我在 http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options 上的 gcc 文档中找到了 Ofast leve
我在 for 循环中实现了 OpenMP 并行化,其中我有一个 sum,这是导致我的代码变慢的主要原因。当我这样做时,我发现最终结果与我为非并行化代码(用 C 编写)获得的结果不同。所以首先,人们可能
我有一个 C 程序,其中包含 math.h 并使用该 header 中的 sqrt 函数。非常奇怪,当我不传递 -Ofast 标志时,我的代码无法编译。 如果我使用以下代码编译我的代码: gcc -s
我使用 gcc -pg 和 gprof 看到了奇怪的分析结果。 我找不到更好/更小的重现方法,因此我链接了我看到问题的实际代码。 我正在使用代码here ,使用 make prof 构建 gprof
这个问题在这里已经有了答案: Does rustc / cargo have a -march=native equivalent? (1 个回答) 关闭 2 年前。 Rust 是否具有 GCC 的
我正在将索引的地址输入到扩展的内联汇编操作中的表中,但是 GCC 在不需要时生成额外的 lea 指令,即使在使用 -Ofast 时也是如此-fomit-frame-pointer 或 -Os -f..
当使用 -O3 编译下面的基准代码时,它在延迟方面的差异给我留下了深刻的印象,所以我开始怀疑编译器是否通过某种方式删除代码来“作弊”。有办法检查吗?我可以安全地使用 -O3 进行基准测试吗?期望速度提
问题 我们有一个用于模拟任务的中型程序,我们需要对其进行优化。我们已经尽最大努力将源代码优化到我们编程技能的极限,包括使用 Gprof 和 Valgrind 进行分析。 最终完成后,我们希望在多个系统
类似于的SO问题What does gcc's ffast-math actually do? 并且与 Clang optimization levels 的 SO 问题相关,我想知道什么 clang
摘要 根据我的测试,使用 -O0 时 NSArray 的平均访问时间最快。我的测试代码访问长度为 0 到 10000 的所有数组的每个元素。 循环每个数组: start = mach_absolute
我是一名优秀的程序员,十分优秀!