From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2093) id 4BAB13858CDB; Mon, 20 Feb 2023 11:03:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BAB13858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676891033; bh=Ef2+N0dM5fQZDFBJfbfqLJJI9WGKsh5cI3JkBP9wGWc=; h=From:To:Subject:Date:From; b=n+z+vdTGqHDBgYiO7pP7zKcU5eVkcZg0GMXY4Xk5keoyCusPa/a+Y8cGxeka8Oua+ J7R2bm3Tso1EFqvpZtwsASeJYVYYos1TfiV/cAKXKAX8Aow4uKcfqiZdnEjJspHHNo kTszGqB3h7GNMe0DbcDKPVGhwifm9oe+RkNi4k1M= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kito Cheng To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-11220] RISC-V: Make __divdi3 handle div by zero same as hardware. X-Act-Checkin: gcc X-Git-Author: Jim Wilson X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: b7fa32ad2b428c7dcb62e6eef8dd330e5186a0c5 X-Git-Newrev: d465a40200324d56c51f02f2c5807e716f9c8775 Message-Id: <20230220110353.4BAB13858CDB@sourceware.org> Date: Mon, 20 Feb 2023 11:03:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d465a40200324d56c51f02f2c5807e716f9c8775 commit r10-11220-gd465a40200324d56c51f02f2c5807e716f9c8775 Author: Jim Wilson 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