Handle overflow from signed divide by -1.
authorAndrew Cagney <cagney@redhat.com>
Mon, 28 Jul 1997 13:46:53 +0000 (13:46 +0000)
committerAndrew Cagney <cagney@redhat.com>
Mon, 28 Jul 1997 13:46:53 +0000 (13:46 +0000)
sim/mips/gencode.c

index e264b0a4dc7b2b35d4b13bbde36fe1912444fddc..5e4563d7d9f85a78c2eebe3dfa5da507f9561736 100644 (file)
@@ -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");