move pia_res_to_output to common test helpers
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 9 Oct 2020 03:21:51 +0000 (20:21 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 9 Oct 2020 03:21:51 +0000 (20:21 -0700)
src/soc/fu/div/test/helper.py
src/soc/fu/test/pia.py [new file with mode: 0644]

index a11b34942356448d7386c1aff5435ef4406350d9..5be75e64b9c4fc58901926ac15d8bf3272977273 100644 (file)
@@ -14,6 +14,7 @@ from soc.decoder.isa.all import ISA
 from soc.config.endian import bigendian
 
 from soc.fu.test.common import ALUHelpers
+from soc.fu.test.pia import pia_res_to_output
 from soc.fu.div.pipeline import DivBasePipe
 from soc.fu.div.pipe_data import DivPipeSpec
 
@@ -37,37 +38,6 @@ def get_cu_inputs(dec2, sim):
     return res
 
 
-def pia_res_to_output(pia_res):
-    retval = {}
-    if pia_res.rt is not None:
-        retval["o"] = pia_res.rt
-    if pia_res.cr0 is not None:
-        cr0 = pia_res.cr0
-        v = 0
-        if cr0.lt:
-            v |= 8
-        if cr0.gt:
-            v |= 4
-        if cr0.eq:
-            v |= 2
-        if cr0.so:
-            v |= 1
-        retval["cr_a"] = v
-    if pia_res.overflow is not None:
-        overflow = pia_res.overflow
-        v = 0
-        if overflow.ov:
-            v |= 1
-        if overflow.ov32:
-            v |= 2
-        retval["xer_ov"] = v
-        retval["xer_so"] = overflow.so
-    else:
-        retval["xer_ov"] = 0
-        retval["xer_so"] = 0
-    return retval
-
-
 def set_alu_inputs(alu, dec2, sim):
     # TODO: see https://bugs.libre-soc.org/show_bug.cgi?id=305#c43
     # detect the immediate here (with m.If(self.i.ctx.op.imm_data.imm_ok))
diff --git a/src/soc/fu/test/pia.py b/src/soc/fu/test/pia.py
new file mode 100644 (file)
index 0000000..b51ab7d
--- /dev/null
@@ -0,0 +1,33 @@
+import power_instruction_analyzer as pia
+
+
+def pia_res_to_output(pia_res):
+    assert isinstance(pia_res, pia.InstructionOutput)
+    retval = {}
+    if pia_res.rt is not None:
+        retval["o"] = pia_res.rt
+    if pia_res.cr0 is not None:
+        cr0 = pia_res.cr0
+        v = 0
+        if cr0.lt:
+            v |= 8
+        if cr0.gt:
+            v |= 4
+        if cr0.eq:
+            v |= 2
+        if cr0.so:
+            v |= 1
+        retval["cr_a"] = v
+    if pia_res.overflow is not None:
+        overflow = pia_res.overflow
+        v = 0
+        if overflow.ov:
+            v |= 1
+        if overflow.ov32:
+            v |= 2
+        retval["xer_ov"] = v
+        retval["xer_so"] = overflow.so
+    else:
+        retval["xer_ov"] = 0
+        retval["xer_so"] = 0
+    return retval