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 cr_arr
= Array([cr
[i
] for i
in range(32)])
56 cr_o_arr
= Array([cr
[i
] for i
in range(32)])
58 with m
.Switch(rec
.insn_type
):
59 with m
.Case(InternalOp
.OP_MTCRF
):
60 xfx_fields
= dut
.fields
.FormXFX
61 FXM
= xfx_fields
.FXM
[0:-1]
64 comb
+= Assert(cr_o
[4*i
:4*i
+4] == a
[4*i
:4*i
+4])
68 class CRTestCase(FHDLTestCase
):
69 def test_formal(self
):
71 self
.assertFormal(module
, mode
="bmc", depth
=2)
74 vl
= rtlil
.convert(dut
, ports
=[])
75 with
open("cr_main_stage.il", "w") as f
:
79 if __name__
== '__main__':