-from nmigen import Module, Signal
-from nmigen.back.pysim import Simulator, Delay, Settle
-from nmigen.test.utils import FHDLTestCase
-from nmigen.cli import rtlil
import unittest
-from soc.decoder.isa.caller import ISACaller, special_sprs
-from soc.decoder.power_decoder import (create_pdecode)
-from soc.decoder.power_decoder2 import (PowerDecode2)
-from soc.decoder.power_enums import (XER_bits, Function, InternalOp)
-from soc.decoder.selectable_int import SelectableInt
-from soc.simulator.program import Program
-from soc.decoder.isa.all import ISA
+from soc.decoder.power_enums import (XER_bits,)
from soc.fu.alu.test.test_pipe_caller import TestCase, ALUTestCase, test_data
from soc.fu.compunits.compunits import ALUFunctionUnit
from soc.fu.compunits.test.test_compunit import TestRunner
-from soc.experiment.compalu_multi import find_ok # hack
-import random
-
-def set_cu_input(cu, idx, data):
- rdop = cu.get_in_name(idx)
- yield cu.src_i[idx].eq(data)
- while True:
- rd_rel_o = yield cu.rd.rel[idx]
- print ("rd_rel %d wait HI" % idx, rd_rel_o, rdop, hex(data))
- if rd_rel_o:
- break
- yield
- yield cu.rd.go[idx].eq(1)
- while True:
- yield
- rd_rel_o = yield cu.rd.rel[idx]
- if rd_rel_o:
- break
- print ("rd_rel %d wait HI" % idx, rd_rel_o)
- yield
- yield cu.rd.go[idx].eq(0)
-
-
-def get_cu_output(cu, idx, code):
- wrmask = yield cu.wrmask
- wrop = cu.get_out_name(idx)
- wrok = cu.get_out(idx)
- fname = find_ok(wrok.fields)
- wrok = yield getattr(wrok, fname)
- print ("wr_rel mask", repr(code), idx, wrop, bin(wrmask), fname, wrok)
- assert wrmask & (1<<idx), \
- "get_cu_output '%s': mask bit %d not set\n" \
- "write-operand '%s' Data.ok likely not set (%s)" \
- % (code, idx, wrop, hex(wrok))
- while True:
- wr_relall_o = yield cu.wr.rel
- wr_rel_o = yield cu.wr.rel[idx]
- print ("wr_rel %d wait" % idx, hex(wr_relall_o), wr_rel_o)
- if wr_rel_o:
- break
- yield
- yield cu.wr.go[idx].eq(1)
- yield Settle()
- result = yield cu.dest[idx]
- yield
- yield cu.wr.go[idx].eq(0)
- print ("result", repr(code), idx, wrop, wrok, hex(result))
- return result
-
class ALUTestRunner(TestRunner):
super().__init__(test_data, ALUFunctionUnit, self)
def get_cu_inputs(self, 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
+ """naming (res) must conform to ALUFunctionUnit input regspec
+ """
res = {}
reg3_ok = yield dec2.e.read_reg3.ok
assert reg3_ok != reg1_ok
if reg3_ok:
data1 = yield dec2.e.read_reg3.data
- res[0] = sim.gpr(data1).value
+ res['a'] = sim.gpr(data1).value
elif reg1_ok:
data1 = yield dec2.e.read_reg1.data
- res[0] = sim.gpr(data1).value
+ res['a'] = sim.gpr(data1).value
- # If there's an immediate, set the B operand to that
reg2_ok = yield dec2.e.read_reg2.ok
if reg2_ok:
data2 = yield dec2.e.read_reg2.data
- res[1] = sim.gpr(data2).value
+ res['b'] = sim.gpr(data2).value
carry = 1 if sim.spr['XER'][XER_bits['CA']] else 0
carry32 = 1 if sim.spr['XER'][XER_bits['CA32']] else 0
- res[3] = carry | (carry32<<1)
+ res['xer_ca'] = carry | (carry32<<1)
so = 1 if sim.spr['XER'][XER_bits['SO']] else 0
- res[2] = so
+ res['xer_so'] = so
return res
def check_cu_outputs(self, res, dec2, sim, code):
+ """naming (res) must conform to ALUFunctionUnit output regspec
+ """
out_reg_valid = yield dec2.e.write_reg.ok
if out_reg_valid:
write_reg_idx = yield dec2.e.write_reg.data