+def scoreboard_sim(dut, producers, consumers):
+
+ # stores the operation count
+ op_count = 0
+ zero_a_count = 0
+ imm_ok_count = 0
+
+ def op_sim_alu(a, b, op, expected, delays,
+ inv_a=0, imm=0, imm_ok=0, zero_a=0):
+ print("op_sim", a, b, op, expected)
+ yield dut.issue_i.eq(0)
+ yield
+ # forward data and delays to the producers and consumers
+ if not zero_a:
+ yield from producers[0].send(a, delays[0])
+ if not imm_ok:
+ yield from producers[1].send(b, delays[1])
+ yield from consumers[0].receive(expected, delays[2])
+ # submit operation, and assert issue_i for one cycle
+ yield dut.oper_i.insn_type.eq(op)
+ yield dut.oper_i.invert_in.eq(inv_a)
+ yield dut.oper_i.imm_data.data.eq(imm)
+ yield dut.oper_i.imm_data.ok.eq(imm_ok)
+ yield dut.oper_i.zero_a.eq(zero_a)
+ yield dut.issue_i.eq(1)
+ yield
+ yield dut.issue_i.eq(0)
+ # wait for busy to be negated
+ yield Settle()
+ while (yield dut.busy_o):
+ yield
+ yield Settle()
+ # update the operation count
+ nonlocal op_count, zero_a_count, imm_ok_count
+ op_count = (op_count + 1) & 255
+ # On zero_a and imm_ok executions, the producer counters will fall
+ # behind. But, by summing the following counts, the invariant is
+ # preserved.
+ if zero_a:
+ zero_a_count = zero_a_count + 1
+ if imm_ok:
+ imm_ok_count = imm_ok_count + 1
+ # check that producers and consumers have the same count
+ # this assures that no data was left unused or was lost
+ assert (yield producers[0].count) + zero_a_count == op_count
+ assert (yield producers[1].count) + imm_ok_count == op_count
+ assert (yield consumers[0].count) == op_count
+