-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MIPS: Implement __multi3 for GCC7 MIPS64r6 builds
commit ebabcf1 upstream. 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 > 0xffffffffffffffff; 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. Reported-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: James Hogan <jhogan@kernel.org> Tested-by: Waldemar Brodkorb <wbx@openadk.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Maciej W. Rozycki <macro@mips.com> Cc: Matthew Fortune <matthew.fortune@mips.com> Cc: Florian Fainelli <florian@openwrt.org> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/17890/ Cc: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
- Loading branch information
James Hogan
authored and
Greg Kroah-Hartman
committed
Mar 3, 2018
1 parent
37d866a
commit cacdb01
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/export.h> | ||
|
||
#include "libgcc.h" | ||
|
||
/* | ||
* GCC 7 suboptimally generates __multi3 calls for mips64r6, so for that | ||
* specific case only we'll implement it here. | ||
* | ||
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981 | ||
*/ | ||
#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ == 7) | ||
|
||
/* multiply 64-bit values, low 64-bits returned */ | ||
static inline long long notrace dmulu(long long a, long long b) | ||
{ | ||
long long res; | ||
|
||
asm ("dmulu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b)); | ||
return res; | ||
} | ||
|
||
/* multiply 64-bit unsigned values, high 64-bits of 128-bit result returned */ | ||
static inline long long notrace dmuhu(long long a, long long b) | ||
{ | ||
long long res; | ||
|
||
asm ("dmuhu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b)); | ||
return res; | ||
} | ||
|
||
/* multiply 128-bit values, low 128-bits returned */ | ||
ti_type notrace __multi3(ti_type a, ti_type b) | ||
{ | ||
TWunion res, aa, bb; | ||
|
||
aa.ti = a; | ||
bb.ti = b; | ||
|
||
/* | ||
* a * b = (a.lo * b.lo) | ||
* + 2^64 * (a.hi * b.lo + a.lo * b.hi) | ||
* [+ 2^128 * (a.hi * b.hi)] | ||
*/ | ||
res.s.low = dmulu(aa.s.low, bb.s.low); | ||
res.s.high = dmuhu(aa.s.low, bb.s.low); | ||
res.s.high += dmulu(aa.s.high, bb.s.low); | ||
res.s.high += dmulu(aa.s.low, bb.s.high); | ||
|
||
return res.ti; | ||
} | ||
EXPORT_SYMBOL(__multi3); | ||
|
||
#endif /* 64BIT && CPU_MIPSR6 && GCC7 */ |