From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <rth@twiddle.net>
Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] int128: optimize
Date: Thu, 20 Jun 2013 23:20:48 +0200 [thread overview]
Message-ID: <51C37230.2040306@redhat.com> (raw)
In-Reply-To: <51C331E0.6030402@twiddle.net>
Il 20/06/2013 18:46, Richard Henderson ha scritto:
> On 06/20/2013 08:00 AM, Paolo Bonzini wrote:
>> static inline Int128 int128_sub(Int128 a, Int128 b)
>> {
>> - return int128_add(a, int128_neg(b));
>> + uint64_t lo = a.lo - b.lo;
>> + return (Int128) { lo, (lo < a.lo) + a.hi - b.hi };
>
> This one isn't right. Consider { 2, 0 } - { 2, 0 }
>
> lo = 2 - 2 = 0;
> = { 0, (0 < 2) + 0 - 0 }
> = { 0, 1 }
>
> I'd be happier with a more traditional
>
> (Int128){ a.lo - b.lo, a.hi - b.hi - (a.lo < b.lo) };
Yeah, I wasn't quite sure of this and I was waiting for testcases to
prove me wrong... To fix it in the style I used you need
(Int128){ lo, a.hi - b.hi - (lo > a.lo) }
(We have to sum a + ~b + 1. We have lo = a.lo + ~b.lo + 1, from which
the carry-out is either lo <= a.lo or lo <= ~b.lo, using <= because of
the carry-in. Then the high part is
a.hi + ~b.hi + (lo <= a.lo)
= a.hi + (-1 - b.hi) + 1 - (lo > a.lo)
= a.hi - b.hi - (lo > a.lo)
). But I'll go with your version, it probably generates better code
too.
Paolo
next prev parent reply other threads:[~2013-06-20 21:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-20 15:00 [Qemu-devel] [PATCH] int128: optimize Paolo Bonzini
2013-06-20 16:46 ` Richard Henderson
2013-06-20 21:20 ` Paolo Bonzini [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-07-02 12:46 Jay Foad
2013-07-02 14:54 ` Paolo Bonzini
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=51C37230.2040306@redhat.com \
--to=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.