Skip to contentSkip to conversation

About __udivdi3

DISCUSSION Eric Lin 6 participants 10 messages Aug 6, 2019 1 message not in the archive RISC-V

lore
Share & tools
lore

Eric Lin

author
#1 lore raw
In reply to a message not in the archive

Cc: mailing list

Quoted 11 lines · Eric Lin

Hi Palmer/Paul,

Recently I encounter a problem that the output from __udivdi3 is wrong. The compiler will generate __udivdi3 library call when doing 64-bit over 64-bit division on 32-bit platform.

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

Best Regards,
Eric Lin

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 10 lines · Eric Lin

Cc: mailing list

Quoted 8 lines · Eric Lin

Hi Palmer/Paul,

Recently I encounter a problem that the output from __udivdi3 is wrong. The compiler will generate __udivdi3 library call when doing 64-bit over 64-bit division on 32-bit platform.

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

It sounds like you're describing a potential issue with gcc, rather than the kernel. If that's so, then the gcc mailing list(s) would be a better place to discuss this: https://gcc.gnu.org/lists.html

- Paul

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#3 lore raw

Hi Paul,

Quoted 13 lines · Paul Walmsley
Quoted 10 lines · Eric Lin

Cc: mailing list

Quoted 8 lines · Eric Lin

Hi Palmer/Paul,

Recently I encounter a problem that the output from __udivdi3 is wrong. The compiler will generate __udivdi3 library call when doing 64-bit over 64-bit division on 32-bit platform.

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

Quoted 6 lines

It sounds like you're describing a potential issue with gcc, rather than the kernel. If that's so, then the gcc mailing list(s) would be a better place to discuss this: https://gcc.gnu.org/lists.html

- Paul

Sorry, maybe I didn't describe it clearly.
When doing 64-bit over 64-bit division on 32-bit platform, the gcc will link the __udivdi3 function in arch/riscv/lib/udivdi3.S, but the output is wrong because the function is designed for RV64 ABI only.

I've tried to modify the arch/riscv/Makefile to make it link libgcc's __udivdi3 library. The output is correct after using the libgcc's __udivdi3.

So, I don't think the __udivdi3 in arch/riscv/lib can support 64-bit over 64-bit division on 32-bit platform.

Best Regards,
Eric

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw
In reply to Paul Walmsley
Quoted 6 lines · Paul Walmsley
Quoted 2 lines
Quoted 2 lines

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

It sounds like you're describing a potential issue with gcc, rather than the kernel. If that's so, then the gcc mailing list(s) would be a better place to discuss this: https://gcc.gnu.org/lists.html

The kernel doesn't link with libgcc.a. It has its own copy of udivdi3 when needed.

Jim

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw
Quoted 10 lines · Jim Wilson
Quoted 6 lines · Paul Walmsley
Quoted 2 lines
Quoted 2 lines

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

It sounds like you're describing a potential issue with gcc, rather than the kernel. If that's so, then the gcc mailing list(s) would be a better place to discuss this: https://gcc.gnu.org/lists.html

The kernel doesn't link with libgcc.a. It has its own copy of udivdi3 when needed.

Looking at he udivdi3 code in the kernel, it certainly looks to me that it is meant for RV64 compilation i.e. 64-bit-wide registers. It won't produce the right result for sure if compiled for RV32.

That being said, a 32-bit kernel should never require udivdi3. The other 32-bit architectures expressly omitted it on purpose to prevent its use. Most of the time, what is needed is a 64 by 32 division and, unfortunately, gcc doesn't know how to optimize that on 32-bit platforms. This is what the do_div() macro is for.

So the "lib-$(CONFIG_32BIT) += udivdi3.o" in arch/riscv/lib/Makefile is completely wrong. I could see its presence if the div instruction isn't available on some RV64 implementation, but that should be removed otherwise.

Nicolas

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw
In reply to Jim Wilson
Quoted 10 lines · Jim Wilson
Quoted 6 lines · Paul Walmsley
Quoted 2 lines
Quoted 2 lines

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

It sounds like you're describing a potential issue with gcc, rather than the kernel. If that's so, then the gcc mailing list(s) would be a better place to discuss this: https://gcc.gnu.org/lists.html

The kernel doesn't link with libgcc.a. It has its own copy of udivdi3 when needed.

Linus still maintains his stance to not support 64 by 64-bit divisions on 32-bit platforms, and thus Linux does not support it. You can do 64 by 32-bit divisions using the awkward do_div macros, but that's it.

This is supposed to apply to all 32-bit platforms, not just RISC-V.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#7 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Jim Wilson
Quoted 6 lines · Paul Walmsley
Quoted 2 lines
Quoted 2 lines

It seems __udivdi3 only supports 64-bit platform.
Do you have any comments? Thanks.

It sounds like you're describing a potential issue with gcc, rather than the kernel. If that's so, then the gcc mailing list(s) would be a better place to discuss this: https://gcc.gnu.org/lists.html

Quoted 8 lines
Quoted 2 lines

The kernel doesn't link with libgcc.a. It has its own copy of udivdi3 when needed.

Linus still maintains his stance to not support 64 by 64-bit divisions on 32-bit platforms, and thus Linux does not support it. You can do 64 by 32-bit divisions using the awkward do_div macros, but that's it.

This is supposed to apply to all 32-bit platforms, not just RISC-V.

Yep. I think the best bet is to just drop it, with something like this:

commit f7f2185e0e3e60a8b77fb519a98b752242ade235
gpg: Signature made Tue 06 Aug 2019 08:06:30 AM PDT
gpg: using RSA key 00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
gpg: issuer "[email protected]"
gpg: Good signature from "Palmer Dabbelt <[email protected]>" [ultimate]
gpg: aka "Palmer Dabbelt <[email protected]>" [ultimate]
Author: Palmer Dabbelt <[email protected]>
Date: Tue Aug 6 08:03:59 2019 -0700

RISC-V: Remove udivdi3

This should never have landed in the first place: it was added as part of 64-bit divide support for 32-bit systems, but the kernel doesn't allow this sort of division. I must have forgotten to remove it.

This patch removes the support. Since this routine only worked on 64-bit platforms but was only built on 32-bit platforms, it's essentially just nonsense anyway.

   diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
   index 8e364ebf37de..267feaa10f6a 100644
   --- a/arch/riscv/lib/Makefile
   +++ b/arch/riscv/lib/Makefile
   @@ -5,5 +5,3 @@ lib-y	+= memset.o
    lib-y	+= uaccess.o
    lib-$(CONFIG_64BIT) += tishift.o

-
-lib-$(CONFIG_32BIT) += udivdi3.o
diff --git a/arch/riscv/lib/udivdi3.S b/arch/riscv/lib/udivdi3.S deleted file mode 100644
index 3f07476a91a9..000000000000
--- a/arch/riscv/lib/udivdi3.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2016-2017 Free Software Foundation, Inc.
- */
-
-#include <linux/linkage.h>
-
-ENTRY(__udivdi3)
- mv a2, a1
- mv a1, a0
- li a0, -1
- beqz a2, .L5
- li a3, 1
- bgeu a2, a1, .L2
-.L1:
- blez a2, .L2
- slli a2, a2, 1
- slli a3, a3, 1
- bgtu a1, a2, .L1
-.L2:
- li a0, 0
-.L3:
- bltu a1, a2, .L4
- sub a1, a1, a2
- or a0, a0, a3
-.L4:
- srli a3, a3, 1
- srli a2, a2, 1
- bnez a3, .L3
-.L5:
- ret
-ENDPROC(__udivdi3)

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#8 lore raw

(privately)

Quoted 15 lines · Palmer Dabbelt

Yep. I think the best bet is to just drop it, with something like this:

commit f7f2185e0e3e60a8b77fb519a98b752242ade235
gpg: Signature made Tue 06 Aug 2019 08:06:30 AM PDT
gpg: using RSA key 00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
gpg: issuer "[email protected]"
gpg: Good signature from "Palmer Dabbelt <[email protected]>" [ultimate]
gpg: aka "Palmer Dabbelt <[email protected]>" [ultimate]
Author: Palmer Dabbelt <[email protected]>
Date: Tue Aug 6 08:03:59 2019 -0700
RISC-V: Remove udivdi3
This should never have landed in the first place: it was added as
part
of 64-bit divide support for 32-bit systems, but the kernel doesn't allow this sort of division. I must have forgotten to remove it.

Just FYI, you probably already know this, but this patch was mangled on the list. I'll reformat it and queue it up, but figured you probably would want to know if you didn't already.

- Paul

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw
Quoted 20 lines · Paul Walmsley

(privately)

Quoted 15 lines · Palmer Dabbelt

Yep. I think the best bet is to just drop it, with something like this:

commit f7f2185e0e3e60a8b77fb519a98b752242ade235
gpg: Signature made Tue 06 Aug 2019 08:06:30 AM PDT
gpg: using RSA key 00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
gpg: issuer "[email protected]"
gpg: Good signature from "Palmer Dabbelt <[email protected]>" [ultimate]
gpg: aka "Palmer Dabbelt <[email protected]>" [ultimate]
Author: Palmer Dabbelt <[email protected]>
Date: Tue Aug 6 08:03:59 2019 -0700
RISC-V: Remove udivdi3
This should never have landed in the first place: it was added as
part
of 64-bit divide support for 32-bit systems, but the kernel doesn't allow this sort of division. I must have forgotten to remove it.

Quoted 3 lines

Just FYI, you probably already know this, but this patch was mangled on the list. I'll reformat it and queue it up, but figured you probably would want to know if you didn't already.

Ya, they're mangled when I inline them. I'm usually just asking for people to look at the concept here, and I send a real patch out later.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Acked-by
#10 lore raw
In reply to Palmer Dabbelt
Quoted 9 lines · Palmer Dabbelt

Author: Palmer Dabbelt <[email protected]>
Date: Tue Aug 6 08:03:59 2019 -0700

RISC-V: Remove udivdi3

This should never have landed in the first place: it was added as part of 64-bit divide support for 32-bit systems, but the kernel doesn't allow this sort of division. I must have forgotten to remove it.

Quoted 5 lines

This patch removes the support. Since this routine only worked on 64-bit platforms but was only built on 32-bit platforms, it's essentially just nonsense anyway.

Related: there is still some opportunity for performance gain on rv32 by providing an assembly version of __arch_xprod_64() if someone is up to it.

Nicolas

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv