from soc.fu.alu.pipeline import ALUBasePipe
from soc.fu.alu.pipe_data import ALUPipeSpec
+from soc.fu.logical.pipeline import LogicalBasePipe
+from soc.fu.logical.pipe_data import LogicalPipeSpec
+
from soc.fu.cr.pipeline import CRBasePipe
from soc.fu.cr.pipe_data import CRPipeSpec
class ALUFunctionUnit(FunctionUnitBaseSingle):
def __init__(self): super().__init__(ALUPipeSpec, ALUBasePipe)
+class LogicalFunctionUnit(FunctionUnitBaseSingle):
+ def __init__(self): super().__init__(LogicalPipeSpec, LogicalBasePipe)
+
class CRFunctionUnit(FunctionUnitBaseSingle):
def __init__(self): super().__init__(CRPipeSpec, CRBasePipe)
import unittest
-from soc.decoder.power_enums import (XER_bits,)
+from soc.decoder.power_enums import (XER_bits, Function)
# XXX bad practice: use of global variables
from soc.fu.alu.test.test_pipe_caller import ALUTestCase # creates the tests
class ALUTestRunner(TestRunner):
def __init__(self, test_data):
- super().__init__(test_data, ALUFunctionUnit, self)
+ super().__init__(test_data, ALUFunctionUnit, self,
+ Function.ALU)
def get_cu_inputs(self, dec2, sim):
"""naming (res) must conform to ALUFunctionUnit input regspec
class TestRunner(FHDLTestCase):
- def __init__(self, test_data, fukls, iodef):
+ def __init__(self, test_data, fukls, iodef, funit):
super().__init__("run_all")
self.test_data = test_data
self.fukls = fukls
- self.iodef = iodef
+ self.iodef = iodef
+ self.funit = funit
def run_all(self):
m = Module()
yield instruction.eq(ins) # raw binary instr.
yield Settle()
fn_unit = yield pdecode2.e.fn_unit
- self.assertEqual(fn_unit, Function.ALU.value)
+ self.assertEqual(fn_unit, self.funit.value)
# set operand and get inputs
yield from set_operand(cu, pdecode2, sim)
--- /dev/null
+import unittest
+from soc.decoder.power_enums import (XER_bits, Function)
+
+# XXX bad practice: use of global variables
+from soc.fu.logical.test.test_pipe_caller import LogicalTestCase
+from soc.fu.logical.test.test_pipe_caller import test_data
+
+from soc.fu.compunits.compunits import LogicalFunctionUnit
+from soc.fu.compunits.test.test_compunit import TestRunner
+
+
+class LogicalTestRunner(TestRunner):
+ def __init__(self, test_data):
+ super().__init__(test_data, LogicalFunctionUnit, self,
+ Function.LOGICAL)
+
+ def get_cu_inputs(self, dec2, sim):
+ """naming (res) must conform to LogicalFunctionUnit input regspec
+ """
+ res = {}
+
+ # RA (or RC)
+ reg3_ok = yield dec2.e.read_reg3.ok
+ reg1_ok = yield dec2.e.read_reg1.ok
+ assert reg3_ok != reg1_ok
+ if reg3_ok:
+ data1 = yield dec2.e.read_reg3.data
+ res['a'] = sim.gpr(data1).value
+ elif reg1_ok:
+ data1 = yield dec2.e.read_reg1.data
+ res['a'] = sim.gpr(data1).value
+
+ # RB (or immediate)
+ reg2_ok = yield dec2.e.read_reg2.ok
+ if reg2_ok:
+ data2 = yield dec2.e.read_reg2.data
+ res['b'] = sim.gpr(data2).value
+
+ return res
+
+ def check_cu_outputs(self, res, dec2, sim, code):
+ """naming (res) must conform to LogicalFunctionUnit output regspec
+ """
+
+ # RT
+ out_reg_valid = yield dec2.e.write_reg.ok
+ if out_reg_valid:
+ write_reg_idx = yield dec2.e.write_reg.data
+ expected = sim.gpr(write_reg_idx).value
+ cu_out = res['o']
+ print(f"expected {expected:x}, actual: {cu_out:x}")
+ self.assertEqual(expected, cu_out, code)
+
+ rc = yield dec2.e.rc.data
+ op = yield dec2.e.insn_type
+ cridx_ok = yield dec2.e.write_cr.ok
+ cridx = yield dec2.e.write_cr.data
+
+ print ("check extra output", repr(code), cridx_ok, cridx)
+
+ if rc:
+ self.assertEqual(cridx_ok, 1, code)
+ self.assertEqual(cridx, 0, code)
+
+ # CR (CR0-7)
+ if cridx_ok:
+ cr_expected = sim.crl[cridx].get_range().value
+ cr_actual = res['cr0']
+ print ("CR", cridx, cr_expected, cr_actual)
+ self.assertEqual(cr_expected, cr_actual, "CR%d %s" % (cridx, code))
+
+ # XER.ca
+ cry_out = yield dec2.e.output_carry
+ if cry_out:
+ expected_carry = 1 if sim.spr['XER'][XER_bits['CA']] else 0
+ xer_ca = res['xer_ca']
+ real_carry = xer_ca & 0b1 # XXX CO not CO32
+ self.assertEqual(expected_carry, real_carry, code)
+ expected_carry32 = 1 if sim.spr['XER'][XER_bits['CA32']] else 0
+ real_carry32 = bool(xer_ca & 0b10) # XXX CO32
+ self.assertEqual(expected_carry32, real_carry32, code)
+
+
+if __name__ == "__main__":
+ unittest.main(exit=False)
+ suite = unittest.TestSuite()
+ suite.addTest(LogicalTestRunner(test_data))
+
+ runner = unittest.TextTestRunner()
+ runner.run(suite)