From: Andrew Cagney Date: Mon, 28 Jul 1997 13:46:53 +0000 (+0000) Subject: Handle overflow from signed divide by -1. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9204a35e78a137f3f30d5ea979da6f3308f1a64e;p=binutils-gdb.git Handle overflow from signed divide by -1. --- diff --git a/sim/mips/gencode.c b/sim/mips/gencode.c index e264b0a4dc7..5e4563d7d9f 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");