public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-11220] RISC-V: Make __divdi3 handle div by zero same as hardware.
@ 2023-02-20 11:03 Kito Cheng
  0 siblings, 0 replies; only message in thread
From: Kito Cheng @ 2023-02-20 11:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d465a40200324d56c51f02f2c5807e716f9c8775

commit r10-11220-gd465a40200324d56c51f02f2c5807e716f9c8775
Author: Jim Wilson <jimw@sifive.com>
Date:   Tue Jun 2 11:19:39 2020 -0700

    RISC-V: Make __divdi3 handle div by zero same as hardware.
    
    The ISA manual specifies that divide by zero always returns -1 as the result.
    We were failing to do that when the dividend was negative.
    
    Original patch from Virginie Moser.
    
            libgcc/
            * config/riscv/div.S (__divdi3): For negative arguments, change bgez
            to bgtz.
    
    (cherry picked from commit 4013baf99c38f7bca06a51f8301e8fb195ccfa33)

Diff:
---
 libgcc/config/riscv/div.S | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libgcc/config/riscv/div.S b/libgcc/config/riscv/div.S
index 151f8e273ac..17234324c1e 100644
--- a/libgcc/config/riscv/div.S
+++ b/libgcc/config/riscv/div.S
@@ -107,10 +107,12 @@ FUNC_END (__umoddi3)
   /* Handle negative arguments to __divdi3.  */
 .L10:
   neg   a0, a0
-  bgez  a1, .L12      /* Compute __udivdi3(-a0, a1), then negate the result.  */
+  /* Zero is handled as a negative so that the result will not be inverted.  */
+  bgtz  a1, .L12     /* Compute __udivdi3(-a0, a1), then negate the result.  */
+
   neg   a1, a1
-  j     __udivdi3     /* Compute __udivdi3(-a0, -a1).  */
-.L11:                 /* Compute __udivdi3(a0, -a1), then negate the result.  */
+  j     __udivdi3    /* Compute __udivdi3(-a0, -a1).  */
+.L11:                /* Compute __udivdi3(a0, -a1), then negate the result.  */
   neg   a1, a1
 .L12:
   move  t0, ra

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-20 11:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20 11:03 [gcc r10-11220] RISC-V: Make __divdi3 handle div by zero same as hardware Kito Cheng

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 read-only IMAP folder(s) and NNTP newsgroup(s).