aboutsummaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-07-28 13:46:53 +0000
committerAndrew Cagney <cagney@redhat.com>1997-07-28 13:46:53 +0000
commit9204a35e78a137f3f30d5ea979da6f3308f1a64e (patch)
treea0e951384147d6072cab232dfef432eb863eb37b /sim
parent6546a590b45a2473c144b2a855c5949f8198ac68 (diff)
downloadfsf-binutils-gdb-9204a35e78a137f3f30d5ea979da6f3308f1a64e.zip
fsf-binutils-gdb-9204a35e78a137f3f30d5ea979da6f3308f1a64e.tar.gz
fsf-binutils-gdb-9204a35e78a137f3f30d5ea979da6f3308f1a64e.tar.bz2
Handle overflow from signed divide by -1.
Diffstat (limited to 'sim')
-rw-r--r--sim/mips/gencode.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/sim/mips/gencode.c b/sim/mips/gencode.c
index e264b0a..5e4563d 100644
--- a/sim/mips/gencode.c
+++ b/sim/mips/gencode.c
@@ -3488,18 +3488,37 @@ build_instruction (doisa, features, mips16, insn)
{
char hi = (i == 0 ? ' ' : '1');
int d = i * 2;
+ if (! (insn->flags & UNSIGNED))
+ {
+ printf("if (RT_SW(%d) == -1)\n", d );
+ printf(" {\n");
+ printf(" LO%c = -RS_%sW(%d);\n", hi, sign, d );
+ printf(" HI%c = 0;\n", hi );
+ printf(" }\nelse ");
+ };
printf("if (RT_UW(%d) != 0)\n", d );
- printf(" {\n");
- printf("LO%c = (signed32)(RS_%sW(%d) / RT_%sW(%d));\n", hi, sign, d, sign, d );
- printf("HI%c = (signed32)(RS_%sW(%d) %% RT_%sW(%d));\n", hi, sign, d, sign, d );
- printf(" }\n");
+ printf(" {\n");
+ printf(" LO%c = (signed32)(RS_%sW(%d) / RT_%sW(%d));\n", hi, sign, d, sign, d );
+ printf(" HI%c = (signed32)(RS_%sW(%d) %% RT_%sW(%d));\n", hi, sign, d, sign, d );
+ printf(" }\n");
}
break;
}
case PDIVBW:
printf("signed32 devisor = RT_SH(0);\n");
- printf("if (devisor != 0)\n");
+ printf("if (devisor == -1)\n");
+ printf(" {\n");
+ printf(" LO_SW(0) = -RS_SW(0);\n");
+ printf(" HI_SW(0) = 0;\n");
+ printf(" LO_SW(1) = -RS_SW(1);\n");
+ printf(" HI_SW(1) = 0;\n");
+ printf(" LO_SW(2) = -RS_SW(2);\n");
+ printf(" HI_SW(2) = 0;\n");
+ printf(" LO_SW(3) = -RS_SW(3);\n");
+ printf(" HI_SW(3) = 0;\n");
+ printf(" }\n");
+ printf("else if (devisor != 0)\n");
printf(" {\n");
printf(" LO_SW(0) = RS_SW(0) / devisor;\n");
printf(" HI_SW(0) = SIGNEXTEND( (RS_SW(0) %% devisor), 16 );\n");