From 1fc2a159a3181ac77fe7156de7ca811d185548f9 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 27 Aug 2020 20:37:04 +0100 Subject: [PATCH] really bad hack to fix simulator bug in carry handling https://bugs.libre-soc.org/show_bug.cgi?id=476 --- src/soc/decoder/isa/caller.py | 30 +++++++++++++++++++++++------- src/soc/decoder/selectable_int.py | 3 ++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/soc/decoder/isa/caller.py b/src/soc/decoder/isa/caller.py index e3d349bb..dd4ed1e1 100644 --- a/src/soc/decoder/isa/caller.py +++ b/src/soc/decoder/isa/caller.py @@ -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 diff --git a/src/soc/decoder/selectable_int.py b/src/soc/decoder/selectable_int.py index f98f6162..8eabec3e 100644 --- a/src/soc/decoder/selectable_int.py +++ b/src/soc/decoder/selectable_int.py @@ -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) -- 2.30.2