fix path to new include file
[openadk.git] / target / linux / patches / 4.14.8 / mips64r6-multi3.patch
blobb635f4bb2cddb30246981f2669f8f35b1409b6b4
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.14.8.orig/arch/mips/lib/libgcc.h linux-4.14.8/arch/mips/lib/libgcc.h
7 --- linux-4.14.8.orig/arch/mips/lib/libgcc.h 2017-12-20 10:10:38.000000000 +0100
8 +++ linux-4.14.8/arch/mips/lib/libgcc.h 2017-12-25 16:58:38.258470502 +0100
9 @@ -10,10 +10,18 @@
10 struct DWstruct {
11 int high, low;
14 +struct TWstruct {
15 + long long high, low;
16 +};
17 #elif defined(__LITTLE_ENDIAN)
18 struct DWstruct {
19 int low, high;
22 +struct TWstruct {
23 + long long low, high;
24 +};
25 #else
26 #error I feel sick.
27 #endif
28 @@ -23,4 +31,13 @@
29 long long ll;
30 } DWunion;
32 +#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6)
33 +typedef int ti_type __attribute__((mode(TI)));
35 +typedef union {
36 + struct TWstruct s;
37 + ti_type ti;
38 +} TWunion;
39 +#endif
41 #endif /* __ASM_LIBGCC_H */
42 diff -Nur linux-4.14.8.orig/arch/mips/lib/Makefile linux-4.14.8/arch/mips/lib/Makefile
43 --- linux-4.14.8.orig/arch/mips/lib/Makefile 2017-12-20 10:10:38.000000000 +0100
44 +++ linux-4.14.8/arch/mips/lib/Makefile 2017-12-25 16:58:38.258470502 +0100
45 @@ -16,4 +16,5 @@
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 \
51 + ucmpdi2.o
52 diff -Nur linux-4.14.8.orig/arch/mips/lib/multi3.c linux-4.14.8/arch/mips/lib/multi3.c
53 --- linux-4.14.8.orig/arch/mips/lib/multi3.c 1970-01-01 01:00:00.000000000 +0100
54 +++ linux-4.14.8/arch/mips/lib/multi3.c 2017-12-25 16:58:38.258470502 +0100
55 @@ -0,0 +1,52 @@
56 +// SPDX-License-Identifier: GPL-2.0
57 +#include <linux/export.h>
59 +#include "libgcc.h"
61 +/*
62 + * GCC 7 suboptimally generates __multi3 calls for mips64r6, so for that
63 + * specific case only we'll implement it here.
64 + *
65 + * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981
66 + */
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)
72 + long long res;
73 + asm ("dmulu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b));
74 + return res;
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)
80 + long long res;
81 + asm ("dmuhu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b));
82 + return res;
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;
90 + aa.ti = a;
91 + bb.ti = b;
93 + /*
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)]
97 + */
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);
103 + return res.ti;
105 +EXPORT_SYMBOL(__multi3);
107 +#endif /* 64BIT && CPU_MIPSR6 && GCC7 */