Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jeff Law via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: Fwd: Fix for v850e divq instruction
Date: Mon, 4 Apr 2022 16:49:00 -0600	[thread overview]
Message-ID: <e22d76f5-6343-3e86-1713-d6a05112a0bc@gmail.com> (raw)
In-Reply-To: <4eaa501f-9b0a-20dc-6972-0ca0686d2a75@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

Similarly, this should have gone to the gdb list.


-------- Forwarded Message --------
Subject: 	Fix for v850e divq instruction
Date: 	Sun, 3 Apr 2022 10:25:16 -0600
From: 	Jeff Law <jeffreyalaw@gmail.com>
To: 	binutils@sourceware.org



This is the last of the correctness fixes I've been carrying around for 
the v850.

Like the other recent fixes, this is another case where we haven't been 
as careful as we should WRT host vs target types.   For the divq 
instruction both operands are 32 bit types.  Yet in the simulator code 
we convert them from unsigned int to signed long by assignment.  So 
0xfffffffb (aka -5) turns into 4294967291 and naturally that changes the 
result of our division.

The fix is simple, insert a cast to int32_t to force interpretation as a 
signed value.

Testcase for the simulator is included.  It has a trivial dependency on 
the bins patch.

OK for the trunk?

JEff

[-- Attachment #2: P --]
[-- Type: text/plain, Size: 868 bytes --]

diff --git a/sim/testsuite/v850/divq.cgs b/sim/testsuite/v850/divq.cgs
new file mode 100644
index 00000000000..8461f86f7a0
--- /dev/null
+++ b/sim/testsuite/v850/divq.cgs
@@ -0,0 +1,11 @@
+# v850 bins
+# mach: v850e3v5
+# as: -mv850e3v5
+
+	.include "testutils.inc"
+	seti	0xfffffffb r11
+	seti	0x32 r10
+	divq	r11, r10, r11
+	reg	r10, 0xfffffff6
+	reg	r11, 0x0
+	pass
diff --git a/sim/v850/simops.c b/sim/v850/simops.c
index d2640577fc8..f90a0f7573c 100644
--- a/sim/v850/simops.c
+++ b/sim/v850/simops.c
@@ -3135,8 +3135,8 @@ v850_div (SIM_DESC sd, unsigned int op0, unsigned int op1, unsigned int *op2p, u
   bfd_boolean     overflow = FALSE;
   
   /* Compute the result.  */
-  divide_by   = op0;
-  divide_this = op1;
+  divide_by   = (int32_t)op0;
+  divide_this = (int32_t)op1;
 
   if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
     {


       reply	other threads:[~2022-04-04 22:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4eaa501f-9b0a-20dc-6972-0ca0686d2a75@gmail.com>
2022-04-04 22:49 ` Jeff Law via Gdb-patches [this message]
2022-04-06  3:56   ` Mike Frysinger via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e22d76f5-6343-3e86-1713-d6a05112a0bc@gmail.com \
    --to=gdb-patches@sourceware.org \
    --cc=jeffreyalaw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox