From cf32d62679901d9d9ae096f2ef1b8e4cf79c7627 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 3 Jun 2020 12:10:20 +0100 Subject: [PATCH] move obtaining simulator data into common function for logical pipe tests --- .../compunits/test/test_logical_compunit.py | 17 +------ src/soc/fu/logical/test/test_pipe_caller.py | 47 ++++++++++++------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/soc/fu/compunits/test/test_logical_compunit.py b/src/soc/fu/compunits/test/test_logical_compunit.py index 8745b0b1..2591bcd4 100644 --- a/src/soc/fu/compunits/test/test_logical_compunit.py +++ b/src/soc/fu/compunits/test/test_logical_compunit.py @@ -2,7 +2,7 @@ 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 LogicalTestCase, get_cu_inputs from soc.fu.logical.test.test_pipe_caller import test_data from soc.fu.compunits.compunits import LogicalFunctionUnit @@ -17,20 +17,7 @@ class LogicalTestRunner(TestRunner): def get_cu_inputs(self, dec2, sim): """naming (res) must conform to LogicalFunctionUnit input regspec """ - res = {} - - # RA (or RC) - reg1_ok = yield dec2.e.read_reg1.ok - if reg1_ok: - data1 = yield dec2.e.read_reg1.data - res['ra'] = 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['rb'] = sim.gpr(data2).value - + res = yield from get_cu_inputs(dec2, sim) return res def check_cu_outputs(self, res, dec2, sim, code): diff --git a/src/soc/fu/logical/test/test_pipe_caller.py b/src/soc/fu/logical/test/test_pipe_caller.py index c8f1ebc2..480603ab 100644 --- a/src/soc/fu/logical/test/test_pipe_caller.py +++ b/src/soc/fu/logical/test/test_pipe_caller.py @@ -23,32 +23,45 @@ class TestCase: self.sprs = sprs self.name = name +def get_cu_inputs(dec2, sim): + """naming (res) must conform to LogicalFunctionUnit input regspec + """ + res = {} -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)) - # and place it into data_i.b - + # RA (or RC) reg1_ok = yield dec2.e.read_reg1.ok if reg1_ok: data1 = yield dec2.e.read_reg1.data - data1 = sim.gpr(data1).value - else: - data1 = 0 + res['ra'] = sim.gpr(data1).value - yield alu.p.data_i.a.eq(data1) - - # If there's an immediate, set the B operand to that + # RB (or immediate) reg2_ok = yield dec2.e.read_reg2.ok + #imm_ok = yield dec2.e.imm_data.imm_ok + if reg2_ok: + data2 = yield dec2.e.read_reg2.data + data2 = sim.gpr(data2).value + res['rb'] = data2 + #elif imm_ok: + # data2 = yield dec2.e.imm_data.imm + # res['rb'] = data2 + + return res + + +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)) + # and place it into data_i.b + + inp = yield from get_cu_inputs(dec2, sim) + if 'ra' in inp: + yield alu.p.data_i.a.eq(inp['ra']) + if 'rb' in inp: + yield alu.p.data_i.b.eq(inp['rb']) imm_ok = yield dec2.e.imm_data.imm_ok if imm_ok: data2 = yield dec2.e.imm_data.imm - elif reg2_ok: - data2 = yield dec2.e.read_reg2.data - data2 = sim.gpr(data2).value - else: - data2 = 0 - yield alu.p.data_i.b.eq(data2) + yield alu.p.data_i.b.eq(data2) # This test bench is a bit different than is usual. Initially when I -- 2.30.2