1f8374d17bbbceebd362365475d70de3442e8dc6
1 from nmigen
import Module
, Signal
2 from nmigen
.back
.pysim
import Simulator
, Delay
3 from nmigen
.test
.utils
import FHDLTestCase
4 from nmigen
.cli
import rtlil
8 from power_major_decoder
import (PowerMajorDecoder
, Function
,
9 In1Sel
, In2Sel
, In3Sel
, OutSel
,
11 single_bit_flags
, get_signal_name
,
12 InternalOp
, major_opcodes
)
15 class DecoderTestCase(FHDLTestCase
):
16 def test_function_unit(self
):
20 function_unit
= Signal(Function
)
21 internal_op
= Signal(InternalOp
)
22 in1_sel
= Signal(In1Sel
)
23 in2_sel
= Signal(In2Sel
)
24 in3_sel
= Signal(In3Sel
)
25 out_sel
= Signal(OutSel
)
27 ldst_len
= Signal(LdstLen
)
28 cry_in
= Signal(CryIn
)
30 m
.submodules
.dut
= dut
= PowerMajorDecoder()
31 comb
+= [dut
.opcode_in
.eq(opcode
),
32 function_unit
.eq(dut
.function_unit
),
33 in1_sel
.eq(dut
.in1_sel
),
34 in2_sel
.eq(dut
.in2_sel
),
35 in3_sel
.eq(dut
.in3_sel
),
36 out_sel
.eq(dut
.out_sel
),
37 rc_sel
.eq(dut
.rc_sel
),
38 ldst_len
.eq(dut
.ldst_len
),
39 cry_in
.eq(dut
.cry_in
),
40 internal_op
.eq(dut
.internal_op
)]
45 for row
in major_opcodes
:
46 yield opcode
.eq(int(row
['opcode']))
48 signals
= [(function_unit
, Function
, 'unit'),
49 (internal_op
, InternalOp
, 'internal op'),
50 (in1_sel
, In1Sel
, 'in1'),
51 (in2_sel
, In2Sel
, 'in2'),
52 (in3_sel
, In3Sel
, 'in3'),
53 (out_sel
, OutSel
, 'out'),
55 (cry_in
, CryIn
, 'cry in'),
56 (ldst_len
, LdstLen
, 'ldst len')]
57 for sig
, enm
, name
in signals
:
59 expected
= enm
[row
[name
]]
60 msg
= f
"{sig.name} == {enm(result)}, expected: {expected}"
61 self
.assertEqual(enm(result
), expected
, msg
)
62 for bit
in single_bit_flags
:
63 sig
= getattr(dut
, get_signal_name(bit
))
65 expected
= int(row
[bit
])
66 msg
= f
"{sig.name} == {result}, expected: {expected}"
67 self
.assertEqual(expected
, result
, msg
)
68 sim
.add_process(process
)
69 with sim
.write_vcd("test.vcd", "test.gtkw", traces
=[
70 opcode
, function_unit
, internal_op
,
75 dut
= PowerMajorDecoder()
76 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
77 with
open("power_major_decoder.il", "w") as f
:
81 if __name__
== "__main__":