From: "Måns Rullgård" <mans@mansr.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Juri Lelli <juri.lelli@gmail.com>, Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [RFC][PATCH 2/3] math128: Introduce {mult,add,cmp}_u128
Date: Tue, 24 Apr 2012 21:12:20 +0100 [thread overview]
Message-ID: <yw1xy5pkj3dn.fsf@unicorn.mansr.com> (raw)
In-Reply-To: <CA+55aFyvBTDh_DkXs6Z6zFmjyYxvWaAEm9-rJDXhvPx8CpDiKA@mail.gmail.com> (Linus Torvalds's message of "Tue, 24 Apr 2012 12:37:53 -0700")
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Tue, Apr 24, 2012 at 9:10 AM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
>> Grow rudimentary u128 support without relying on gcc/libgcc.
>>
>> +#ifndef add_u128
>> +static inline u128 add_u128(u128 a, u128 b)
>> +{
>> + u128 res;
>> +
>> + res.hi = a.hi + b.hi;
>> + res.lo = a.lo + b.lo;
>> +
>> + if (res.lo < a.lo || res.lo < b.lo)
>> + res.hi++;
>
> This is wrong. Or at least stupid.
>
> Just do one of the comparisons, not both. If overflow occurs, the
> result will be smaller than *either* of the added numbers, so
> comparing both is just silly and confused.
>
> So just pick one.
>
> Also, it might be worth looking at code generation, to see if it's
> better to just do
>
> a.hi += b.hi;
> a.low += b.low;
> if (a.low < b.low)
> a.hi++;
> return a;
I have no idea if it makes a difference, but that if statement can be
written as a.hi += a.low < b.low. Just an observation.
> because that might make it clear that there are fewer actual values
> live at any particular time. But gcc may not care. Try it.
>
> Also, for the multiply, please make sure gcc knows to do a "32x32->64"
> multiplication, rather than thinking it needs to do full 64x64
> multiplies..
On ARM it does the right thing at least since 4.3, which is the oldest
ARM compiler I have at hand.
--
Måns Rullgård
mans@mansr.com
next prev parent reply other threads:[~2012-04-24 20:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-24 16:10 [RFC][PATCH 0/3] gcc work-around and math128 Peter Zijlstra
2012-04-24 16:10 ` [RFC][PATCH 1/3] kernel,sched,time: Clean up gcc work-arounds Peter Zijlstra
2012-04-24 19:39 ` Linus Torvalds
2012-04-25 0:14 ` Stephen Rothwell
2012-04-24 16:10 ` [RFC][PATCH 2/3] math128: Introduce {mult,add,cmp}_u128 Peter Zijlstra
2012-04-24 19:37 ` Linus Torvalds
2012-04-24 19:43 ` Peter Zijlstra
2012-04-24 20:12 ` Måns Rullgård [this message]
2012-04-24 21:54 ` Peter Zijlstra
2012-04-25 0:09 ` H. Peter Anvin
2012-04-25 1:46 ` Linus Torvalds
2012-04-25 8:35 ` Peter Zijlstra
2012-04-25 10:13 ` Peter Zijlstra
2012-04-25 0:23 ` Stephen Rothwell
2012-04-25 8:11 ` Peter Zijlstra
2012-04-25 11:23 ` Geert Uytterhoeven
2012-04-25 11:58 ` Peter Zijlstra
2012-04-25 14:35 ` Geert Uytterhoeven
2012-04-25 15:09 ` Peter Zijlstra
2012-04-24 16:10 ` [RFC][PATCH 3/3] math128, x86_64: Implement {mult,add}_u128 in 64bit asm Peter Zijlstra
2012-04-24 16:34 ` H. Peter Anvin
2012-04-24 16:36 ` Peter Zijlstra
2012-04-24 17:17 ` H. Peter Anvin
2012-04-24 17:19 ` Peter Zijlstra
2012-04-24 17:20 ` H. Peter Anvin
2012-04-24 22:00 ` Peter Zijlstra
2012-04-24 22:03 ` H. Peter Anvin
2012-04-24 17:22 ` [RFC][PATCH 0/3] gcc work-around and math128 H. Peter Anvin
2012-04-24 17:27 ` H. Peter Anvin
2012-04-24 21:15 ` Andy Lutomirski
2012-04-24 21:18 ` Linus Torvalds
2012-04-24 21:32 ` Peter Zijlstra
2012-04-24 21:35 ` Andy Lutomirski
2012-04-24 21:51 ` Peter Zijlstra
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=yw1xy5pkj3dn.fsf@unicorn.mansr.com \
--to=mans@mansr.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=juri.lelli@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®