From: Ian Campbell Subject: Re: [PATCH 16/17] xen: arm: refactor xchg and cmpxchg into their own headers Date: Fri, 21 Mar 2014 08:42:20 +0000 Message-ID: <1395391340.11953.7.camel@dagon.hellion.org.uk> References: <1395330336.3104.12.camel@kazak.uk.xensource.com> <1395330365-9901-16-git-send-email-ian.campbell@citrix.com> <532B2AEF.5010905@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <532B2AEF.5010905@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Julien Grall Cc: stefano.stabellini@eu.citrix.com, tim@xen.org, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Thu, 2014-03-20 at 17:52 +0000, Julien Grall wrote: > Hi Ian, > > On 03/20/2014 03:46 PM, Ian Campbell wrote: > > diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h > > new file mode 100644 > > index 0000000..70c6090 > > --- /dev/null > > +++ b/xen/include/asm-arm/arm32/cmpxchg.h > > +static always_inline unsigned long __cmpxchg( > > + volatile void *ptr, unsigned long old, unsigned long new, int size) > > +{ > > + unsigned long oldval, res; > > + > > + switch (size) { > > + case 1: > > + do { > > + asm volatile("@ __cmpxchg1\n" > > + " ldrexb %1, [%2]\n" > > + " mov %0, #0\n" > > + " teq %1, %3\n" > > + " strexbeq %0, %4, [%2]\n" > > + : "=&r" (res), "=&r" (oldval) > > + : "r" (ptr), "Ir" (old), "r" (new) > > + : "memory", "cc"); > > + } while (res); > > + break; > > + case 2: > > + do { > > + asm volatile("@ __cmpxchg2\n" > > + " ldrexh %1, [%2]\n" > > + " mov %0, #0\n" > > + " teq %1, %3\n" > > + " strexheq %0, %4, [%2]\n" > > + : "=&r" (res), "=&r" (oldval) > > + : "r" (ptr), "Ir" (old), "r" (new) > > + : "memory", "cc"); > > + } while (res); > > + break; > > + case 4: > > + do { > > + asm volatile("@ __cmpxchg4\n" > > + " ldrex %1, [%2]\n" > > + " mov %0, #0\n" > > + " teq %1, %3\n" > > + " strexeq %0, %4, [%2]\n" > > + : "=&r" (res), "=&r" (oldval) > > + : "r" (ptr), "Ir" (old), "r" (new) > > + : "memory", "cc"); > > + } while (res); > > + break; > > +#if 0 > > + case 8: > > + do { > > + asm volatile("@ __cmpxchg8\n" > > + " ldrexd %1, [%2]\n" > > + " mov %0, #0\n" > > + " teq %1, %3\n" > > + " strexdeq %0, %4, [%2]\n" > > + : "=&r" (res), "=&r" (oldval) > > + : "r" (ptr), "Ir" (old), "r" (new) > > + : "memory", "cc"); > > + } while (res); > > + break; > > +#endif > > Is it really useful to let the dead code in the header? This was a pure code motion patch so I'm not going to remove it here. In any case this will come in handy the first time someone tries to cmpxchg an 8 byte value. Ian.