原子位测试和设置(BTS)的程序集内在函数 [英] assembly intrinsic for atomic bit test and set (BTS)

查看:70
本文介绍了原子位测试和设置(BTS)的程序集内在函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结构节点*地址;//format< addr,flagBit1,flagBit2>

我想使用BTS 原子上设置 flagBit1 位.

I want to use BTS to atomically set the flagBit1 bit.

编辑

我想盲目设置此位,而不关心之前是否已设置

我可以按照使用bts汇编中的建议使用汇编代码来完成此操作gcc编译器的说明

但是我可以使用一种可在不同体系结构之间移植的内在函数吗?

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 ,而只是执行 lock或应该没问题.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆