Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top