Settings

Theme

Ask HN: Can someone make a CAS just checking last bit on x86/ARM please?

4 points by goofy_lemur 3 months ago · 3 comments · 1 min read


Guys/gals, I was thinking about doing some work here and I noticed there's no operation that allows a atomic compare/exchange based on the last bit.

There should be an instruction that allows you to do an update of a 64 bit value only if the last bit is a 0.

The idea here is you would be able to swap pointer values atomically only if they were unlocked.

2^63 is such a huge number, it is sufficient to represent practically all the data in the universe. If we allowed an atomic compare exchange on the last bit, or something like check if the last bit is 0, allow the write, otherwise don't, it would make programming a lot easier.

Thanks!

Normal_gaussian 3 months ago

You're going to have to give a much clearer set of examples and justifications. I've had to CAS on bit masks, but not enough that it would make sense to introduce a new operation for it. I just CAS and spin if it fails and the bitmask is still valid.

  • goofy_lemurOP 3 months ago

    all right, I am doing a sort of a copy-on-write thing here. So the idea is that I only want to update the pointer if the record it points to is "unlocked"

charleslmunger 3 months ago

What hardware are you running on where the cost of a relaxed 64 bit load and a branch is significant compared to a (possibly contended) cas?

You could always use ldset on arm for this.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection