装配内在的位测试和设置(BTS) [英] assembly intrinsic for bit test and set (BTS)
问题描述
结构节点*地址; //格式<地址,flagBit1,flagBit2>
我想用BTS为原子设置 flagBit1
位。
I want to use BTS to atomically set the flagBit1
bit.
修改
我要盲目设置该位,但不关心,如果它是previously设置或不
我可以使用汇编code得到这个工作作为<建议href=\"http://stackoverflow.com/questions/1983303/using-bts-assembly-instruction-with-gcc-compiler\">Using用gcc编译BTS汇编指令
I can use assembly code to get this done as suggested in Using bts assembly instruction with gcc compiler
但有一个内在的我可以用它在不同的架构移植?
But is there an intrinsic I can use which is portable across different architectures?
例如, GCC原子内建命令有 __ sync_fetch_and_or
。这是否具有相同的属性作为BTS?
For instance, gcc Atomic Builtins has __sync_fetch_and_or
. Does this have the same property as BTS?
推荐答案
有关有点盲目设置, sync_fetch_and_or
或 sync_or_and_fetch
似乎都同样好,其结果丢弃编译器知道以优化它。
在x86上GCC不会用 BTS
,相反,它只会做一个锁或
这应该是罚款。
For a blind setting of a bit, sync_fetch_and_or
or sync_or_and_fetch
seem to be both equally good, with the result discarded the compiler knows to optimize it out.
On x86 gcc won't use bts
, instead it will simply do a lock or
which should be fine.
这篇关于装配内在的位测试和设置(BTS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!