from soc.fu.cr.cr_input_record import CompCROpSubset
from soc.experiment.alu_hier import ALU, DummyALU
from soc.experiment.compalu_multi import MultiCompUnit
-from soc.decoder.power_enums import MicrOp
+from openpower.decoder.power_enums import MicrOp
from nmutil.gtkw import write_gtkw
from nmigen import Module, Signal
from nmigen.cli import rtlil
self.consumers.append(ResultConsumer(sim, dut, i))
def issue(self, src_i, op, expected, src_delays, dest_delays,
- inv_a=0, imm=0, imm_ok=0, zero_a=0,
+ inv_a=0, imm=0, imm_ok=0, zero_a=0, rc=0,
rdmaskn=None, wrmask=None):
"""Executes the issue operation"""
dut = self.dut
yield dut.oper_i.imm_data.ok.eq(imm_ok)
if hasattr(dut.oper_i, "zero_a"):
yield dut.oper_i.zero_a.eq(zero_a)
+ if hasattr(dut.oper_i, "rc"):
+ yield dut.oper_i.rc.rc.eq(rc)
if hasattr(dut, "rdmaskn"):
rdmaskn_bits = 0
for i in range(len(rdmaskn)):
yield self.dut.oper_i.imm_data.ok.eq(0)
if hasattr(dut.oper_i, "zero_a"):
yield self.dut.oper_i.zero_a.eq(0)
+ if hasattr(dut.oper_i, "rc"):
+ yield dut.oper_i.rc.rc.eq(0)
# wait for busy to be negated
yield Settle()
while (yield dut.busy_o):
# fall behind. But, by summing the following counts, the invariant is
# preserved.
if zero_a and not rdmaskn[0]:
- self.zero_a_count = self.zero_a_count + 1
+ self.zero_a_count += 1
if imm_ok and not rdmaskn[1]:
- self.imm_ok_count = self.imm_ok_count + 1
+ self.imm_ok_count += 1
for i in range(len(rdmaskn)):
if rdmaskn[i]:
- self.rdmaskn_count[i] = self.rdmaskn_count[i] + 1
+ self.rdmaskn_count[i] += 1
for i in range(len(wrmask)):
if wrmask[i]:
- self.wrmask_count[i] = self.wrmask_count[i] + 1
+ self.wrmask_count[i] += 1
# check that producers and consumers have the same count
# this assures that no data was left unused or was lost
# first, check special cases (zero_a and imm_ok)
def scoreboard_sim(op):
+ # the following tests cases have rc=0, so no CR output is expected
# zero (no) input operands test
# 0 + 8 = 8
- yield from op.issue([5, 2], MicrOp.OP_ADD, [8],
+ yield from op.issue([5, 2], MicrOp.OP_ADD, [8, 0],
zero_a=1, imm=8, imm_ok=1,
- src_delays=[0, 2], dest_delays=[0])
+ wrmask=[0, 1],
+ src_delays=[0, 2], dest_delays=[0, 0])
# 5 + 8 = 13
- yield from op.issue([5, 2], MicrOp.OP_ADD, [13],
+ yield from op.issue([5, 2], MicrOp.OP_ADD, [13, 0],
inv_a=0, imm=8, imm_ok=1,
- src_delays=[2, 0], dest_delays=[2])
+ wrmask=[0, 1],
+ src_delays=[2, 0], dest_delays=[2, 0])
# 5 + 2 = 7
- yield from op.issue([5, 2], MicrOp.OP_ADD, [7],
- src_delays=[1, 1], dest_delays=[1])
+ yield from op.issue([5, 2], MicrOp.OP_ADD, [7, 0],
+ wrmask=[0, 1],
+ src_delays=[1, 1], dest_delays=[1, 0])
# (-6) + 2 = (-4)
- yield from op.issue([5, 2], MicrOp.OP_ADD, [65532],
+ yield from op.issue([5, 2], MicrOp.OP_ADD, [65532, 0],
inv_a=1,
- src_delays=[1, 2], dest_delays=[0])
+ wrmask=[0, 1],
+ src_delays=[1, 2], dest_delays=[0, 0])
# 0 + 2 = 2
- yield from op.issue([5, 2], MicrOp.OP_ADD, [2],
+ yield from op.issue([5, 2], MicrOp.OP_ADD, [2, 0],
zero_a=1,
- src_delays=[2, 0], dest_delays=[1])
+ wrmask=[0, 1],
+ src_delays=[2, 0], dest_delays=[1, 0])
# test combinatorial zero-delay operation
- # In the test ALU, any operation other than ADD, MUL or SHR
+ # In the test ALU, any operation other than ADD, MUL, EXTS or SHR
# is zero-delay, and do a subtraction.
# 5 - 2 = 3
- yield from op.issue([5, 2], MicrOp.OP_NOP, [3],
- src_delays=[0, 1], dest_delays=[2])
+ yield from op.issue([5, 2], MicrOp.OP_CMP, [3, 0],
+ wrmask=[0, 1],
+ src_delays=[0, 1], dest_delays=[2, 0])
# test all combinations of masked input ports
- # 5 + 0 (masked) = 5
- yield from op.issue([5, 2], MicrOp.OP_ADD, [5],
- rdmaskn=[0, 1],
- src_delays=[2, 1], dest_delays=[0])
- # 0 (masked) + 2 = 2
- yield from op.issue([5, 2], MicrOp.OP_ADD, [2],
- rdmaskn=[1, 0],
- src_delays=[1, 2], dest_delays=[1])
- # 0 (masked) + 0 (masked) = 0
- yield from op.issue([5, 2], MicrOp.OP_ADD, [0],
- rdmaskn=[1, 1],
- src_delays=[1, 2], dest_delays=[1])
- # note: the current test ALU down not have any masked write operations
+ # NOP does not make any request nor response
+ yield from op.issue([5, 2], MicrOp.OP_NOP, [0, 0],
+ rdmaskn=[1, 1], wrmask=[1, 1],
+ src_delays=[1, 2], dest_delays=[1, 0])
+ # sign_extend(0x80) = 0xFF80
+ yield from op.issue([0x80, 2], MicrOp.OP_EXTS, [0xFF80, 0],
+ rdmaskn=[0, 1], wrmask=[0, 1],
+ src_delays=[2, 1], dest_delays=[0, 0])
+ # sign_extend(0x80) = 0xFF80
+ yield from op.issue([2, 0x80], MicrOp.OP_EXTSWSLI, [0xFF80, 0],
+ rdmaskn=[1, 0], wrmask=[0, 1],
+ src_delays=[1, 2], dest_delays=[1, 0])
+ # test with rc=1, so expect results on the CR output port
+ # 5 + 2 = 7
+ # 7 > 0 => CR = 0b100
+ yield from op.issue([5, 2], MicrOp.OP_ADD, [7, 0b100],
+ rc=1,
+ src_delays=[1, 1], dest_delays=[1, 0])
+ # sign_extend(0x80) = 0xFF80
+ # -128 < 0 => CR = 0b010
+ yield from op.issue([0x80, 2], MicrOp.OP_EXTS, [0xFF80, 0b010],
+ rc=1, rdmaskn=[0, 1],
+ src_delays=[2, 1], dest_delays=[0, 2])
+ # 5 - 5 = 0
+ # 0 == 0 => CR = 0b001
+ yield from op.issue([5, 2], MicrOp.OP_CMP, [0, 0b001],
+ imm=5, imm_ok=1, rc=1,
+ src_delays=[0, 1], dest_delays=[2, 1])
def test_compunit_fsm():
m = Module()
alu = ALU(16)
- dut = MultiCompUnit(16, alu, CompALUOpSubset)
+ dut = MultiCompUnit(16, alu, CompALUOpSubset, n_dst=2)
m.submodules.cu = dut
vl = rtlil.convert(dut, ports=dut.ports())
+ ('' if is_engine_pysim() else '[6:0]'),
{'display': 'insn_type'})]),
('operand 1 port', 'in', [
+ ('cu_rdmaskn_i[2:0]', {'bit': 2}),
('cu_rd__rel_o[2:0]', {'bit': 2}),
('cu_rd__go_i[2:0]', {'bit': 2}),
'src1_i[15:0]']),
('operand 2 port', 'in', [
+ ('cu_rdmaskn_i[2:0]', {'bit': 1}),
('cu_rd__rel_o[2:0]', {'bit': 1}),
('cu_rd__go_i[2:0]', {'bit': 1}),
'src2_i[15:0]']),
('operand 3 port', 'in', [
+ ('cu_rdmaskn_i[2:0]', {'bit': 0}),
('cu_rd__rel_o[2:0]', {'bit': 0}),
('cu_rd__go_i[2:0]', {'bit': 0}),
'src1_i[15:0]']),
('result port', 'out', [
- 'cu_wr__rel_o', 'cu_wr__go_i', 'dest1_o[15:0]']),
+ 'cu_wrmask_o', 'cu_wr__rel_o', 'cu_wr__go_i', 'dest1_o[15:0]']),
('alu', {'submodule': 'alu'}, [
('prev port', 'in', [
'oper_i_None__insn_type', 'i1[15:0]',
('oper_i_None__invert_in', {'display': 'invert_in'}),
('oper_i_None__imm_data__data[63:0]', {'display': 'data[63:0]'}),
('oper_i_None__imm_data__ok', {'display': 'imm_ok'}),
- ('oper_i_None__zero_a', {'display': 'zero_a'})]),
+ ('oper_i_None__zero_a', {'display': 'zero_a'}),
+ ('oper_i_None__rc__rc', {'display': 'rc'})]),
('operand 1 port', 'in', [
+ ('cu_rdmaskn_i[1:0]', {'bit': 1}),
('cu_rd__rel_o[1:0]', {'bit': 1}),
('cu_rd__go_i[1:0]', {'bit': 1}),
'src1_i[15:0]']),
('operand 2 port', 'in', [
+ ('cu_rdmaskn_i[1:0]', {'bit': 0}),
('cu_rd__rel_o[1:0]', {'bit': 0}),
('cu_rd__go_i[1:0]', {'bit': 0}),
'src2_i[15:0]']),
('result port', 'out', [
- 'cu_wr__rel_o', 'cu_wr__go_i', 'dest1_o[15:0]']),
+ ('cu_wrmask_o[1:0]', {'bit': 1}),
+ ('cu_wr__rel_o[1:0]', {'bit': 1}),
+ ('cu_wr__go_i[1:0]', {'bit': 1}),
+ 'dest1_o[15:0]']),
+ ('cr port', 'out', [
+ ('cu_wrmask_o[1:0]', {'bit': 0}),
+ ('cu_wr__rel_o[1:0]', {'bit': 0}),
+ ('cu_wr__go_i[1:0]', {'bit': 0}),
+ 'dest2_o[15:0]']),
('alu', {'submodule': 'alu'}, [
('prev port', 'in', [
'op__insn_type', 'op__invert_in', 'a[15:0]', 'b[15:0]',
'valid_i', 'ready_o']),
('next port', 'out', [
- 'alu_o[15:0]', 'valid_o', 'ready_i'])]),
+ 'alu_o[15:0]', 'valid_o', 'ready_i',
+ 'alu_o_ok', 'alu_cr_ok'])]),
('debug', {'module': 'top'},
['src1_count[7:0]', 'src2_count[7:0]', 'dest1_count[7:0]'])]
inspec = [('INT', 'a', '0:15'),
('INT', 'b', '0:15')]
- outspec = [('INT', 'o', '0:15')]
+ outspec = [('INT', 'o', '0:15'),
+ ('INT', 'cr', '0:15')]
regspec = (inspec, outspec)