Skip to content

Commit e419dde

Browse files
Greg Ungerergeertu
Greg Ungerer
authored andcommitted
m68k: Use kernel's generic muldi3 libgcc function
Use the kernels own generic lib/muldi3.c implementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specific umul_ppmm() macro into a header file that is included by lib/muldi3.c. That way it can take advantage of the single instruction when available. There does not appear to be any existing mechanism for the generic lib/muldi3.c code to pick up an external arch definition of umul_ppmm(). Create an arch specific libgcc.h that can optionally be included by the system include/linux/libgcc.h to allow for this. Somewhat oddly there is also a similar definition of umul_ppmm() in the non-architecture code in lib/crypto/mpi/longlong.h for a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something like compiler.h instead. Actually there is a few other defines of umul_ppmm() macros spread around in various architectures, but not directly usable for the m68k case. Signed-off-by: Greg Ungerer <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 40384c8 commit e419dde

File tree

6 files changed

+35
-98
lines changed

6 files changed

+35
-98
lines changed

arch/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,14 @@ config HAVE_ARCH_COMPILER_H
15261526
linux/compiler-*.h in order to override macro definitions that those
15271527
headers generally provide.
15281528

1529+
config HAVE_ARCH_LIBGCC_H
1530+
bool
1531+
help
1532+
An architecture can select this if it provides an
1533+
asm/libgcc.h header that should be included after
1534+
linux/libgcc.h in order to override macro definitions that
1535+
header generally provides.
1536+
15291537
config HAVE_ARCH_PREL32_RELOCATIONS
15301538
bool
15311539
help

arch/m68k/Kconfig

+2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ config M68K
2323
select GENERIC_LIB_ASHLDI3
2424
select GENERIC_LIB_ASHRDI3
2525
select GENERIC_LIB_LSHRDI3
26+
select GENERIC_LIB_MULDI3
2627
select HAS_IOPORT if PCI || ISA || ATARI_ROM_ISA
28+
select HAVE_ARCH_LIBGCC_H
2729
select HAVE_ARCH_SECCOMP
2830
select HAVE_ARCH_SECCOMP_FILTER
2931
select HAVE_ASM_MODVERSIONS

arch/m68k/include/asm/libgcc.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __ASM_M68K_LIBGCC_H
3+
#define __ASM_M68K_LIBGCC_H
4+
5+
#ifndef CONFIG_CPU_HAS_NO_MULDIV64
6+
/*
7+
* For those 68K CPUs that support 64bit multiply define umul_ppm()
8+
* for the common muldi3 libgcc helper function (in lib/muldi3.c).
9+
* CPUs that don't have it (like the original 68000 and ColdFire)
10+
* will fallback to using the C-coded version of umul_ppmm().
11+
*/
12+
#define umul_ppmm(w1, w0, u, v) \
13+
__asm__ ("mulu%.l %3,%1:%0" \
14+
: "=d" ((unsigned long)(w0)), \
15+
"=d" ((unsigned long)(w1)) \
16+
: "%0" ((unsigned long)(u)), \
17+
"dmi" ((unsigned long)(v)))
18+
#endif /* !CONFIG_CPU_HAS_NO_MULDIV64 */
19+
20+
#endif /* __ASM_M68K_LIBGCC_H */

arch/m68k/lib/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for m68k-specific library files..
55
#
66

7-
lib-y := muldi3.o memcpy.o memset.o memmove.o
7+
lib-y := memcpy.o memset.o memmove.o
88

99
lib-$(CONFIG_MMU) += uaccess.o
1010
lib-$(CONFIG_CPU_HAS_NO_MULDIV64) += mulsi3.o divsi3.o udivsi3.o

arch/m68k/lib/muldi3.c

-97
This file was deleted.

include/linux/libgcc.h

+4
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ long long notrace __lshrdi3(long long u, word_type b);
3434
long long notrace __muldi3(long long u, long long v);
3535
word_type notrace __ucmpdi2(unsigned long long a, unsigned long long b);
3636

37+
#ifdef CONFIG_HAVE_ARCH_LIBGCC_H
38+
#include <asm/libgcc.h>
39+
#endif
40+
3741
#endif /* __ASM_LIBGCC_H */

0 commit comments

Comments
 (0)