Albert Lee wrote:
Someone inquired on IRC about the atomic increment/decrement functions on
i386/amd64.
The atomic_{inc,dec}_*_nv functions are implemented as a leaq + cmpxchg
loop. For example:
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/common/atomic/amd64/atomic.s#76
The question was why these don't use an xadd instead. I'm pretty sure it
would take fewer cycles in any case, so this is weird.
Any thoughts?
-Albert
"no immediate form" makes it a little suboptimal; you'd have to put 1 in a reg
first. And of course you'd want LOCK too. It wouldn't surprise me if the
author(s) simply weren't aware of xadd; I'd never heard of it until you
mentioned it (not that I'm any kind of instruction-set expert)...
The "exchange, then sum" is somewhat confusing, too; I guess it's so you can get
the old value of a memory location to then test, if you wish, which is
irrelevant here, but that might make me shy away from the instruction as "doing
stuff I don't want".
but I'm just speculating; don't know the real reason.
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code