m68k: use kernel's generic muldi3 libgcc function
PATCH v2 1/1 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.
--- arch/Kconfig | 8 +++ arch/m68k/Kconfig | 2 + arch/m68k/include/asm/libgcc.h | 20 +++++++ arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-) create mode 100644 arch/m68k/include/asm/libgcc.h delete mode 100644 arch/m68k/lib/muldi3.c
v2: change to using arch libgcc.h instead of compiler.h
arch/Kconfig +8 -0
@@ -1331,6 +1331,14 @@ config HAVE_ARCH_COMPILER_H linux/compiler-*.h in order to override macro definitions that those headers generally provide. +config HAVE_ARCH_LIBGCC_H + bool + help + An architecture can select this if it provides an + asm/libgcc.h header that should be included after + linux/libgcc.h in order to override macro definitions that + header generally provides. + config HAVE_ARCH_PREL32_RELOCATIONS bool help
arch/m68k/Kconfig +2 -0
@@ -22,7 +22,9 @@ config M68K select GENERIC_LIB_ASHLDI3 select GENERIC_LIB_ASHRDI3 select GENERIC_LIB_LSHRDI3 + select GENERIC_LIB_MULDI3 select HAS_IOPORT if PCI || ISA || ATARI_ROM_ISA + select HAVE_ARCH_LIBGCC_H select HAVE_ARCH_SECCOMP select HAVE_ARCH_SECCOMP_FILTER select HAVE_ASM_MODVERSIONS
arch/m68k/include/asm/libgcc.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_M68K_LIBGCC_H +#define __ASM_M68K_LIBGCC_H + +#ifndef CONFIG_CPU_HAS_NO_MULDIV64 +/* +* For those 68K CPUs that support 64bit multiply define umul_ppm() +* for the common muldi3 libgcc helper function (in lib/muldi3.c). +* CPUs that don't have it (like the original 68000 and ColdFire) +* will fallback to using the C-coded version of umul_ppmm(). +*/ +#define umul_ppmm (w1, w0, u, v) \ + __asm__ ("mulu%.l %3,%1:%0" \ + : "=d" ((unsigned long)(w0)), \ + "=d" ((unsigned long)(w1)) \ + : "%0" ((unsigned long)(u)), \ + "dmi" ((unsigned long)(v))) +#endif /* !CONFIG_CPU_HAS_NO_MULDIV64 */ + +#endif /* __ASM_M68K_LIBGCC_H */
arch/m68k/lib/Makefile +1 -1
@@ -4,7 +4,7 @@ # Makefile for m68k-specific library files.. # -lib-y := muldi3.o memcpy.o memset.o memmove.o +lib-y := memcpy.o memset.o memmove.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_CPU_HAS_NO_MULDIV64) += mulsi3.o divsi3.o udivsi3.o
arch/m68k/lib/muldi3.c deleted +0 -97
97 lines not on this page · raw message
include/linux/libgcc.h +4 -0
@@ -34,4 +34,8 @@ long long notrace __lshrdi3(long long u, word_type b);long long notrace __muldi3 (long long u,long long v); word_type notrace __ucmpdi2(unsigned long long a, unsigned long long b); +#ifdef CONFIG_HAVE_ARCH_LIBGCC_H +#include <asm/libgcc.h> +#endif +#endif /* __ASM_LIBGCC_H */
Signature · 1 line
2.25.1
Hi Greg, Arnd,
Quoted 11 lines · Greg Ungerer
Use the kernels own generic
lib/muldi3.cimplementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specificumul_ppmm()macro into a header file that is included bylib/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.ccode to pick up an external arch definition ofumul_ppmm(). Create an arch specificlibgcc.hthat can optionally be included by the systeminclude/linux/libgcc.hto allow for this.
Quoted 8 lines
Somewhat oddly there is also a similar definition of
umul_ppmm()in the non-architecture code inlib/crypto/mpi/longlong.hfor a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something likecompiler.hinstead. Actually there is a few other defines ofumul_ppmm()macros spread around in various architectures, but not directly usable for the m68k case.Signed-off-by Greg Ungerer <[email protected]>
Quoted 9 lines
arch/Kconfig | 8 +++ arch/m68k/Kconfig | 2 + arch/m68k/include/asm/libgcc.h | 20 +++++++ arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-) create mode 100644 arch/m68k/include/asm/libgcc.h delete mode 100644 arch/m68k/lib/muldi3.c
I had this in my local tree for about a year.
Is it fine to queue this in the m68k tree, or does this need a broader coverage?
Thanks!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Geert,
Quoted 35 lines · Geert Uytterhoeven
Hi Greg, Arnd,
Quoted 11 lines · Greg Ungerer
Use the kernels own generic
lib/muldi3.cimplementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specificumul_ppmm()macro into a header file that is included bylib/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.ccode to pick up an external arch definition ofumul_ppmm(). Create an arch specificlibgcc.hthat can optionally be included by the systeminclude/linux/libgcc.hto allow for this.Quoted 8 lines
Somewhat oddly there is also a similar definition of
umul_ppmm()in the non-architecture code inlib/crypto/mpi/longlong.hfor a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something likecompiler.hinstead. Actually there is a few other defines ofumul_ppmm()macros spread around in various architectures, but not directly usable for the m68k case.Signed-off-by Greg Ungerer <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>Quoted 9 lines
arch/Kconfig | 8 +++ arch/m68k/Kconfig | 2 + arch/m68k/include/asm/libgcc.h | 20 +++++++ arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-)create mode 100644
arch/m68k/include/asm/libgcc.hdelete mode 100644arch/m68k/lib/muldi3.c
Quoted 3 lines
I had this in my local tree for about a year.
Is it fine to queue this in the m68k tree, or does this need a broader coverage?
I am still in favor of it :-)
Would be good to get some feedback on the common code changes, like the change to libgcc.h.
Regards
Greg
Arnd, ping...
Quoted 42 lines · Greg Ungerer
Hi Geert,
Quoted 35 lines · Geert Uytterhoeven
Hi Greg, Arnd,
Quoted 11 lines · Greg Ungerer
Use the kernels own generic
lib/muldi3.cimplementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specificumul_ppmm()macro into a header file that is included bylib/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.ccode to pick up an external arch definition ofumul_ppmm(). Create an arch specificlibgcc.hthat can optionally be included by the systeminclude/linux/libgcc.hto allow for this.Quoted 8 lines
Somewhat oddly there is also a similar definition of
umul_ppmm()in the non-architecture code inlib/crypto/mpi/longlong.hfor a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something likecompiler.hinstead. Actually there is a few other defines ofumul_ppmm()macros spread around in various architectures, but not directly usable for the m68k case.Signed-off-by Greg Ungerer <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>Quoted 9 lines
arch/Kconfig | 8 +++
arch/m68k/Kconfig | 2 +
arch/m68k/include/asm/libgcc.h| 20 +++++++arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-)create mode 100644
arch/m68k/include/asm/libgcc.hdelete mode 100644arch/m68k/lib/muldi3.cQuoted 3 lines
I had this in my local tree for about a year.
Is it fine to queue this in the m68k tree, or does this need a broader coverage?
Quoted 8 lines
I am still in favor of it :-)
Would be good to get some feedback on the common code changes, like the change tolibgcc.h.Regards
Greg
From 1fe3aa42e42fc73b9ce8754516699b1be7aec7bb Mon Sep 17 00:00:00 2001
From: Greg Ungerer <[email protected]>
Date: Mon, 13 Nov 2023 13:59:50 +1000
Subject: [PATCH] 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.
--- arch/Kconfig | 8 +++ arch/m68k/Kconfig | 2 + arch/m68k/include/asm/libgcc.h | 20 +++++++ arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-) create mode 100644 arch/m68k/include/asm/libgcc.h delete mode 100644 arch/m68k/lib/muldi3.c
arch/Kconfig +8 -0
@@ -1526,6 +1526,14 @@ config HAVE_ARCH_COMPILER_H linux/compiler-*.h in order to override macro definitions that those headers generally provide. +config HAVE_ARCH_LIBGCC_H + bool + help + An architecture can select this if it provides an + asm/libgcc.h header that should be included after + linux/libgcc.h in order to override macro definitions that + header generally provides. + config HAVE_ARCH_PREL32_RELOCATIONS bool help
arch/m68k/Kconfig +2 -0
@@ -23,7 +23,9 @@ config M68K select GENERIC_LIB_ASHLDI3 select GENERIC_LIB_ASHRDI3 select GENERIC_LIB_LSHRDI3 + select GENERIC_LIB_MULDI3 select HAS_IOPORT if PCI || ISA || ATARI_ROM_ISA + select HAVE_ARCH_LIBGCC_H select HAVE_ARCH_SECCOMP select HAVE_ARCH_SECCOMP_FILTER select HAVE_ASM_MODVERSIONS
arch/m68k/include/asm/libgcc.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_M68K_LIBGCC_H +#define __ASM_M68K_LIBGCC_H + +#ifndef CONFIG_CPU_HAS_NO_MULDIV64 +/* +* For those 68K CPUs that support 64bit multiply define umul_ppm() +* for the common muldi3 libgcc helper function (in lib/muldi3.c). +* CPUs that don't have it (like the original 68000 and ColdFire) +* will fallback to using the C-coded version of umul_ppmm(). +*/ +#define umul_ppmm (w1, w0, u, v) \ + __asm__ ("mulu%.l %3,%1:%0" \ + : "=d" ((unsigned long)(w0)), \ + "=d" ((unsigned long)(w1)) \ + : "%0" ((unsigned long)(u)), \ + "dmi" ((unsigned long)(v))) +#endif /* !CONFIG_CPU_HAS_NO_MULDIV64 */ + +#endif /* __ASM_M68K_LIBGCC_H */
arch/m68k/lib/Makefile +1 -1
@@ -4,7 +4,7 @@ # Makefile for m68k-specific library files.. # -lib-y := muldi3.o memcpy.o memset.o memmove.o +lib-y := memcpy.o memset.o memmove.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_CPU_HAS_NO_MULDIV64) += mulsi3.o divsi3.o udivsi3.o
arch/m68k/lib/muldi3.c deleted +0 -97
97 lines not on this page · raw message
include/linux/libgcc.h +4 -0
@@ -34,4 +34,8 @@ long long notrace __lshrdi3(long long u, word_type b);long long notrace __muldi3 (long long u,long long v); word_type notrace __ucmpdi2(unsigned long long a, unsigned long long b); +#ifdef CONFIG_HAVE_ARCH_LIBGCC_H +#include <asm/libgcc.h> +#endif +#endif /* __ASM_LIBGCC_H */
Signature · 1 line
2.25.1
Arnd Bergmann
Reviewed-byQuoted 1 line · Greg Ungerer
Arnd, ping...
Sorry I hadn't realized you were waiting for me.
Quoted 35 lines · Greg Ungerer
Quoted 34 lines · Geert Uytterhoeven
Quoted 33 lines · Greg Ungerer
Quoted 11 lines
Use the kernels own generic
lib/muldi3.cimplementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specificumul_ppmm()macro into a header file that is included bylib/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.ccode to pick up an external arch definition ofumul_ppmm(). Create an arch specificlibgcc.hthat can optionally be included by the systeminclude/linux/libgcc.hto allow for this.Quoted 8 lines
Somewhat oddly there is also a similar definition of
umul_ppmm()in the non-architecture code inlib/crypto/mpi/longlong.hfor a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something likecompiler.hinstead. Actually there is a few other defines ofumul_ppmm()macros spread around in various architectures, but not directly usable for the m68k case.Signed-off-by Greg Ungerer <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>Quoted 9 lines
arch/Kconfig | 8 +++
arch/m68k/Kconfig | 2 +
arch/m68k/include/asm/libgcc.h| 20 +++++++arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-)create mode 100644
arch/m68k/include/asm/libgcc.hdelete mode 100644arch/m68k/lib/muldi3.c
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I had this in my local tree for about a year.
Is it fine to queue this in the m68k tree, or does this need a broader coverage?I am still in favor of it :-)
Would be good to get some feedback on the common code changes, like the change tolibgcc.h.
This looks fine to me, nice cleanup. My instinct at first was to add an asm-generic/libgcc.h as a fallback in place of the Kconfig symbol and move the common macro there, but there really isn't much benefit to that over your version. Either way, please merge this through the m68k tree.
Arnd
Geert Uytterhoeven
maintainerQuoted 44 lines · Arnd Bergmann
Quoted 35 lines · Greg Ungerer
Quoted 34 lines · Greg Ungerer
Quoted 33 lines · Geert Uytterhoeven
Quoted 11 lines · Greg Ungerer
Use the kernels own generic
lib/muldi3.cimplementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specificumul_ppmm()macro into a header file that is included bylib/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.ccode to pick up an external arch definition ofumul_ppmm(). Create an arch specificlibgcc.hthat can optionally be included by the systeminclude/linux/libgcc.hto allow for this.Quoted 8 lines
Somewhat oddly there is also a similar definition of
umul_ppmm()in the non-architecture code inlib/crypto/mpi/longlong.hfor a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something likecompiler.hinstead. Actually there is a few other defines ofumul_ppmm()macros spread around in various architectures, but not directly usable for the m68k case.Signed-off-by Greg Ungerer <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>Quoted 9 lines
arch/Kconfig | 8 +++ arch/m68k/Kconfig | 2 + arch/m68k/include/asm/libgcc.h | 20 +++++++ arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-)create mode 100644
arch/m68k/include/asm/libgcc.hdelete mode 100644arch/m68k/lib/muldi3.cQuoted 7 lines
Quoted 7 lines
Quoted 3 lines
I had this in my local tree for about a year.
Is it fine to queue this in the m68k tree, or does this need a broader coverage?I am still in favor of it :-)
Would be good to get some feedback on the common code changes, like the change tolibgcc.h.
Quoted 7 lines
Reviewed-by Arnd Bergmann <[email protected]>This looks fine to me, nice cleanup. My instinct at first was to add an
asm-generic/libgcc.has a fallback in place of theKconfigsymbol and move the common macro there, but there really isn't much benefit to that over your version. Either way, please merge this through the m68k tree.
Thanks, queued in the m68k tree for v6.14.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds