Skip to content

Commit 477904c

Browse files
committedApr 6, 2022
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.
1 parent 49fffa5 commit 477904c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
 

‎sim/testsuite/v850/divq.cgs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# v850 bins
2+
# mach: v850e3v5
3+
# as: -mv850e3v5
4+
5+
.include "testutils.inc"
6+
seti 0xfffffffb r11
7+
seti 0x32 r10
8+
divq r11, r10, r11
9+
reg r10, 0xfffffff6
10+
reg r11, 0x0
11+
pass

‎sim/v850/simops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,8 +3135,8 @@ v850_div (SIM_DESC sd, unsigned int op0, unsigned int op1, unsigned int *op2p, u
31353135
bfd_boolean overflow = FALSE;
31363136

31373137
/* Compute the result. */
3138-
divide_by = op0;
3139-
divide_this = op1;
3138+
divide_by = (int32_t)op0;
3139+
divide_this = (int32_t)op1;
31403140

31413141
if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
31423142
{

0 commit comments

Comments
 (0)