views:

122

answers:

2

Does 80x86 have instructions for atomically testing and setting individual bits of a word?

A: 

Yes, they have. See here for a complete reference: http://en.wikipedia.org/wiki/X86_instruction_listings

Konamiman
It's not necessarily that simple. If the OP wants to test atomicity at the bit level, then the answer is no.
bcat
+6  A: 

If you mean testing and modifying a bit as a single atomic operation, then the bit test instructions (BT, BTS, BTR, and BTC) can all be made atomic by using the LOCK prefix.

If you mean testing a bit atomically, and then setting a bit atomically as separate operations, you can test the bit using a standard atomic read, and modifying the bit can be done using LOCK OR, LOCK AND, LOCK XOR instructions.

If you need something more complicated, e.g. testing one bit and then setting a different bit, you'll have to use the standard compare-and-swap CMPXCHG instruction in a retry loop.

Niall