相关疑难解决方法(0)

为什么Clang优化x*1.0而不是x + 0.0?

为什么Clang会优化此代码中的循环

#include <time.h>
#include <stdio.h>

static size_t const N = 1 << 27;
static double arr[N] = { /* initialize to zero */ };

int main()
{
    clock_t const start = clock();
    for (int i = 0; i < N; ++i) { arr[i] *= 1.0; }
    printf("%u ms\n", (unsigned)(clock() - start) * 1000 / CLOCKS_PER_SEC);
}
Run Code Online (Sandbox Code Playgroud)

但不是这段代码中的循环?

#include <time.h>
#include <stdio.h>

static size_t const N = 1 << 27;
static double arr[N] = { /* initialize to zero */ }; …
Run Code Online (Sandbox Code Playgroud)

c c++ floating-point optimization clang

125
推荐指数
2
解决办法
5523
查看次数

标签 统计

c ×1

c++ ×1

clang ×1

floating-point ×1

optimization ×1