aboutsummaryrefslogtreecommitdiff
path: root/packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch
diff options
context:
space:
mode:
authorXeonacid <h.dwwwwww@gmail.com>2025-04-04 13:35:06 +0200
committerChris Packham <judge.packham@gmail.com>2025-04-22 09:57:25 +1200
commit4e7bdd2b259eb95386ab5987d525f54470159e67 (patch)
tree7767e8bccdbbc4ca99f2d807d9a3cbf1282c6ea0 /packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch
parentb9348944c8b357e798989d9b224e869decd02919 (diff)
downloadcrosstool-ng-4e7bdd2b259eb95386ab5987d525f54470159e67.tar.gz
crosstool-ng-4e7bdd2b259eb95386ab5987d525f54470159e67.tar.bz2
crosstool-ng-4e7bdd2b259eb95386ab5987d525f54470159e67.zip
gcc/riscv: Fix incorrect jal with HIDDEN_JUMPTARGET
Similar to #2315, backport commit 45116f3 for gcc 7,8,9. Gcc 7 is the first version to support RISC-V. Signed-off-by: Xeonacid <h.dwwwwww@gmail.com>
Diffstat (limited to 'packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch')
-rw-r--r--packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch b/packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch
new file mode 100644
index 00000000..47c25104
--- /dev/null
+++ b/packages/gcc/8.5.0/0033-riscv-Make-__divdi3-handle-div-by-zero-same-as-hard.patch
@@ -0,0 +1,40 @@
+From 4013baf99c38f7bca06a51f8301e8fb195ccfa33 Mon Sep 17 00:00:00 2001
+From: Jim Wilson <jimw@sifive.com>
+Date: Tue, 2 Jun 2020 11:19:39 -0700
+Subject: [PATCH] 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.
+---
+ 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 151f8e273a..17234324c1 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
+--
+2.49.0
+