From: James Hogan <james.hogan@mips.com>
To: "Maciej W. Rozycki" <macro@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Matthew Fortune <matthew.fortune@mips.com>,
Florian Fainelli <florian@openwrt.org>,
"Waldemar Brodkorb" <wbx@openadk.org>,
<linux-mips@linux-mips.org>
Subject: Re: [PATCH] MIPS: Implement __multi3 for GCC7 MIPS64r6 builds
Date: Sat, 9 Dec 2017 07:15:58 +0000 [thread overview]
Message-ID: <20171209071558.GQ5027@jhogan-linux.mipstec.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1712082339130.4584@tp.orcam.me.uk>
[-- Attachment #1: Type: text/plain, Size: 1547 bytes --]
On Fri, Dec 08, 2017 at 11:52:05PM +0000, Maciej W. Rozycki wrote:
> On Wed, 6 Dec 2017, James Hogan wrote:
>
> > GCC7 is a bit too eager to generate suboptimal __multi3 calls (128bit
> > multiply with 128bit result) for MIPS64r6 builds, even in code which
> > doesn't explicitly use 128bit types, such as the following:
> >
> > unsigned long func(unsigned long a, unsigned long b)
> > {
> > return a > (~0UL) / b;
> > }
> >
> > Which GCC rearanges to:
> >
> > return (unsigned __int128)a * (unsigned __int128)b > 0xffffffff;
>
> You mean:
>
> return (unsigned __int128)a * (unsigned __int128)b > 0xffffffffffffffff;
>
> presumably, or is there another bug here?
Yes, thats what was meant. It was copy + pasted from Ralf's analysis.
Thanks
James
>
> > Therefore implement __multi3, but only for MIPS64r6 with GCC7 as under
> > normal circumstances we wouldn't expect any calls to __multi3 to be
> > generated from kernel code.
>
> That does look bad; I'd expect a `umulditi3' (widening 64-bit by 64-bit
> unsigned multiplication) kind of operation instead, which should expand
> internally. And we only really need to execute DMUHU and then check the
> result for non-zero here, because the value of the low 64 bits of the
> product does not matter for the evaluation of the expression.
>
> I don't know offhand if such a transformation can be handled by GCC as it
> stands by tweaking the MIPS backend without a corresponding update to the
> middle end though.
>
> Maciej
>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: James Hogan <james.hogan@mips.com>
To: "Maciej W. Rozycki" <macro@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Matthew Fortune <matthew.fortune@mips.com>,
Florian Fainelli <florian@openwrt.org>,
Waldemar Brodkorb <wbx@openadk.org>,
linux-mips@linux-mips.org
Subject: Re: [PATCH] MIPS: Implement __multi3 for GCC7 MIPS64r6 builds
Date: Sat, 9 Dec 2017 07:15:58 +0000 [thread overview]
Message-ID: <20171209071558.GQ5027@jhogan-linux.mipstec.com> (raw)
Message-ID: <20171209071558.Iq4ODCZNrcj8-ci1Ra7bYDySPXlT6OcR-jQRl1wUI4M@z> (raw)
In-Reply-To: <alpine.DEB.2.00.1712082339130.4584@tp.orcam.me.uk>
[-- Attachment #1: Type: text/plain, Size: 1547 bytes --]
On Fri, Dec 08, 2017 at 11:52:05PM +0000, Maciej W. Rozycki wrote:
> On Wed, 6 Dec 2017, James Hogan wrote:
>
> > GCC7 is a bit too eager to generate suboptimal __multi3 calls (128bit
> > multiply with 128bit result) for MIPS64r6 builds, even in code which
> > doesn't explicitly use 128bit types, such as the following:
> >
> > unsigned long func(unsigned long a, unsigned long b)
> > {
> > return a > (~0UL) / b;
> > }
> >
> > Which GCC rearanges to:
> >
> > return (unsigned __int128)a * (unsigned __int128)b > 0xffffffff;
>
> You mean:
>
> return (unsigned __int128)a * (unsigned __int128)b > 0xffffffffffffffff;
>
> presumably, or is there another bug here?
Yes, thats what was meant. It was copy + pasted from Ralf's analysis.
Thanks
James
>
> > Therefore implement __multi3, but only for MIPS64r6 with GCC7 as under
> > normal circumstances we wouldn't expect any calls to __multi3 to be
> > generated from kernel code.
>
> That does look bad; I'd expect a `umulditi3' (widening 64-bit by 64-bit
> unsigned multiplication) kind of operation instead, which should expand
> internally. And we only really need to execute DMUHU and then check the
> result for non-zero here, because the value of the low 64 bits of the
> product does not matter for the evaluation of the expression.
>
> I don't know offhand if such a transformation can be handled by GCC as it
> stands by tweaking the MIPS backend without a corresponding update to the
> middle end though.
>
> Maciej
>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-12-09 7:21 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 20:55 undefined reference to `__multi3' when building with gcc 7.x Thomas Petazzoni
2017-08-04 0:05 ` Ralf Baechle
2017-08-04 15:19 ` Ralf Baechle
2017-08-04 15:41 ` Thomas Petazzoni
2017-08-04 22:25 ` Ralf Baechle
2017-08-05 11:56 ` Thomas Petazzoni
2017-08-07 8:34 ` Ralf Baechle
2017-08-13 20:46 ` Thomas Petazzoni
2017-08-17 7:15 ` Ralf Baechle
2017-08-17 8:49 ` Matthew Fortune
2017-08-17 22:19 ` Ralf Baechle
2017-10-07 19:22 ` Thomas Petazzoni
2017-11-07 17:39 ` Thomas Petazzoni
2017-08-17 1:01 ` Maciej W. Rozycki
2017-08-17 1:01 ` Maciej W. Rozycki
2017-12-03 9:56 ` Thomas Petazzoni
2017-12-05 23:49 ` James Hogan
2017-12-05 23:49 ` James Hogan
2017-12-06 7:50 ` Thomas Petazzoni
2017-12-06 7:50 ` Thomas Petazzoni
2017-12-07 7:20 ` [PATCH] MIPS: Implement __multi3 for GCC7 MIPS64r6 builds James Hogan
2017-12-08 23:52 ` Maciej W. Rozycki
2017-12-08 23:52 ` Maciej W. Rozycki
2017-12-09 7:15 ` James Hogan [this message]
2017-12-09 7:15 ` James Hogan
2017-12-27 8:31 ` Waldemar Brodkorb
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=20171209071558.GQ5027@jhogan-linux.mipstec.com \
--to=james.hogan@mips.com \
--cc=florian@openwrt.org \
--cc=linux-mips@linux-mips.org \
--cc=macro@mips.com \
--cc=matthew.fortune@mips.com \
--cc=ralf@linux-mips.org \
--cc=thomas.petazzoni@free-electrons.com \
--cc=wbx@openadk.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