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
,
10 single_bit_flags
, get_signal_name
,
11 InternalOp
, major_opcodes
)
14 class DecoderTestCase(FHDLTestCase
):
15 def test_function_unit(self
):
19 function_unit
= Signal(Function
)
20 internal_op
= Signal(InternalOp
)
21 in1_sel
= Signal(In1Sel
)
22 in2_sel
= Signal(In2Sel
)
23 in3_sel
= Signal(In3Sel
)
24 out_sel
= Signal(OutSel
)
26 m
.submodules
.dut
= dut
= PowerMajorDecoder()
27 comb
+= [dut
.opcode_in
.eq(opcode
),
28 function_unit
.eq(dut
.function_unit
),
29 in1_sel
.eq(dut
.in1_sel
),
30 in2_sel
.eq(dut
.in2_sel
),
31 in3_sel
.eq(dut
.in3_sel
),
32 out_sel
.eq(dut
.out_sel
),
33 internal_op
.eq(dut
.internal_op
)]
38 for row
in major_opcodes
:
39 yield opcode
.eq(int(row
['opcode']))
41 result
= yield function_unit
42 expected
= Function
[row
['unit']].value
43 self
.assertEqual(expected
, result
)
45 result
= yield internal_op
46 expected
= InternalOp
[row
['internal op']].value
47 self
.assertEqual(expected
, result
)
49 result
= yield in1_sel
50 expected
= In1Sel
[row
['in1']].value
51 self
.assertEqual(expected
, result
)
53 result
= yield in2_sel
54 expected
= In2Sel
[row
['in2']].value
55 self
.assertEqual(expected
, result
)
57 result
= yield in3_sel
58 expected
= In3Sel
[row
['in3']].value
59 self
.assertEqual(expected
, result
)
61 result
= yield out_sel
62 expected
= OutSel
[row
['out']].value
63 self
.assertEqual(expected
, result
)
65 for bit
in single_bit_flags
:
66 sig
= getattr(dut
, get_signal_name(bit
))
68 expected
= int(row
[bit
])
69 self
.assertEqual(expected
, result
)
70 sim
.add_process(process
)
71 with sim
.write_vcd("test.vcd", "test.gtkw", traces
=[
72 opcode
, function_unit
, internal_op
,
77 dut
= PowerMajorDecoder()
78 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
79 with
open("power_major_decoder.il", "w") as f
:
83 if __name__
== "__main__":