简体   繁体   English

使用编译标志-o3复制数组

[英]Array copying with compile flag -o3

When compiling the code below with gcc -o3 it takes around 50% longer time than without the "-o3". 当使用gcc -o3编译下面的代码时,与不使用“ -o3”相比,它花费的时间大约长50%。 What can be the reason for that? 可能是什么原因呢?

const int stepsize = 2;
for (j = 0; j < NOOFITERATIONS; j++) {
  for(i=0; i < ROUND_DOWN(SOMEBIGSIZE, stepsize); i+=stepsize) {
      c[i] = a[i] + b[i];
      c[i+1] = a[i+1] + b[i+1];
  }
  for(; i < SOMEBIGSIZE; i++)
      c[i] = a[i] + b[i];
}

Taken from the GCC docs (all emphasis mine): 取自GCC文档 (全部为我的重点):

Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program. 启用优化标志会使编译器尝试以牺牲编译时间和调试程序的能力为代价来提高性能和/或代码大小。 [...] [...]

Optimizing compilation takes somewhat more time , and a lot more memory for a large function. 优化编译需要更多的时间 ,而大型函数需要更多的内存。

With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time . 使用-O时,编译器会尝试减少代码大小和执行时间,而不执行任何占用大量编译时间的优化。

This is completely expected behavior. 这是完全预期的行为。 Basically, your compiler needs to do more work for you, which increases the compilation time. 基本上,您的编译器需要为您做更多的工作,这会增加编译时间。

From the Optimize Options - 从“ 优化选项”中 -

Optimize yet more. 优化更多。 -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-loop-vectorize, -ftree-slp-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options. -O3打开-O2指定的所有优化,还打开-finline-functions,-funswitch-loops,-fpredictive-commoning,-fgcse-re-reload,-ftree-loop-vectorize,-ftree-slp-vectorize ,-fvect-cost-model,-ftree-partial-pre和-fipa-cp-clone选项。

My assumption is those are expensive optimizations with your loops... especially the loop vectorize optimization. 我的假设是那些昂贵的循环优化……尤其是循环矢量优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM