[prev in list] [next in list] [prev in thread] [next in thread] 

List:       opensolaris-code
Subject:    Re: [osol-code] i386 atomic inc/dec function
From:       Dan Mick <dan.mick () sun ! com>
Date:       2009-10-10 2:26:25
Message-ID: 4ACFF0D1.7050800 () sun ! com
[Download RAW message or body]

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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic