X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fsoc%2Fsimple%2Ftest%2Ftest_core.py;h=b2c219da2c1825498553c357ea1d75d85c31bdd0;hb=575802fa56d7175ebbdc16bb5c493b556dab9c74;hp=da844e34332f14513236460e7e0863fc3e914ff1;hpb=96ddc2959d8ce96bf88cd53d7f9353add52fdedf;p=soc.git diff --git a/src/soc/simple/test/test_core.py b/src/soc/simple/test/test_core.py index da844e34..b2c219da 100644 --- a/src/soc/simple/test/test_core.py +++ b/src/soc/simple/test/test_core.py @@ -1,3 +1,9 @@ +"""simple core test + +related bugs: + + * https://bugs.libre-soc.org/show_bug.cgi?id=363 +""" from nmigen import Module, Signal, Cat from nmigen.back.pysim import Simulator, Delay, Settle from nmutil.formaltest import FHDLTestCase @@ -6,113 +12,190 @@ import unittest from soc.decoder.isa.caller import special_sprs from soc.decoder.power_decoder import create_pdecode from soc.decoder.power_decoder2 import PowerDecode2 +from soc.decoder.selectable_int import SelectableInt from soc.decoder.isa.all import ISA -from soc.decoder.power_enums import Function, XER_bits - +from soc.decoder.power_enums import SPR, spr_dict, Function, XER_bits +from soc.config.test.test_loadstore import TestMemPspec +from soc.config.endian import bigendian from soc.simple.core import NonProductionCore -from soc.experiment.compalu_multi import find_ok # hack +from soc.experiment.compalu_multi import find_ok # hack -# test with ALU data and Logical data -from soc.fu.alu.test.test_pipe_caller import TestCase, ALUTestCase, test_data -#from soc.fu.logical.test.test_pipe_caller import LogicalTestCase, test_data +from soc.fu.compunits.test.test_compunit import (setup_test_memory, + check_sim_memory) +# test with ALU data and Logical data +from soc.fu.alu.test.test_pipe_caller import ALUTestCase +from soc.fu.logical.test.test_pipe_caller import LogicalTestCase +from soc.fu.shift_rot.test.test_pipe_caller import ShiftRotTestCase +from soc.fu.cr.test.test_pipe_caller import CRTestCase +from soc.fu.branch.test.test_pipe_caller import BranchTestCase +from soc.fu.ldst.test.test_pipe_caller import LDSTTestCase +from soc.regfile.util import spr_to_fast_reg + + +def setup_regs(core, test): + + # set up INT regfile, "direct" write (bypass rd/write ports) + intregs = core.regs.int + for i in range(32): + yield intregs.regs[i].reg.eq(test.regs[i]) + + # set up CR regfile, "direct" write across all CRs + cr = test.cr + crregs = core.regs.cr + #cr = int('{:32b}'.format(cr)[::-1], 2) + print("cr reg", hex(cr)) + for i in range(8): + #j = 7-i + cri = (cr >> (i*4)) & 0xf + #cri = int('{:04b}'.format(cri)[::-1], 2) + print("cr reg", hex(cri), i, + crregs.regs[i].reg.shape()) + yield crregs.regs[i].reg.eq(cri) + + # set up XER. "direct" write (bypass rd/write ports) + xregs = core.regs.xer + print("sprs", test.sprs) + xer = None + if 'XER' in test.sprs: + xer = test.sprs['XER'] + if 1 in test.sprs: + xer = test.sprs[1] + if xer is not None: + if isinstance(xer, int): + xer = SelectableInt(xer, 64) + sobit = xer[XER_bits['SO']].value + yield xregs.regs[xregs.SO].reg.eq(sobit) + cabit = xer[XER_bits['CA']].value + ca32bit = xer[XER_bits['CA32']].value + yield xregs.regs[xregs.CA].reg.eq(Cat(cabit, ca32bit)) + ovbit = xer[XER_bits['OV']].value + ov32bit = xer[XER_bits['OV32']].value + yield xregs.regs[xregs.OV].reg.eq(Cat(ovbit, ov32bit)) + print("setting XER so %d ca %d ca32 %d ov %d ov32 %d" % + (sobit, cabit, ca32bit, ovbit, ov32bit)) + else: + yield xregs.regs[xregs.SO].reg.eq(0) + yield xregs.regs[xregs.OV].reg.eq(0) + yield xregs.regs[xregs.CA].reg.eq(0) + + # setting both fast and slow SPRs from test data + + fregs = core.regs.fast + sregs = core.regs.spr + for sprname, val in test.sprs.items(): + if isinstance(val, SelectableInt): + val = val.value + if isinstance(sprname, int): + sprname = spr_dict[sprname].SPR + if sprname == 'XER': + continue + fast = spr_to_fast_reg(sprname) + if fast is None: + # match behaviour of SPRMap in power_decoder2.py + for i, x in enumerate(SPR): + if sprname == x.name: + yield sregs[i].reg.eq(val) + print("setting slow SPR %d (%s) to %x" % + (i, sprname, val)) + else: + yield fregs.regs[fast].reg.eq(val) + print("setting fast reg %d (%s) to %x" % + (fast, sprname, val)) + + # allow changes to settle before reporting on XER + yield Settle() -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) - yield cu.src_i[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<