English 中文(简体)
Atomic bitfield operations on 80x86?
原标题:

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

问题回答

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.





相关问题
Minimum bit length needed for a positive integer in Python

1 = 0b1 -> 1 5 = 0b101 -> 3 10 = 0b1010 -> 4 100 = 0b1100100 -> 7 1000 = 0b1111101000 -> 10 … How can I get the bit length of an integer, i.e. the number of bits that are necessary to ...

C/C++ efficient bit array

Can you recommend efficient/clean way to manipulate arbitrary length bit array? Right now I am using regular int/char bitmask, but those are not very clean when array length is greater than datatype ...

Why is it useful to count the number of bits?

I ve seen the numerous questions about counting the number of set bits in an insert type of input, but why is it useful? For those looking for algorithms about bit counting, look here: Counting ...

Comparing set of bits in byte array

I have a byte array, as follows: byte[] array = new byte[] { 0xAB, 0x7B, 0xF0, 0xEA, 0x04, 0x2E, 0xF3, 0xA9}; The task is to find the quantity of occurrences 0xA in it. Could you advise what to ...

One s complement instead of just a sum of bits

A question in my university homework is why use the one s complement instead of just the sum of bits in a TCP checksum. I can t find it in my book and Google isn t helping. Any chance someone can ...

热门标签