1 from nmigen
import Module
, Signal
, Elaboratable
2 from nmigen
.asserts
import Assert
, AnyConst
3 from nmigen
.test
.utils
import FHDLTestCase
5 from soc
.decoder
.power_decoder
import create_pdecode
, PowerOp
6 from soc
.decoder
.power_enums
import (In1Sel
, In2Sel
, In3Sel
,
9 from soc
.decoder
.power_decoder2
import (PowerDecode2
,
10 Decode2ToExecute1Type
)
13 class Driver(Elaboratable
):
18 def elaborate(self
, platform
):
20 self
.comb
= self
.m
.d
.comb
21 instruction
= Signal(32)
23 self
.comb
+= instruction
.eq(AnyConst(32))
25 pdecode
= create_pdecode()
27 self
.m
.submodules
.pdecode2
= pdecode2
= PowerDecode2(pdecode
)
28 self
.comb
+= pdecode2
.dec
.opcode_in
.eq(instruction
)
30 self
.test_in1(pdecode2
, pdecode
)
38 def test_in1(self
, pdecode2
, pdecode
):
42 with m
.If(pdecode
.op
.in1_sel
== In1Sel
.RA
):
43 comb
+= Assert(pdecode2
.e
.read_reg1
.data
== ra
)
44 comb
+= Assert(pdecode2
.e
.read_reg1
.ok
== 1)
45 with m
.If(pdecode
.op
.in1_sel
== In1Sel
.RA_OR_ZERO
):
47 comb
+= Assert(pdecode2
.e
.read_reg1
.ok
== 0)
49 comb
+= Assert(pdecode2
.e
.read_reg1
.data
== ra
)
50 comb
+= Assert(pdecode2
.e
.read_reg1
.ok
== 1)
51 op
= pdecode
.op
.internal_op
52 with m
.If((op
== InternalOp
.OP_BC
) |
53 (op
== InternalOp
.OP_BCREG
)):
54 with m
.If(~pdecode
.BO
[2]):
55 comb
+= Assert(pdecode2
.e
.read_spr1
.data
== SPR
.CTR
)
56 comb
+= Assert(pdecode2
.e
.read_spr1
.ok
== 1)
57 with m
.If((op
== InternalOp
.OP_MFSPR
) |
58 (op
== InternalOp
.OP_MTSPR
)):
59 comb
+= Assert(pdecode2
.e
.read_spr1
.data
==
61 comb
+= Assert(pdecode2
.e
.read_spr1
.ok
== 1)
66 pdecode2
= m
.submodules
.pdecode2
68 with m
.If(dec
.op
.in2_sel
== In2Sel
.RB
):
69 comb
+= Assert(pdecode2
.e
.read_reg2
.ok
== 1)
70 comb
+= Assert(pdecode2
.e
.read_reg2
.data
==
72 with m
.Elif(dec
.op
.in2_sel
== In2Sel
.NONE
):
73 comb
+= Assert(pdecode2
.e
.imm_data
.ok
== 0)
74 comb
+= Assert(pdecode2
.e
.read_reg2
.ok
== 0)
75 with m
.Elif(dec
.op
.in2_sel
== In2Sel
.SPR
):
76 comb
+= Assert(pdecode2
.e
.imm_data
.ok
== 0)
77 comb
+= Assert(pdecode2
.e
.read_reg2
.ok
== 0)
78 comb
+= Assert(pdecode2
.e
.read_spr2
.ok
== 1)
79 with m
.If(dec
.FormXL
.XO
[9]):
80 comb
+= Assert(pdecode2
.e
.read_spr2
.data
== SPR
.CTR
)
82 comb
+= Assert(pdecode2
.e
.read_spr2
.data
== SPR
.LR
)
84 comb
+= Assert(pdecode2
.e
.imm_data
.ok
== 1)
85 with m
.Switch(dec
.op
.in2_sel
):
86 with m
.Case(In2Sel
.CONST_UI
):
87 comb
+= Assert(pdecode2
.e
.imm_data
.data
== dec
.UI
[0:-1])
88 with m
.Case(In2Sel
.CONST_SI
):
89 comb
+= Assert(pdecode2
.e
.imm_data
.data
== dec
.SI
[0:-1])
90 with m
.Case(In2Sel
.CONST_UI_HI
):
91 comb
+= Assert(pdecode2
.e
.imm_data
.data
==
93 with m
.Case(In2Sel
.CONST_SI_HI
):
94 comb
+= Assert(pdecode2
.e
.imm_data
.data
==
96 with m
.Case(In2Sel
.CONST_LI
):
97 comb
+= Assert(pdecode2
.e
.imm_data
.data
==
99 with m
.Case(In2Sel
.CONST_BD
):
100 comb
+= Assert(pdecode2
.e
.imm_data
.data
==
102 with m
.Case(In2Sel
.CONST_DS
):
103 comb
+= Assert(pdecode2
.e
.imm_data
.data
==
105 with m
.Case(In2Sel
.CONST_M1
):
106 comb
+= Assert(pdecode2
.e
.imm_data
.data
== ~
0)
107 with m
.Case(In2Sel
.CONST_SH
):
108 comb
+= Assert(pdecode2
.e
.imm_data
.data
== dec
.sh
[0:-1])
109 with m
.Case(In2Sel
.CONST_SH32
):
110 comb
+= Assert(pdecode2
.e
.imm_data
.data
== dec
.SH32
[0:-1])
117 pdecode2
= m
.submodules
.pdecode2
118 with m
.If(pdecode2
.dec
.op
.in3_sel
== In3Sel
.RS
):
119 comb
+= Assert(pdecode2
.e
.read_reg3
.ok
== 1)
120 comb
+= Assert(pdecode2
.e
.read_reg3
.data
==
121 pdecode2
.dec
.RS
[0:-1])
126 pdecode2
= m
.submodules
.pdecode2
127 sel
= pdecode2
.dec
.op
.out_sel
129 with m
.If(sel
== OutSel
.SPR
):
130 comb
+= Assert(pdecode2
.e
.write_spr
.ok
== 1)
131 comb
+= Assert(pdecode2
.e
.write_reg
.ok
== 0)
132 with m
.Elif(sel
== OutSel
.NONE
):
133 comb
+= Assert(pdecode2
.e
.write_spr
.ok
== 0)
134 comb
+= Assert(pdecode2
.e
.write_reg
.ok
== 0)
136 comb
+= Assert(pdecode2
.e
.write_spr
.ok
== 0)
137 comb
+= Assert(pdecode2
.e
.write_reg
.ok
== 1)
138 data
= pdecode2
.e
.write_reg
.data
139 with m
.If(sel
== OutSel
.RT
):
140 comb
+= Assert(data
== dec
.RT
[0:-1])
141 with m
.If(sel
== OutSel
.RA
):
142 comb
+= Assert(data
== dec
.RA
[0:-1])
147 pdecode2
= m
.submodules
.pdecode2
148 sel
= pdecode2
.dec
.op
.rc_sel
150 comb
+= Assert(pdecode2
.e
.rc
.ok
== 1)
151 with m
.If(sel
== RC
.NONE
):
152 comb
+= Assert(pdecode2
.e
.rc
.data
== 0)
153 with m
.If(sel
== RC
.ONE
):
154 comb
+= Assert(pdecode2
.e
.rc
.data
== 1)
155 with m
.If(sel
== RC
.RC
):
156 comb
+= Assert(pdecode2
.e
.rc
.data
== dec
.Rc
[0:-1])
160 class Decoder2TestCase(FHDLTestCase
):
161 def test_decoder2(self
):
163 self
.assertFormal(module
, mode
="bmc", depth
=4)
165 if __name__
== '__main__':