qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Avi Kivity <avi@redhat.com>
Cc: aik@ozlabs.ru, agraf@suse.de, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Memory API bugfix - abolish addrrrange_end()
Date: Sun, 16 Oct 2011 22:40:11 +1100	[thread overview]
Message-ID: <20111016114011.GG4580@truffala.fritz.box> (raw)
In-Reply-To: <4E9AAA33.3010806@redhat.com>

On Sun, Oct 16, 2011 at 11:56:03AM +0200, Avi Kivity wrote:
> On 10/12/2011 04:37 AM, David Gibson wrote:
[snip]
> >  static AddrRange addrrange_intersection(AddrRange r1, AddrRange r2)
> >  {
> > -    int64_t start = MAX(r1.start, r2.start);
> > -    /* off-by-one arithmetic to prevent overflow */
> > -    int64_t end = MIN(addrrange_end(r1) - 1, addrrange_end(r2) - 1);
> > -    return addrrange_make(start, end - start + 1);
> > +    if (r1.start <= r2.start) {
> > +        return addrrange_make(r2.start,
> > +                              MIN(r2.size, r1.size - (r2.start - r1.start)));
> > +    } else {
> > +        return addrrange_make(r1.start,
> > +                              MIN(r1.size, r2.size - (r1.start - r2.start)));
> > +    }
> >  }
> >  
> 
> This is pretty ugly.

A little, but it's correct...

> >  struct CoalescedMemoryRange {
> > @@ -201,7 +202,8 @@ static void flatview_destroy(FlatView *view)
> >  
> >  static bool can_merge(FlatRange *r1, FlatRange *r2)
> >  {
> > -    return addrrange_end(r1->addr) == r2->addr.start
> > +    assert (r1->addr.start < r2->addr.start);
> 
> So is this, to a lesser extent.

Well, the assert is optional; I basically just put that in to document
the assumptions going into this function.

> Let me see if I can work up a synthetic int128 type.

So.. you think replacing every single basic arithmetic operations with
calls to implement the synthetic type, _and_ imposing the resulting
overhead is _less_ ugly than some slightly fiddly re-ordering of
operations?  Seriously?


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

  reply	other threads:[~2011-10-16 11:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12  2:37 [Qemu-devel] [PATCH] Memory API bugfix - abolish addrrrange_end() David Gibson
2011-10-16  9:56 ` Avi Kivity
2011-10-16 11:40   ` David Gibson [this message]
2011-10-16 12:35     ` Avi Kivity
2011-10-17  5:31       ` David Gibson
2011-10-17 10:34         ` Avi Kivity
2011-10-18  1:38           ` David Gibson
2011-10-18  9:49             ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111016114011.GG4580@truffala.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).