1 MIPS: Implement __multi3 for GCC7 MIPS64r6 builds
3 Reported-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
4 Signed-off-by: James Hogan <jhogan@kernel.org>
6 diff -Nur linux-4.9.71.orig/arch/mips/lib/libgcc.h linux-4.9.71/arch/mips/lib/libgcc.h
7 --- linux-4.9.71.orig/arch/mips/lib/libgcc.h 2017-12-20 10:07:34.000000000 +0100
8 +++ linux-4.9.71/arch/mips/lib/libgcc.h 2017-12-25 16:08:31.476051643 +0100
15 + long long high, low;
17 #elif defined(__LITTLE_ENDIAN)
23 + long long low, high;
32 +#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6)
33 +typedef int ti_type __attribute__((mode(TI)));
41 #endif /* __ASM_LIBGCC_H */
42 diff -Nur linux-4.9.71.orig/arch/mips/lib/Makefile linux-4.9.71/arch/mips/lib/Makefile
43 --- linux-4.9.71.orig/arch/mips/lib/Makefile 2017-12-20 10:07:34.000000000 +0100
44 +++ linux-4.9.71/arch/mips/lib/Makefile 2017-12-25 16:08:31.476051643 +0100
46 obj-$(CONFIG_CPU_TX39XX) += r3k_dump_tlb.o
48 # libgcc-style stuff needed in the kernel
49 -obj-y += ashldi3.o ashrdi3.o bswapsi.o bswapdi.o cmpdi2.o lshrdi3.o ucmpdi2.o
50 +obj-y += ashldi3.o ashrdi3.o bswapsi.o bswapdi.o cmpdi2.o lshrdi3.o multi3.o \
52 diff -Nur linux-4.9.71.orig/arch/mips/lib/multi3.c linux-4.9.71/arch/mips/lib/multi3.c
53 --- linux-4.9.71.orig/arch/mips/lib/multi3.c 1970-01-01 01:00:00.000000000 +0100
54 +++ linux-4.9.71/arch/mips/lib/multi3.c 2017-12-25 16:08:31.476051643 +0100
56 +// SPDX-License-Identifier: GPL-2.0
57 +#include <linux/export.h>
62 + * GCC 7 suboptimally generates __multi3 calls for mips64r6, so for that
63 + * specific case only we'll implement it here.
65 + * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981
67 +#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ == 7)
69 +/* multiply 64-bit values, low 64-bits returned */
70 +static inline long long notrace dmulu(long long a, long long b)
73 + asm ("dmulu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b));
77 +/* multiply 64-bit unsigned values, high 64-bits of 128-bit result returned */
78 +static inline long long notrace dmuhu(long long a, long long b)
81 + asm ("dmuhu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b));
85 +/* multiply 128-bit values, low 128-bits returned */
86 +ti_type notrace __multi3(ti_type a, ti_type b)
88 + TWunion res, aa, bb;
94 + * a * b = (a.lo * b.lo)
95 + * + 2^64 * (a.hi * b.lo + a.lo * b.hi)
96 + * [+ 2^128 * (a.hi * b.hi)]
98 + res.s.low = dmulu(aa.s.low, bb.s.low);
99 + res.s.high = dmuhu(aa.s.low, bb.s.low);
100 + res.s.high += dmulu(aa.s.high, bb.s.low);
101 + res.s.high += dmulu(aa.s.low, bb.s.high);
105 +EXPORT_SYMBOL(__multi3);
107 +#endif /* 64BIT && CPU_MIPSR6 && GCC7 */