From: "Jan Beulich" Subject: Re: [PATCHv4 3/8] x86: provide add_sized() Date: Thu, 07 May 2015 17:05:43 +0100 Message-ID: <554BA9770200007800077C5E@mail.emea.novell.com> References: <1430408002-30666-1-git-send-email-david.vrabel@citrix.com> <1430408002-30666-4-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YqOIy-0004bS-VG for xen-devel@lists.xenproject.org; Thu, 07 May 2015 16:05:45 +0000 In-Reply-To: <1430408002-30666-4-git-send-email-david.vrabel@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: Keir Fraser , Ian Campbell , Andrew Cooper , Tim Deegan , Jennifer Herbert , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 30.04.15 at 17:33, wrote: > @@ -55,6 +69,20 @@ void __bad_atomic_size(void); > __x; \ > }) > > +#define add_sized(p, x) ({ \ > + typeof(*(p)) __x = (x); \ > + unsigned long x_ = (unsigned long)__x; \ I don't see the need for this triple type conversion (together with the code below): original -> typeof(*(p)) -> unsigned long -> uintN_t. (For write_atomic() I think this aids writing pointers, but add_sized() surely isn't meant to do that?) > + switch ( sizeof(*(p)) ) \ > + { \ > + case 1: add_u8_sized((uint8_t *)(p), (uint8_t)x_); break; \ > + case 2: add_u16_sized((uint16_t *)(p), (uint16_t)x_); break; \ > + case 4: add_u32_sized((uint32_t *)(p), (uint32_t)x_); break; \ > + case 8: add_u64_sized((uint64_t *)(p), (uint64_t)x_); break; \ > + default: __bad_atomic_size(); break; \ > + } \ > + __x; \ I don't see why write_atomic() needs this, and I even less so understand why add_sized() would need to return its second input. Jan