reimplement div[u][w]/rem[u][w]
authorAndrew Waterman <waterman@eecs.berkeley.edu>
Thu, 16 Feb 2012 03:44:24 +0000 (19:44 -0800)
committerAndrew Waterman <waterman@eecs.berkeley.edu>
Thu, 16 Feb 2012 03:44:24 +0000 (19:44 -0800)
fixes bugs for inputs not properly sign-extended

riscv/insns/div.h
riscv/insns/divu.h
riscv/insns/divuw.h
riscv/insns/divw.h
riscv/insns/rem.h
riscv/insns/remu.h
riscv/insns/remuw.h
riscv/insns/remw.h

index 82a40666dcca5021cf67dc7f74c828b52e2e3089..8412f6120a810792976f8cc97df34592ffd2a9ff 100644 (file)
@@ -1,6 +1,8 @@
-if(RS2 == 0)
+sreg_t lhs = sext_xprlen(RS1);
+sreg_t rhs = sext_xprlen(RS2);
+if(rhs == 0)
   RD = UINT64_MAX;
-else if(sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1)
-  RD = RS1;
+else if(lhs == INT64_MIN && rhs == -1)
+  RD = lhs;
 else
-  RD = sext_xprlen(sext_xprlen(RS1) / sext_xprlen(RS2));
+  RD = sext_xprlen(lhs / rhs);
index 681afd217bbbda882d88de0c7a93848c8ed0d6fa..4346349d3a45254e51c81c10b51d2c66903d2162 100644 (file)
@@ -1,4 +1,6 @@
-if(RS2 == 0)
+reg_t lhs = zext_xprlen(RS1);
+reg_t rhs = zext_xprlen(RS2);
+if(rhs == 0)
   RD = UINT64_MAX;
 else
-  RD = sext_xprlen(zext_xprlen(RS1) / zext_xprlen(RS2));
+  RD = sext_xprlen(lhs / rhs);
index 2cf051141ca8ffa35ae1f18f5b9b80c482719982..7f6e32115c9d7bcd7ef1b98b93cdbbed302406e0 100644 (file)
@@ -1,5 +1,7 @@
 require_xpr64;
-if(zext32(RS2) == 0)
+reg_t lhs = zext32(RS1);
+reg_t rhs = zext32(RS2);
+if(rhs == 0)
   RD = UINT64_MAX;
 else
-  RD = sext32(zext32(RS1) / zext32(RS2));
+  RD = sext32(lhs / rhs);
index 84f42a9b3094345e22ad4367e35c2266db826862..b51d9b7cbc100e2d443de550b47664d6fe8a6d83 100644 (file)
@@ -1,7 +1,7 @@
 require_xpr64;
-if(int32_t(RS2) == 0)
+sreg_t lhs = sext32(RS1);
+sreg_t rhs = sext32(RS2);
+if(rhs == 0)
   RD = UINT64_MAX;
-else if(int32_t(RS1) == INT32_MIN && int32_t(RS2) == -1)
-  RD = RS1;
 else
-  RD = sext32(int32_t(RS1) / int32_t(RS2));
+  RD = sext32(lhs / rhs);
index ac82a56f4179219a30354d11a9e4531ee45569d4..8094b5bba1715b3c59db12b7e99073f2644d7069 100644 (file)
@@ -1,6 +1,8 @@
-if(RS2 == 0)
-  RD = RS1;
-else if(sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1)
+sreg_t lhs = sext_xprlen(RS1);
+sreg_t rhs = sext_xprlen(RS2);
+if(rhs == 0)
+  RD = lhs;
+else if(lhs == INT64_MIN && rhs == -1)
   RD = 0;
 else
-  RD = sext_xprlen(sext_xprlen(RS1) % sext_xprlen(RS2));
+  RD = sext_xprlen(lhs % rhs);
index c698aca2fefadae41f339b9d947e4e47b5ee5c4c..ca66318fea0ecd05ba73ef89c6530a1b4b044b83 100644 (file)
@@ -1,4 +1,6 @@
-if(RS2 == 0)
-  RD = RS1;
+reg_t lhs = zext_xprlen(RS1);
+reg_t rhs = zext_xprlen(RS2);
+if(rhs == 0)
+  RD = lhs;
 else
-  RD = sext_xprlen(zext_xprlen(RS1) % zext_xprlen(RS2));
+  RD = sext_xprlen(lhs % rhs);
index 1cc015ded15d67ebd9b983a4f78f01bd5634f5df..aac13fbf1defa03563f13f37724cceff050bb013 100644 (file)
@@ -1,5 +1,7 @@
 require_xpr64;
-if(zext_xprlen(RS2) == 0)
-  RD = RS1;
+reg_t lhs = zext32(RS1);
+reg_t rhs = zext32(RS2);
+if(rhs == 0)
+  RD = lhs;
 else
-  RD = sext32(zext_xprlen(RS1) % zext_xprlen(RS2));
+  RD = sext32(lhs % rhs);
index 1093533e3f2d9e62e568c7ee331792501c01553b..cc89fa740678ca8bfc6a92ab09fc7b22e34b7d2f 100644 (file)
@@ -1,7 +1,7 @@
 require_xpr64;
-if(int32_t(RS2) == 0)
-  RD = RS1;
-else if(int32_t(RS1) == INT32_MIN && int32_t(RS2) == -1)
-  RD = 0;
+sreg_t lhs = sext32(RS1);
+sreg_t rhs = sext32(RS2);
+if(rhs == 0)
+  RD = lhs;
 else
-  RD = sext32(int32_t(RS1) % int32_t(RS2));
+  RD = sext32(lhs % rhs);