<i id='fxF3o'><tr id='fxF3o'><dt id='fxF3o'><q id='fxF3o'><span id='fxF3o'><b id='fxF3o'><form id='fxF3o'><ins id='fxF3o'></ins><ul id='fxF3o'></ul><sub id='fxF3o'></sub></form><legend id='fxF3o'></legend><bdo id='fxF3o'><pre id='fxF3o'><center id='fxF3o'></center></pre></bdo></b><th id='fxF3o'></th></span></q></dt></tr></i><div id='fxF3o'><tfoot id='fxF3o'></tfoot><dl id='fxF3o'><fieldset id='fxF3o'></fieldset></dl></div>

    <tfoot id='fxF3o'></tfoot>
    <legend id='fxF3o'><style id='fxF3o'><dir id='fxF3o'><q id='fxF3o'></q></dir></style></legend>
  • <small id='fxF3o'></small><noframes id='fxF3o'>

        <bdo id='fxF3o'></bdo><ul id='fxF3o'></ul>

        使编译器/优化器能够制作更快程序的编码实践

        时间:2023-09-16
      1. <small id='E1uLK'></small><noframes id='E1uLK'>

        <legend id='E1uLK'><style id='E1uLK'><dir id='E1uLK'><q id='E1uLK'></q></dir></style></legend>
        • <bdo id='E1uLK'></bdo><ul id='E1uLK'></ul>

                <tbody id='E1uLK'></tbody>
                  <tfoot id='E1uLK'></tfoot>
                  <i id='E1uLK'><tr id='E1uLK'><dt id='E1uLK'><q id='E1uLK'><span id='E1uLK'><b id='E1uLK'><form id='E1uLK'><ins id='E1uLK'></ins><ul id='E1uLK'></ul><sub id='E1uLK'></sub></form><legend id='E1uLK'></legend><bdo id='E1uLK'><pre id='E1uLK'><center id='E1uLK'></center></pre></bdo></b><th id='E1uLK'></th></span></q></dt></tr></i><div id='E1uLK'><tfoot id='E1uLK'></tfoot><dl id='E1uLK'><fieldset id='E1uLK'></fieldset></dl></div>
                  本文介绍了使编译器/优化器能够制作更快程序的编码实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  很多年前,C 编译器并不是特别聪明.作为一种解决方法,K&R 发明了 register 关键字,以提示编译器,将这个变量保存在内部寄存器中可能是个好主意.他们还制作了三级运算符以帮助生成更好的代码.

                  Many years ago, C compilers were not particularly smart. As a workaround K&R invented the register keyword, to hint to the compiler, that maybe it would be a good idea to keep this variable in an internal register. They also made the tertiary operator to help generate better code.

                  随着时间的推移,编译器逐渐成熟.他们变得非常聪明,因为他们的流分析使他们能够比您可能做的更好地决定在寄存器中保存哪些值.register 关键字变得不重要了.

                  As time passed, the compilers matured. They became very smart in that their flow analysis allowing them to make better decisions about what values to hold in registers than you could possibly do. The register keyword became unimportant.

                  由于别名,对于某些类型的操作,FORTRAN 可能比 C 更快问题.理论上,通过仔细编码,可以绕过这一限制,使优化器能够生成更快的代码.

                  FORTRAN can be faster than C for some sorts of operations, due to alias issues. In theory with careful coding, one can get around this restriction to enable the optimizer to generate faster code.

                  哪些编码实践可以让编译器/优化器生成更快的代码?

                  • 确定您使用的平台和编译器,我们将不胜感激.
                  • 为什么该技术似乎有效?
                  • 鼓励使用示例代码.

                  这是一个相关问题

                  这个问题与分析和优化的整体过程无关.假设程序已经正确编写、充分优化编译、测试并投入生产.您的代码中可能存在阻止优化器尽其所能完成最佳工作的构造.您可以做些什么来重构以消除这些禁令,并允许优化器生成更快的代码?

                  This question is not about the overall process to profile, and optimize. Assume that the program has been written correctly, compiled with full optimization, tested and put into production. There may be constructs in your code that prohibit the optimizer from doing the best job that it can. What can you do to refactor that will remove these prohibitions, and allow the optimizer to generate even faster code?

                  偏移相关链接

                  推荐答案

                  写入局部变量而不是输出参数!这对于解决混叠减速问题非常有帮助.例如,如果您的代码看起来像

                  Write to local variables and not output arguments! This can be a huge help for getting around aliasing slowdowns. For example, if your code looks like

                  void DoSomething(const Foo& foo1, const Foo* foo2, int numFoo, Foo& barOut)
                  {
                      for (int i=0; i<numFoo, i++)
                      {
                           barOut.munge(foo1, foo2[i]);
                      }
                  }
                  

                  编译器不知道 foo1 != barOut,因此每次循环都必须重新加载 foo1.在对 barOut 的写入完成之前,它也无法读取 foo2[i].您可以开始使用受限制的指针,但这样做同样有效(并且更清晰):

                  the compiler doesn't know that foo1 != barOut, and thus has to reload foo1 each time through the loop. It also can't read foo2[i] until the write to barOut is finished. You could start messing around with restricted pointers, but it's just as effective (and much clearer) to do this:

                  void DoSomethingFaster(const Foo& foo1, const Foo* foo2, int numFoo, Foo& barOut)
                  {
                      Foo barTemp = barOut;
                      for (int i=0; i<numFoo, i++)
                      {
                           barTemp.munge(foo1, foo2[i]);
                      }
                      barOut = barTemp;
                  }
                  

                  这听起来很傻,但是编译器可以更聪明地处理局部变量,因为它不可能在内存中与任何参数重叠.这可以帮助您避免可怕的加载命中存储(Francis Boivin 在此线程中提到).

                  It sounds silly, but the compiler can be much smarter dealing with the local variable, since it can't possibly overlap in memory with any of the arguments. This can help you avoid the dreaded load-hit-store (mentioned by Francis Boivin in this thread).

                  这篇关于使编译器/优化器能够制作更快程序的编码实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 SSE/AVX 获取存储在 __m256d 中的值的总和 下一篇:C++ 中正弦、余弦和平方根的最快实现(不需要太准

                  相关文章

                  最新文章

                  <tfoot id='DqD5o'></tfoot>

                  <small id='DqD5o'></small><noframes id='DqD5o'>

                      <i id='DqD5o'><tr id='DqD5o'><dt id='DqD5o'><q id='DqD5o'><span id='DqD5o'><b id='DqD5o'><form id='DqD5o'><ins id='DqD5o'></ins><ul id='DqD5o'></ul><sub id='DqD5o'></sub></form><legend id='DqD5o'></legend><bdo id='DqD5o'><pre id='DqD5o'><center id='DqD5o'></center></pre></bdo></b><th id='DqD5o'></th></span></q></dt></tr></i><div id='DqD5o'><tfoot id='DqD5o'></tfoot><dl id='DqD5o'><fieldset id='DqD5o'></fieldset></dl></div>

                    1. <legend id='DqD5o'><style id='DqD5o'><dir id='DqD5o'><q id='DqD5o'></q></dir></style></legend>
                        <bdo id='DqD5o'></bdo><ul id='DqD5o'></ul>