public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix for v850e divq instruction
@ 2022-04-06 15:11 Jeff Law
0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2022-04-06 15:11 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=477904ca751c50d243ee3cba3f12cf75e8ba12b3
commit 477904ca751c50d243ee3cba3f12cf75e8ba12b3
Author: Jeff Law <jeffreyalaw@gmail.com>
Date: Wed Apr 6 11:10:40 2022 -0400
Fix for v850e divq instruction
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.
Diff:
---
sim/testsuite/v850/divq.cgs | 11 +++++++++++
sim/v850/simops.c | 4 ++--
2 files changed, 13 insertions(+), 2 deletions(-)
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 e9a5d489d88..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)))
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-06 15:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 15:11 [binutils-gdb] Fix for v850e divq instruction Jeff Law
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).