Received: from eggs.gnu.org ([2001:4830:134:3::10]:54362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9ZpZ-0002ii-2n for qemu-devel@nongnu.org; Mon, 29 Jun 2015 10:14:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9ZpV-0004MO-T9 for qemu-devel@nongnu.org; Mon, 29 Jun 2015 10:14:41 -0400 Received: from mail-qc0-f176.google.com ([209.85.216.176]:34444) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9ZpV-0004MI-Og for qemu-devel@nongnu.org; Mon, 29 Jun 2015 10:14:37 -0400 Received: by qcji3 with SMTP id i3so43186897qcj.1 for ; Mon, 29 Jun 2015 07:14:37 -0700 (PDT) Date: Mon, 29 Jun 2015 10:14:35 -0400 From: Kevin O'Connor Message-ID: <20150629141435.GD30040@morn.localdomain> References: <1435568020-8669-1-git-send-email-kraxel@redhat.com> <1435568020-8669-8-git-send-email-kraxel@redhat.com> <20150629130229.GB30040@morn.localdomain> <1435585614.30958.25.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1435585614.30958.25.camel@redhat.com> Subject: Re: [Qemu-devel] [SeaBIOS] [PATCH 07/18] virtio: add version 1.0 read/write macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: seabios@seabios.org, qemu-devel@nongnu.org, "Michael S. Tsirkin" On Mon, Jun 29, 2015 at 03:46:54PM +0200, Gerd Hoffmann wrote: > On Mo, 2015-06-29 at 09:02 -0400, Kevin O'Connor wrote: > > On Mon, Jun 29, 2015 at 10:53:29AM +0200, Gerd Hoffmann wrote: > > > Add macros to read/write registers of virtio-1.0 regions. > > > > > > Signed-off-by: Gerd Hoffmann > > > --- > > > src/hw/virtio-pci.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > 1 file changed, 76 insertions(+) > > > > > > diff --git a/src/hw/virtio-pci.h b/src/hw/virtio-pci.h > > > index 893a7dd..e1d8b3e 100644 > > > --- a/src/hw/virtio-pci.h > > > +++ b/src/hw/virtio-pci.h > > > @@ -111,6 +111,82 @@ struct vp_device { > > > struct vp_cap common, notify, isr, device; > > > }; > > > > > > +#define vp_modern_read(_cap, _struct, _field, _var) { \ > > > + u32 addr = _cap.addr; \ > > > + addr += offsetof(_struct, _field); \ > > > > Wouldn't this make more sense if the bulk of the code was in a > > function? > > The idea is that 'sizeof((_struct *)0)->_field)' evaluates to a > compile-time constant, so gcc can optimize away the bulk of the #define. Would it matter though? Are any of these accesses performance sensitive? Also, if "_vp_modern_read()" was marked as inline wouldn't gcc ultimately produce the same thing? > Also we don't have to use u64 for _var then (except when it actually is > a 64bit value). > > But having 'vp_modern_read(..., var)' in the code instead of 'var = > vp_modern_read(...)' isn't that nice indeed. Hrmm. That's an interesting question - how well would gcc do if _vp_modern_read() was inline'd and returned a 64bit value that was then immediately truncated in the majority of cases. -Kevin