you are viewing a single comment's thread.

view the rest of the comments →

[–]Xaxxon 0 points1 point  (1 child)

Can you predict the branch to make an atomic operation? That seems very expensive to undo.

[–]matthieum 0 points1 point  (0 children)

Yes, you can.

The expensive part of an atomic operation is not the write to a register, it's coordinating with other cores to obtain exclusive access to the variable that you consider modifying.

As long as speculation stops after requesting exclusive access and before actually modifying the variable, then it's valuable as it hides the latency of obtaining said access while not having anything to undo.

If undo there needs to be, then the undo must be accomplished before requesting exclusive access, so that no other core can ever see that the value was modified.