1 """Computation Unit (aka "ALU Manager").
3 Manages a Pipeline or FSM, ensuring that the start and end time are 100%
4 monitored. At no time may the ALU proceed without this module notifying
5 the Dependency Matrices. At no time is a result production "abandoned".
6 This module blocks (indicates busy) starting from when it first receives
7 an opcode until it receives notification that
8 its result(s) have been successfully stored in the regfile(s)
10 Documented at http://libre-soc.org/3d_gpu/architecture/compunit
13 from soc
.experiment
.alu_fsm
import Shifter
, CompFSMOpSubset
14 from soc
.fu
.alu
.alu_input_record
import CompALUOpSubset
15 from soc
.fu
.cr
.cr_input_record
import CompCROpSubset
16 from soc
.experiment
.alu_hier
import ALU
, DummyALU
17 from soc
.experiment
.compalu_multi
import MultiCompUnit
18 from soc
.decoder
.power_enums
import MicrOp
19 from nmutil
.gtkw
import write_gtkw
20 from nmigen
import Module
, Signal
21 from nmigen
.cli
import rtlil
23 # NOTE: to use cxxsim, export NMIGEN_SIM_MODE=cxxsim from the shell
24 # Also, check out the cxxsim nmigen branch, and latest yosys from git
25 from nmutil
.sim_tmp_alternative
import (Simulator
, Settle
, is_engine_pysim
,
35 class OperandProducer
:
37 Produces an operand when requested by the Computation Unit
38 (`dut` parameter), using the `rel_o` / `go_i` handshake.
40 Attaches itself to the `dut` operand indexed by `op_index`.
42 Has a programmable delay between the assertion of `rel_o` and the
45 Data is presented only during the cycle in which `go_i` is active.
47 It adds itself as a passive process to the simulation (`sim` parameter).
48 Since it is passive, it will not hang the simulation, and does not need a
49 flag to terminate itself.
51 def __init__(self
, sim
, dut
, op_index
):
52 self
.count
= Signal(8, name
=f
"src{op_index + 1}_count")
53 """ transaction counter"""
54 # data and handshake signals from the DUT
55 self
.port
= dut
.src_i
[op_index
]
56 self
.go_i
= dut
.rd
.go_i
[op_index
]
57 self
.rel_o
= dut
.rd
.rel_o
[op_index
]
58 # transaction parameters, passed via signals
59 self
.delay
= Signal(8)
60 self
.data
= Signal
.like(self
.port
)
61 # add ourselves to the simulation process list
62 sim
.add_sync_process(self
._process
)
67 # Settle() is needed to give a quick response to
70 # wait for rel_o to become active
71 while not (yield self
.rel_o
):
74 # read the transaction parameters
75 delay
= (yield self
.delay
)
76 data
= (yield self
.data
)
77 # wait for `delay` cycles
78 for _
in range(delay
):
80 # activate go_i and present data, for one cycle
82 yield self
.port
.eq(data
)
83 yield self
.count
.eq(self
.count
+ 1)
88 def send(self
, data
, delay
):
90 Schedules the module to send some `data`, counting `delay` cycles after
91 `rel_i` becomes active.
93 To be called from the main test-bench process,
94 it returns in the same cycle.
96 Communication with the worker process is done by means of
97 combinatorial simulation-only signals.
100 yield self
.data
.eq(data
)
101 yield self
.delay
.eq(delay
)
104 class ResultConsumer
:
106 Consumes a result when requested by the Computation Unit
107 (`dut` parameter), using the `rel_o` / `go_i` handshake.
109 Attaches itself to the `dut` result indexed by `op_index`.
111 Has a programmable delay between the assertion of `rel_o` and the
114 Data is retrieved only during the cycle in which `go_i` is active.
116 It adds itself as a passive process to the simulation (`sim` parameter).
117 Since it is passive, it will not hang the simulation, and does not need a
118 flag to terminate itself.
120 def __init__(self
, sim
, dut
, op_index
):
121 self
.count
= Signal(8, name
=f
"dest{op_index + 1}_count")
122 """ transaction counter"""
123 # data and handshake signals from the DUT
124 self
.port
= dut
.dest
[op_index
]
125 self
.go_i
= dut
.wr
.go_i
[op_index
]
126 self
.rel_o
= dut
.wr
.rel_o
[op_index
]
127 # transaction parameters, passed via signals
128 self
.delay
= Signal(8)
129 self
.expected
= Signal
.like(self
.port
)
130 # add ourselves to the simulation process list
131 sim
.add_sync_process(self
._process
)
136 # Settle() is needed to give a quick response to
137 # the zero delay case
139 # wait for rel_o to become active
140 while not (yield self
.rel_o
):
143 # read the transaction parameters
144 delay
= (yield self
.delay
)
145 expected
= (yield self
.expected
)
146 # wait for `delay` cycles
147 for _
in range(delay
):
149 # activate go_i for one cycle
150 yield self
.go_i
.eq(1)
151 yield self
.count
.eq(self
.count
+ 1)
153 # check received data against the expected value
154 result
= (yield self
.port
)
155 assert result
== expected
,\
156 f
"expected {expected}, received {result}"
157 yield self
.go_i
.eq(0)
158 yield self
.port
.eq(0)
160 def receive(self
, expected
, delay
):
162 Schedules the module to receive some result,
163 counting `delay` cycles after `rel_i` becomes active.
164 As 'go_i' goes active, check the result with `expected`.
166 To be called from the main test-bench process,
167 it returns in the same cycle.
169 Communication with the worker process is done by means of
170 combinatorial simulation-only signals.
172 yield self
.expected
.eq(expected
)
173 yield self
.delay
.eq(delay
)
176 def op_sim(dut
, a
, b
, op
, inv_a
=0, imm
=0, imm_ok
=0, zero_a
=0):
177 yield dut
.issue_i
.eq(0)
179 yield dut
.src_i
[0].eq(a
)
180 yield dut
.src_i
[1].eq(b
)
181 yield dut
.oper_i
.insn_type
.eq(op
)
182 yield dut
.oper_i
.invert_in
.eq(inv_a
)
183 yield dut
.oper_i
.imm_data
.data
.eq(imm
)
184 yield dut
.oper_i
.imm_data
.ok
.eq(imm_ok
)
185 yield dut
.oper_i
.zero_a
.eq(zero_a
)
186 yield dut
.issue_i
.eq(1)
188 yield dut
.issue_i
.eq(0)
190 if not imm_ok
or not zero_a
:
191 yield dut
.rd
.go_i
.eq(0b11)
194 rd_rel_o
= yield dut
.rd
.rel_o
195 print("rd_rel", rd_rel_o
)
198 yield dut
.rd
.go_i
.eq(0)
202 if len(dut
.src_i
) == 3:
203 yield dut
.rd
.go_i
.eq(0b100)
206 rd_rel_o
= yield dut
.rd
.rel_o
207 print("rd_rel", rd_rel_o
)
210 yield dut
.rd
.go_i
.eq(0)
214 req_rel_o
= yield dut
.wr
.rel_o
215 result
= yield dut
.data_o
216 print("req_rel", req_rel_o
, result
)
218 req_rel_o
= yield dut
.wr
.rel_o
219 result
= yield dut
.data_o
220 print("req_rel", req_rel_o
, result
)
224 yield dut
.wr
.go_i
[0].eq(1)
226 result
= yield dut
.data_o
228 print("result", result
)
229 yield dut
.wr
.go_i
[0].eq(0)
234 def scoreboard_sim_fsm(dut
, producers
, consumers
):
236 # stores the operation count
239 def op_sim_fsm(a
, b
, direction
, expected
, delays
):
240 print("op_sim_fsm", a
, b
, direction
, expected
)
241 yield dut
.issue_i
.eq(0)
243 # forward data and delays to the producers and consumers
244 yield from producers
[0].send(a
, delays
[0])
245 yield from producers
[1].send(b
, delays
[1])
246 yield from consumers
[0].receive(expected
, delays
[2])
247 # submit operation, and assert issue_i for one cycle
248 yield dut
.oper_i
.sdir
.eq(direction
)
249 yield dut
.issue_i
.eq(1)
251 yield dut
.issue_i
.eq(0)
252 # wait for busy to be negated
254 while (yield dut
.busy_o
):
257 # update the operation count
259 op_count
= (op_count
+ 1) & 255
260 # check that producers and consumers have the same count
261 # this assures that no data was left unused or was lost
262 assert (yield producers
[0].count
) == op_count
263 assert (yield producers
[1].count
) == op_count
264 assert (yield consumers
[0].count
) == op_count
267 # operand 1 arrives immediately
268 # operand 2 arrives after operand 1
269 # write data is accepted immediately
270 yield from op_sim_fsm(13, 2, 1, 3, [0, 2, 0])
272 # operand 2 arrives immediately
273 # operand 1 arrives after operand 2
274 # write data is accepted after some delay
275 yield from op_sim_fsm(3, 4, 0, 48, [2, 0, 2])
277 # operands 1 and 2 arrive at the same time
278 # write data is accepted after some delay
279 yield from op_sim_fsm(21, 0, 0, 21, [1, 1, 1])
282 def scoreboard_sim_dummy(op
):
283 yield from op
.issue([5, 2, 0], MicrOp
.OP_NOP
, [5],
284 src_delays
=[0, 2, 1], dest_delays
=[0])
285 yield from op
.issue([9, 2, 0], MicrOp
.OP_NOP
, [9],
286 src_delays
=[2, 1, 0], dest_delays
=[2])
290 """ALU Operation issuer
292 Issues operations to the DUT"""
293 def __init__(self
, dut
, sim
):
295 self
.zero_a_count
= 0
296 self
.imm_ok_count
= 0
298 # create one operand producer for each input port
299 self
.producers
= list()
300 for i
in range(len(dut
.src_i
)):
301 self
.producers
.append(OperandProducer(sim
, dut
, i
))
302 # create one result consumer for each output port
303 self
.consumers
= list()
304 for i
in range(len(dut
.dest
)):
305 self
.consumers
.append(ResultConsumer(sim
, dut
, i
))
306 def issue(self
, src_i
, op
, expected
, src_delays
, dest_delays
,
307 inv_a
=0, imm
=0, imm_ok
=0, zero_a
=0):
308 """Executes the issue operation"""
310 producers
= self
.producers
311 consumers
= self
.consumers
312 yield dut
.issue_i
.eq(0)
314 # forward data and delays to the producers and consumers
315 # first, send special cases (with zero_a and/or imm_ok)
317 yield from producers
[0].send(src_i
[0], src_delays
[0])
319 yield from producers
[1].send(src_i
[1], src_delays
[1])
320 # then, send the rest (if any)
321 for i
in range(2, len(producers
)):
322 yield from producers
[i
].send(src_i
[i
], src_delays
[i
])
323 for i
in range(len(consumers
)):
324 yield from consumers
[i
].receive(expected
[i
], dest_delays
[i
])
325 # submit operation, and assert issue_i for one cycle
326 yield dut
.oper_i
.insn_type
.eq(op
)
327 if hasattr(dut
.oper_i
, "invert_in"):
328 yield dut
.oper_i
.invert_in
.eq(inv_a
)
329 if hasattr(dut
.oper_i
, "imm_data"):
330 yield dut
.oper_i
.imm_data
.data
.eq(imm
)
331 yield dut
.oper_i
.imm_data
.ok
.eq(imm_ok
)
332 if hasattr(dut
.oper_i
, "zero_a"):
333 yield dut
.oper_i
.zero_a
.eq(zero_a
)
334 yield dut
.issue_i
.eq(1)
336 yield dut
.issue_i
.eq(0)
337 # wait for busy to be negated
339 while (yield dut
.busy_o
):
342 # update the operation count
343 self
.op_count
= (self
.op_count
+ 1) & 255
344 # On zero_a and imm_ok executions, the producer counters will fall
345 # behind. But, by summing the following counts, the invariant is
348 self
.zero_a_count
= self
.zero_a_count
+ 1
350 self
.imm_ok_count
= self
.imm_ok_count
+ 1
351 # check that producers and consumers have the same count
352 # this assures that no data was left unused or was lost
353 # first, check special cases (zero_a and imm_ok)
354 assert (yield producers
[0].count
) + self
.zero_a_count
== self
.op_count
355 assert (yield producers
[1].count
) + self
.imm_ok_count
== self
.op_count
356 # then, check the rest (if any)
357 for i
in range(2, len(producers
)):
358 assert (yield producers
[i
].count
) == self
.op_count
359 for i
in range(len(consumers
)):
360 assert (yield consumers
[i
].count
) == self
.op_count
363 def scoreboard_sim(op
):
364 # zero (no) input operands test
366 yield from op
.issue([5, 2], MicrOp
.OP_ADD
, [8],
367 zero_a
=1, imm
=8, imm_ok
=1,
368 src_delays
=[0, 2], dest_delays
=[0])
370 yield from op
.issue([5, 2], MicrOp
.OP_ADD
, [13],
371 inv_a
=0, imm
=8, imm_ok
=1,
372 src_delays
=[2, 0], dest_delays
=[2])
374 yield from op
.issue([5, 2], MicrOp
.OP_ADD
, [7],
375 src_delays
=[1, 1], dest_delays
=[1])
377 yield from op
.issue([5, 2], MicrOp
.OP_ADD
, [65532],
379 src_delays
=[1, 2], dest_delays
=[0])
381 yield from op
.issue([5, 2], MicrOp
.OP_ADD
, [2],
383 src_delays
=[2, 0], dest_delays
=[1])
385 # test combinatorial zero-delay operation
386 # In the test ALU, any operation other than ADD, MUL or SHR
387 # is zero-delay, and do a subtraction.
389 yield from op
.issue([5, 2], MicrOp
.OP_NOP
, [3],
390 src_delays
=[0, 1], dest_delays
=[2])
393 def test_compunit_fsm():
394 top
= "top.cu" if is_engine_pysim() else "cu"
396 'in': {'color': 'orange'},
397 'out': {'color': 'yellow'},
401 ('operation port', {'color': 'red'}, [
402 'cu_issue_i', 'cu_busy_o',
403 {'comment': 'operation'},
404 'oper_i_None__sdir']),
405 ('operand 1 port', 'in', [
406 ('cu_rd__rel_o[1:0]', {'bit': 1}),
407 ('cu_rd__go_i[1:0]', {'bit': 1}),
409 ('operand 2 port', 'in', [
410 ('cu_rd__rel_o[1:0]', {'bit': 0}),
411 ('cu_rd__go_i[1:0]', {'bit': 0}),
413 ('result port', 'out', [
414 'cu_wr__rel_o', 'cu_wr__go_i', 'dest1_o[7:0]']),
415 ('alu', {'module': top
+'.alu'}, [
416 ('prev port', 'in', [
417 'op__sdir', 'p_data_i[7:0]', 'p_shift_i[7:0]',
418 'p_valid_i', 'p_ready_o']),
419 ('next port', 'out', [
420 'n_data_o[7:0]', 'n_valid_o', 'n_ready_i']),
422 ('debug', {'module': 'top'},
423 ['src1_count[7:0]', 'src2_count[7:0]', 'dest1_count[7:0]'])]
426 "test_compunit_fsm1.gtkw",
427 "test_compunit_fsm1.vcd",
433 dut
= MultiCompUnit(8, alu
, CompFSMOpSubset
)
434 m
.submodules
.cu
= dut
436 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
437 with
open("test_compunit_fsm1.il", "w") as f
:
443 # create one operand producer for each input port
444 prod_a
= OperandProducer(sim
, dut
, 0)
445 prod_b
= OperandProducer(sim
, dut
, 1)
446 # create an result consumer for the output port
447 cons
= ResultConsumer(sim
, dut
, 0)
448 sim
.add_sync_process(wrap(scoreboard_sim_fsm(dut
,
451 sim_writer
= sim
.write_vcd('test_compunit_fsm1.vcd',
452 traces
=[prod_a
.count
,
463 dut
= MultiCompUnit(16, alu
, CompALUOpSubset
)
464 m
.submodules
.cu
= dut
466 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
467 with
open("test_compunit1.il", "w") as f
:
473 # create an operation issuer
475 sim
.add_sync_process(wrap(scoreboard_sim(op
)))
476 sim_writer
= sim
.write_vcd('test_compunit1.vcd')
481 class CompUnitParallelTest
:
482 def __init__(self
, dut
):
485 # Operation cycle should not take longer than this:
486 self
.MAX_BUSY_WAIT
= 50
488 # Minimum duration in which issue_i will be kept inactive,
489 # during which busy_o must remain low.
490 self
.MIN_BUSY_LOW
= 5
492 # Number of cycles to stall until the assertion of go.
493 # One value, for each port. Can be zero, for no delay.
494 self
.RD_GO_DELAY
= [0, 3]
496 # store common data for the input operation of the processes
499 self
.inv_a
= self
.zero_a
= 0
500 self
.imm
= self
.imm_ok
= 0
501 self
.imm_control
= (0, 0)
502 self
.rdmaskn
= (0, 0)
504 self
.operands
= (0, 0)
506 # Indicates completion of the sub-processes
507 self
.rd_complete
= [False, False]
510 print("Begin parallel test.")
511 yield from self
.operation(5, 2, MicrOp
.OP_ADD
)
513 def operation(self
, a
, b
, op
, inv_a
=0, imm
=0, imm_ok
=0, zero_a
=0,
515 # store data for the operation
516 self
.operands
= (a
, b
)
522 self
.imm_control
= (zero_a
, imm_ok
)
523 self
.rdmaskn
= rdmaskn
525 # Initialize completion flags
526 self
.rd_complete
= [False, False]
528 # trigger operation cycle
529 yield from self
.issue()
531 # check that the sub-processes completed, before the busy_o cycle ended
532 for completion
in self
.rd_complete
:
536 # issue_i starts inactive
537 yield self
.dut
.issue_i
.eq(0)
539 for n
in range(self
.MIN_BUSY_LOW
):
541 # busy_o must remain inactive. It cannot rise on its own.
542 busy_o
= yield self
.dut
.busy_o
545 # activate issue_i to begin the operation cycle
546 yield self
.dut
.issue_i
.eq(1)
548 # at the same time, present the operation
549 yield self
.dut
.oper_i
.insn_type
.eq(self
.op
)
550 yield self
.dut
.oper_i
.invert_in
.eq(self
.inv_a
)
551 yield self
.dut
.oper_i
.imm_data
.data
.eq(self
.imm
)
552 yield self
.dut
.oper_i
.imm_data
.ok
.eq(self
.imm_ok
)
553 yield self
.dut
.oper_i
.zero_a
.eq(self
.zero_a
)
554 rdmaskn
= self
.rdmaskn
[0] |
(self
.rdmaskn
[1] << 1)
555 yield self
.dut
.rdmaskn
.eq(rdmaskn
)
557 # give one cycle for the CompUnit to latch the data
560 # busy_o must keep being low in this cycle, because issue_i was
561 # low on the previous cycle.
562 # It cannot rise on its own.
563 # Also, busy_o and issue_i must never be active at the same time, ever.
564 busy_o
= yield self
.dut
.busy_o
568 yield self
.dut
.issue_i
.eq(0)
570 # deactivate inputs along with issue_i, so we can be sure the data
571 # was latched at the correct cycle
572 # note: rdmaskn must be held, while busy_o is active
573 # TODO: deactivate rdmaskn when the busy_o cycle ends
574 yield self
.dut
.oper_i
.insn_type
.eq(0)
575 yield self
.dut
.oper_i
.invert_in
.eq(0)
576 yield self
.dut
.oper_i
.imm_data
.data
.eq(0)
577 yield self
.dut
.oper_i
.imm_data
.ok
.eq(0)
578 yield self
.dut
.oper_i
.zero_a
.eq(0)
581 # wait for busy_o to lower
582 # timeout after self.MAX_BUSY_WAIT cycles
583 for n
in range(self
.MAX_BUSY_WAIT
):
584 # sample busy_o in the current cycle
585 busy_o
= yield self
.dut
.busy_o
587 # operation cycle ends when busy_o becomes inactive
591 # if busy_o is still active, a timeout has occurred
592 # TODO: Uncomment this, once the test is complete:
596 print("If you are reading this, "
597 "it's because the above test failed, as expected,\n"
598 "with a timeout. It must pass, once the test is complete.")
601 print("If you are reading this, "
602 "it's because the above test unexpectedly passed.")
604 def rd(self
, rd_idx
):
605 # wait for issue_i to rise
607 issue_i
= yield self
.dut
.issue_i
610 # issue_i has not risen yet, so rd must keep low
611 rel
= yield self
.dut
.rd
.rel_o
[rd_idx
]
615 # we do not want rd to rise on an immediate operand
616 # if it is immediate, exit the process
617 # likewise, if the read mask is active
618 # TODO: don't exit the process, monitor rd instead to ensure it
619 # doesn't rise on its own
620 if self
.rdmaskn
[rd_idx
] or self
.imm_control
[rd_idx
]:
621 self
.rd_complete
[rd_idx
] = True
624 # issue_i has risen. rel must rise on the next cycle
625 rel
= yield self
.dut
.rd
.rel_o
[rd_idx
]
628 # stall for additional cycles. Check that rel doesn't fall on its own
629 for n
in range(self
.RD_GO_DELAY
[rd_idx
]):
631 rel
= yield self
.dut
.rd
.rel_o
[rd_idx
]
634 # Before asserting "go", make sure "rel" has risen.
635 # The use of Settle allows "go" to be set combinatorially,
636 # rising on the same cycle as "rel".
638 rel
= yield self
.dut
.rd
.rel_o
[rd_idx
]
641 # assert go for one cycle, passing along the operand value
642 yield self
.dut
.rd
.go_i
[rd_idx
].eq(1)
643 yield self
.dut
.src_i
[rd_idx
].eq(self
.operands
[rd_idx
])
644 # check that the operand was sent to the alu
645 # TODO: Properly check the alu protocol
647 alu_input
= yield self
.dut
.get_in(rd_idx
)
648 assert alu_input
== self
.operands
[rd_idx
]
651 # rel must keep high, since go was inactive in the last cycle
652 rel
= yield self
.dut
.rd
.rel_o
[rd_idx
]
655 # finish the go one-clock pulse
656 yield self
.dut
.rd
.go_i
[rd_idx
].eq(0)
657 yield self
.dut
.src_i
[rd_idx
].eq(0)
660 # rel must have gone low in response to go being high
661 # on the previous cycle
662 rel
= yield self
.dut
.rd
.rel_o
[rd_idx
]
665 self
.rd_complete
[rd_idx
] = True
667 # TODO: check that rel doesn't rise again until the end of the
670 def wr(self
, wr_idx
):
671 # monitor self.dut.wr.req[rd_idx] and sets dut.wr.go[idx] for one cycle
673 # TODO: also when dut.wr.go is set, check the output against the
674 # self.expected_o and assert. use dut.get_out(wr_idx) to do so.
676 def run_simulation(self
, vcd_name
):
678 m
.submodules
.cu
= self
.dut
682 sim
.add_sync_process(wrap(self
.driver()))
683 sim
.add_sync_process(wrap(self
.rd(0)))
684 sim
.add_sync_process(wrap(self
.rd(1)))
685 sim
.add_sync_process(wrap(self
.wr(0)))
686 sim_writer
= sim
.write_vcd(vcd_name
)
691 def test_compunit_regspec2_fsm():
693 inspec
= [('INT', 'data', '0:15'),
694 ('INT', 'shift', '0:15')]
695 outspec
= [('INT', 'data', '0:15')]
697 regspec
= (inspec
, outspec
)
701 dut
= MultiCompUnit(regspec
, alu
, CompFSMOpSubset
)
702 m
.submodules
.cu
= dut
707 # create one operand producer for each input port
708 prod_a
= OperandProducer(sim
, dut
, 0)
709 prod_b
= OperandProducer(sim
, dut
, 1)
710 # create an result consumer for the output port
711 cons
= ResultConsumer(sim
, dut
, 0)
712 sim
.add_sync_process(wrap(scoreboard_sim_fsm(dut
,
715 sim_writer
= sim
.write_vcd('test_compunit_regspec2_fsm.vcd',
716 traces
=[prod_a
.count
,
723 def test_compunit_regspec3():
726 'in': {'color': 'orange'},
727 'out': {'color': 'yellow'},
731 ('operation port', {'color': 'red'}, [
732 'cu_issue_i', 'cu_busy_o',
733 {'comment': 'operation'},
734 ('oper_i_None__insn_type', {'display': 'insn_type'})]),
735 ('operand 1 port', 'in', [
736 ('cu_rd__rel_o[2:0]', {'bit': 2}),
737 ('cu_rd__go_i[2:0]', {'bit': 2}),
739 ('operand 2 port', 'in', [
740 ('cu_rd__rel_o[2:0]', {'bit': 1}),
741 ('cu_rd__go_i[2:0]', {'bit': 1}),
743 ('operand 3 port', 'in', [
744 ('cu_rd__rel_o[2:0]', {'bit': 0}),
745 ('cu_rd__go_i[2:0]', {'bit': 0}),
747 ('result port', 'out', [
748 'cu_wr__rel_o', 'cu_wr__go_i', 'dest1_o[15:0]']),
749 ('alu', {'module': 'top.cu.alu'}, [
750 ('prev port', 'in', [
751 'oper_i_None__insn_type', 'i1[15:0]',
752 'valid_i', 'ready_o']),
753 ('next port', 'out', [
754 'alu_o[15:0]', 'valid_o', 'ready_i'])])]
756 write_gtkw("test_compunit_regspec3.gtkw",
757 "test_compunit_regspec3.vcd",
762 inspec
= [('INT', 'a', '0:15'),
763 ('INT', 'b', '0:15'),
764 ('INT', 'c', '0:15')]
765 outspec
= [('INT', 'o', '0:15')]
767 regspec
= (inspec
, outspec
)
771 dut
= MultiCompUnit(regspec
, alu
, CompCROpSubset
)
772 m
.submodules
.cu
= dut
777 # create an operation issuer
779 sim
.add_sync_process(wrap(scoreboard_sim_dummy(op
)))
780 sim_writer
= sim
.write_vcd('test_compunit_regspec3.vcd')
785 def test_compunit_regspec1():
788 'in': {'color': 'orange'},
789 'out': {'color': 'yellow'},
793 ('operation port', {'color': 'red'}, [
794 'cu_issue_i', 'cu_busy_o',
795 {'comment': 'operation'},
796 ('oper_i_None__insn_type', {'display': 'insn_type'}),
797 ('oper_i_None__invert_in', {'display': 'invert_in'}),
798 ('oper_i_None__imm_data__data[63:0]', {'display': 'data[63:0]'}),
799 ('oper_i_None__imm_data__ok', {'display': 'imm_ok'}),
800 ('oper_i_None__zero_a', {'display': 'zero_a'})]),
801 ('operand 1 port', 'in', [
802 ('cu_rd__rel_o[1:0]', {'bit': 1}),
803 ('cu_rd__go_i[1:0]', {'bit': 1}),
805 ('operand 2 port', 'in', [
806 ('cu_rd__rel_o[1:0]', {'bit': 0}),
807 ('cu_rd__go_i[1:0]', {'bit': 0}),
809 ('result port', 'out', [
810 'cu_wr__rel_o', 'cu_wr__go_i', 'dest1_o[15:0]']),
811 ('alu', {'module': 'top.cu.alu'}, [
812 ('prev port', 'in', [
813 'op__insn_type', 'op__invert_in', 'a[15:0]', 'b[15:0]',
814 'valid_i', 'ready_o']),
815 ('next port', 'out', [
816 'alu_o[15:0]', 'valid_o', 'ready_i'])]),
817 ('debug', {'module': 'top'},
818 ['src1_count[7:0]', 'src2_count[7:0]', 'dest1_count[7:0]'])]
820 write_gtkw("test_compunit_regspec1.gtkw",
821 "test_compunit_regspec1.vcd",
826 inspec
= [('INT', 'a', '0:15'),
827 ('INT', 'b', '0:15')]
828 outspec
= [('INT', 'o', '0:15')]
830 regspec
= (inspec
, outspec
)
834 dut
= MultiCompUnit(regspec
, alu
, CompALUOpSubset
)
835 m
.submodules
.cu
= dut
837 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
838 with
open("test_compunit_regspec1.il", "w") as f
:
844 # create an operation issuer
846 sim
.add_sync_process(wrap(scoreboard_sim(op
)))
847 sim_writer
= sim
.write_vcd('test_compunit_regspec1.vcd',
848 traces
=[op
.producers
[0].count
,
849 op
.producers
[1].count
,
850 op
.consumers
[0].count
])
854 test
= CompUnitParallelTest(dut
)
855 test
.run_simulation("test_compunit_parallel.vcd")
858 if __name__
== '__main__':
861 test_compunit_regspec1()
862 test_compunit_regspec2_fsm()
863 test_compunit_regspec3()