18d0d1d83c67a314d2870ac27faca4ab020ec821
1 # Proof of correctness for partitioned equal signal combiner
2 # Copyright (C) 2020 Michael Nolan <mtnolan2640@gmail.com>
4 from nmigen
import (Module
, Signal
, Elaboratable
, Mux
, Cat
, Repl
,
6 from nmigen
.asserts
import Assert
, AnyConst
, Assume
, Cover
7 from nmigen
.test
.utils
import FHDLTestCase
8 from nmigen
.cli
import rtlil
10 from soc
.fu
.cr
.main_stage
import CRMainStage
11 from soc
.fu
.alu
.pipe_data
import ALUPipeSpec
12 from soc
.fu
.alu
.alu_input_record
import CompALUOpSubset
13 from soc
.decoder
.power_enums
import InternalOp
17 # This defines a module to drive the device under test and assert
18 # properties about its outputs
19 class Driver(Elaboratable
):
24 def elaborate(self
, platform
):
28 rec
= CompALUOpSubset()
30 # Setup random inputs for dut.op
34 comb
+= p
.eq(AnyConst(width
))
36 pspec
= ALUPipeSpec(id_wid
=2, op_wid
=recwidth
)
37 m
.submodules
.dut
= dut
= CRMainStage(pspec
)
44 comb
+= [a
.eq(AnyConst(64)),
47 comb
+= dut
.i
.ctx
.op
.eq(rec
)
49 # Assert that op gets copied from the input to output
50 for rec_sig
in rec
.ports():
52 dut_sig
= getattr(dut
.o
.ctx
.op
, name
)
53 comb
+= Assert(dut_sig
== rec_sig
)
55 # big endian indexing. *sigh*
56 cr_arr
= Array([cr
[31-i
] for i
in range(32)])
57 cr_o_arr
= Array([cr_o
[31-i
] for i
in range(32)])
59 xl_fields
= dut
.fields
.FormXL
60 xfx_fields
= dut
.fields
.FormXFX
61 with m
.Switch(rec
.insn_type
):
62 with m
.Case(InternalOp
.OP_MTCRF
):
63 FXM
= xfx_fields
.FXM
[0:-1]
66 comb
+= Assert(cr_o
[4*i
:4*i
+4] == a
[4*i
:4*i
+4])
67 with m
.Case(InternalOp
.OP_CROP
):
68 bt
= Signal(xl_fields
.BT
[0:-1].shape(), reset_less
=True)
69 ba
= Signal(xl_fields
.BA
[0:-1].shape(), reset_less
=True)
70 bb
= Signal(xl_fields
.BB
[0:-1].shape(), reset_less
=True)
71 comb
+= bt
.eq(xl_fields
.BT
[0:-1])
72 comb
+= ba
.eq(xl_fields
.BA
[0:-1])
73 comb
+= bb
.eq(xl_fields
.BB
[0:-1])
78 comb
+= bit_a
.eq(cr_arr
[ba
])
79 comb
+= bit_b
.eq(cr_arr
[bb
])
80 comb
+= bit_o
.eq(cr_o_arr
[bt
])
83 comb
+= lut
.eq(rec
.insn
[6:10])
84 with m
.If(lut
== 0b1000):
85 comb
+= Assert(bit_o
== bit_a
& bit_b
)
86 with m
.If(lut
== 0b0100):
87 comb
+= Assert(bit_o
== bit_a
& ~bit_b
)
88 with m
.If(lut
== 0b1001):
89 comb
+= Assert(bit_o
== ~
(bit_a ^ bit_b
))
90 with m
.If(lut
== 0b0111):
91 comb
+= Assert(bit_o
== ~
(bit_a
& bit_b
))
92 with m
.If(lut
== 0b0001):
93 comb
+= Assert(bit_o
== ~
(bit_a | bit_b
))
94 with m
.If(lut
== 0b1110):
95 comb
+= Assert(bit_o
== bit_a | bit_b
)
96 with m
.If(lut
== 0b1101):
97 comb
+= Assert(bit_o
== bit_a | ~bit_b
)
98 with m
.If(lut
== 0b0110):
99 comb
+= Assert(bit_o
== bit_a ^ bit_b
)
104 class CRTestCase(FHDLTestCase
):
105 def test_formal(self
):
107 self
.assertFormal(module
, mode
="bmc", depth
=2)
108 def test_ilang(self
):
110 vl
= rtlil
.convert(dut
, ports
=[])
111 with
open("cr_main_stage.il", "w") as f
:
115 if __name__
== '__main__':