really bad hack to fix simulator bug in carry handling
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 27 Aug 2020 19:37:04 +0000 (20:37 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 27 Aug 2020 19:37:04 +0000 (20:37 +0100)
https://bugs.libre-soc.org/show_bug.cgi?id=476

src/soc/decoder/isa/caller.py
src/soc/decoder/selectable_int.py

index e3d349bb57f0a1638d987d018a08596b1b2f6c74..dd4ed1e1b6559a530bb8c5d57a3d5ff94ca1ed4c 100644 (file)
@@ -427,17 +427,33 @@ class ISACaller:
             gts.append(gt)
         print(gts)
         cy = 1 if any(gts) else 0
+        print ("CA", cy, gts)
         if not (1 & already_done):
             self.spr['XER'][XER_bits['CA']] = cy
 
-        print("inputs", inputs)
+        print("inputs", already_done, inputs)
         # 32 bit carry
-        gts = []
-        for x in inputs:
-            print("input", x, output)
-            gt = (gtu(x[32:64], output[32:64])) == SelectableInt(1, 1)
-            gts.append(gt)
-        cy32 = 1 if any(gts) else 0
+        # ARGH... different for OP_ADD... *sigh*...
+        op = yield self.dec2.e.do.insn_type
+        if op == MicrOp.OP_ADD.value:
+            res32 = (output.value & (1<<32)) != 0
+            a32 = (inputs[0].value & (1<<32)) != 0
+            if len(inputs) >= 2:
+                b32 = (inputs[1].value & (1<<32)) != 0
+            else:
+                b32 = False
+            cy32 = res32 ^ a32 ^ b32
+            print ("CA32 ADD", cy32)
+        else:
+            gts = []
+            for x in inputs:
+                print("input", x, output)
+                print("     x[32:64]", x, x[32:64])
+                print("     o[32:64]", output, output[32:64])
+                gt = (gtu(x[32:64], output[32:64])) == SelectableInt(1, 1)
+                gts.append(gt)
+            cy32 = 1 if any(gts) else 0
+            print ("CA32", cy32, gts)
         if not (2 & already_done):
             self.spr['XER'][XER_bits['CA32']] = cy32
 
index f98f6162ec625ba2defbf3ed95c520c18c5292ea..8eabec3ed08597ab5b601beed9e042cd396ddb10 100644 (file)
@@ -171,6 +171,7 @@ class SelectableInt:
         mask = (1 << bits) - 1
         self.value = value & mask
         self.bits = bits
+        self.overflow = (value & ~mask) != 0
 
     def eq(self, b):
         self.value = b.value
@@ -288,7 +289,7 @@ class SelectableInt:
             start = self.bits - key.stop
 
             bits = stop - start
-            #print ("__getitem__ slice num bits", bits)
+            #print ("__getitem__ slice num bits", start, stop, bits)
             mask = (1 << bits) - 1
             value = (self.value >> start) & mask
             return SelectableInt(value, bits)