From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Chen, Kenneth W" Date: Thu, 15 Jun 2006 20:50:33 +0000 Subject: RE: Why does ia64 not use fetchadd in atomic.h? Message-Id: <000001c690bd$58f41e10$e434030a@amr.corp.intel.com> List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-ia64@vger.kernel.org Christoph Lameter wrote on Thursday, June 15, 2006 1:36 PM > I just looked at at the asm generated by some of the use of atomic for > statistics and saw that there were complicated compxchg constructs where I > would have expected a simple fetchadd. Why is this? > > F.e. > > static __inline__ int > ia64_atomic_add (int i, atomic_t *v) > { > __s32 old, new; > CMPXCHG_BUGCHECK_DECL > > do { > CMPXCHG_BUGCHECK(v); > old = atomic_read(v); > new = old + i; > } while (ia64_cmpxchg(acq, v, old, new, sizeof(atomic_t)) != old); > return new; > } > > Why not > > #define ia64_atomic_add(__i, __v) ia64_fetchadd(__i, &v->counter, acq) The immediate operand of fetchadd only takes limited value, so it would have to be a combination of fetchadd and cmpxchg. If the constant is known at compile time, it can be optimized for those constants that fetchadd can operate on. Back to your original question, I guess whoever implements ia64_atomic_add didn't bother to optimize it like it's close cousin of atomic_add(). - Ken