arunmoezhi
arunmoezhi

Reputation: 3200

assembly intrinsic for atomic bit test and set (BTS)

struct node* address; //format <addr,flagBit1,flagBit2>

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

EDIT

I want to blindly set this bit without caring about if it was previously set or not

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?

For instance, gcc Atomic Builtins has __sync_fetch_and_or. Does this have the same property as BTS?

Upvotes: 0

Views: 2110

Answers (1)

Jester
Jester

Reputation: 58782

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.

Upvotes: 3

Related Questions