linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm: lib: implement aeabi_uldivmod via div64_u64_rem
@ 2022-07-16  0:16 Nick Desaulniers
  2022-07-16  9:46 ` Arnd Bergmann
  2022-07-18 16:50 ` [PATCH] arm: lib: implement aeabi_uldivmod via div64_u64_rem kernel test robot
  0 siblings, 2 replies; 9+ messages in thread
From: Nick Desaulniers @ 2022-07-16  0:16 UTC (permalink / raw)
  Cc: llvm, Arnd Bergmann, Nathan Chancellor, Miguel Ojeda,
	Ard Biesheuval, Nick Desaulniers, Gary Guo, Russell King,
	linux-arm-kernel, linux-kernel

Compilers frequently need to defer 64b division to a libcall with this
symbol name. It essentially is div64_u64_rem, just with a different
signature. Kernel developers know to call div64_u64_rem, but compilers
don't.

Link: https://lore.kernel.org/lkml/20220524004156.0000790e@garyguo.net/
Suggested-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/arm/lib/Makefile         |  1 +
 arch/arm/lib/aeabi_uldivmod.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 arch/arm/lib/aeabi_uldivmod.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 6d2ba454f25b..3fa273219312 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -29,6 +29,7 @@ endif
 obj-$(CONFIG_UACCESS_WITH_MEMCPY) += uaccess_with_memcpy.o
 
 lib-$(CONFIG_MMU) += $(mmu-y)
+lib-$(CONFIG_AEABI) += aeabi_uldivmod.o
 
 ifeq ($(CONFIG_CPU_32v3),y)
   lib-y	+= io-readsw-armv3.o io-writesw-armv3.o
diff --git a/arch/arm/lib/aeabi_uldivmod.c b/arch/arm/lib/aeabi_uldivmod.c
new file mode 100644
index 000000000000..310427893195
--- /dev/null
+++ b/arch/arm/lib/aeabi_uldivmod.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Unsigned 64b division with remainder, as is typically provided by libgcc or
+ * compiler-rt.
+ *
+ * Copyright (C) 2023 Google, LLC.
+ *
+ * Author: Nick Desaulniers <ndesaulniers@google.com>
+ */
+
+#include <linux/math64.h>
+
+struct result {
+	u64 quot, rem;
+};
+
+struct result __aeabi_uldivmod(u64 numerator, u64 denominator)
+{
+	struct result res;
+
+	res.quot = div64_u64_rem(numerator, denominator, &res.rem);
+	return res;
+}
-- 
2.37.0.170.g444d1eabd0-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-13 17:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16  0:16 [PATCH] arm: lib: implement aeabi_uldivmod via div64_u64_rem Nick Desaulniers
2022-07-16  9:46 ` Arnd Bergmann
2022-10-10 21:23   ` Nick Desaulniers
2022-10-10 22:13     ` Arnd Bergmann
2022-10-10 22:34       ` Nick Desaulniers
2022-10-10 22:53         ` [PATCH] ARM: NWFPE: avoid compiler-generated __aeabi_uldivmod Nick Desaulniers
2022-10-11 11:01           ` Arnd Bergmann
2022-10-13 17:04           ` Nathan Chancellor
2022-07-18 16:50 ` [PATCH] arm: lib: implement aeabi_uldivmod via div64_u64_rem kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).