<tfoot id='pemPt'></tfoot>
    1. <small id='pemPt'></small><noframes id='pemPt'>

        <legend id='pemPt'><style id='pemPt'><dir id='pemPt'><q id='pemPt'></q></dir></style></legend>
      1. <i id='pemPt'><tr id='pemPt'><dt id='pemPt'><q id='pemPt'><span id='pemPt'><b id='pemPt'><form id='pemPt'><ins id='pemPt'></ins><ul id='pemPt'></ul><sub id='pemPt'></sub></form><legend id='pemPt'></legend><bdo id='pemPt'><pre id='pemPt'><center id='pemPt'></center></pre></bdo></b><th id='pemPt'></th></span></q></dt></tr></i><div id='pemPt'><tfoot id='pemPt'></tfoot><dl id='pemPt'><fieldset id='pemPt'></fieldset></dl></div>
          <bdo id='pemPt'></bdo><ul id='pemPt'></ul>
      2. 在 gcc 编译器中使用 bts 汇编指令

        时间:2023-09-18
          <tbody id='wZzQZ'></tbody>

        • <small id='wZzQZ'></small><noframes id='wZzQZ'>

            • <bdo id='wZzQZ'></bdo><ul id='wZzQZ'></ul>

                <legend id='wZzQZ'><style id='wZzQZ'><dir id='wZzQZ'><q id='wZzQZ'></q></dir></style></legend>

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

                1. 本文介绍了在 gcc 编译器中使用 bts 汇编指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在 Mac 上使用 bts 和 bt x86 汇编指令来加速我的 C++ 代码中的位操作.在 Windows 上,_bittestandset 和 _bittest 内部函数运行良好,并提供显着的性能提升.在 Mac 上,gcc 编译器似乎不支持这些,所以我尝试直接在汇编程序中进行.

                  I want to use the bts and bt x86 assembly instructions to speed up bit operations in my C++ code on the Mac. On Windows, the _bittestandset and _bittest intrinsics work well, and provide significant performance gains. On the Mac, the gcc compiler doesn't seem to support those, so I'm trying to do it directly in assembler instead.

                  这是我的 C++ 代码(注意位"可以 >= 32):

                  Here's my C++ code (note that 'bit' can be >= 32):

                  typedef unsigned long LongWord;
                  #define DivLongWord(w) ((unsigned)w >> 5)
                  #define ModLongWord(w) ((unsigned)w & (32-1))
                  
                  inline void SetBit(LongWord array[], const int bit)
                  {
                     array[DivLongWord(bit)] |= 1 << ModLongWord(bit);
                  }
                  
                  inline bool TestBit(const LongWord array[], const int bit)
                  {
                      return (array[DivLongWord(bit)] & (1 << ModLongWord(bit))) != 0;
                  }
                  

                  以下汇编代码可以工作,但不是最优的,因为编译器无法优化寄存器分配:

                  The following assembler code works, but is not optimal, as the compiler can't optimize register allocation:

                  inline void SetBit(LongWord* array, const int bit)
                  {
                     __asm {
                        mov   eax, bit
                        mov   ecx, array
                        bts   [ecx], eax
                     }
                  }
                  

                  问题:如何让编译器围绕 bts 指令进行全面优化?以及如何用 bt 指令替换 TestBit?

                  Question: How do I get the compiler to fully optimize around the bts instruction? And how do I replace TestBit by a bt instruction?

                  推荐答案

                  inline void SetBit(*array, bit) {
                      asm("bts %1,%0" : "+m" (*array) : "r" (bit));
                  }
                  

                  这篇关于在 gcc 编译器中使用 bts 汇编指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:用于处理/解调函数的函数 下一篇:将 ADC(带进位相加)组装到 C++

                  相关文章

                  最新文章

                2. <small id='BoIwS'></small><noframes id='BoIwS'>

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

                      <legend id='BoIwS'><style id='BoIwS'><dir id='BoIwS'><q id='BoIwS'></q></dir></style></legend>