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
5 from nmigen
.asserts
import Assert
, AnyConst
, Assume
, Cover
6 from nmutil
.formaltest
import FHDLTestCase
7 from nmigen
.cli
import rtlil
9 from soc
.fu
.alu
.input_stage
import ALUInputStage
10 from soc
.fu
.alu
.pipe_data
import ALUPipeSpec
11 from soc
.fu
.alu
.alu_input_record
import CompALUOpSubset
12 from soc
.decoder
.power_enums
import MicrOp
16 # This defines a module to drive the device under test and assert
17 # properties about its outputs
18 class Driver(Elaboratable
):
23 def elaborate(self
, platform
):
27 rec
= CompALUOpSubset()
29 # Setup random inputs for dut.op
33 comb
+= p
.eq(AnyConst(width
))
35 pspec
= ALUPipeSpec(id_wid
=2)
36 m
.submodules
.dut
= dut
= ALUInputStage(pspec
)
40 comb
+= [dut
.i
.a
.eq(a
),
45 comb
+= dut
.i
.ctx
.op
.eq(rec
)
47 # Assert that op gets copied from the input to output
51 dut_sig
= getattr(dut
.o
.ctx
.op
, name
)
52 comb
+= Assert(dut_sig
== rec_sig
)
54 with m
.If(rec
.invert_a
):
55 comb
+= Assert(dut
.o
.a
== ~a
)
57 comb
+= Assert(dut
.o
.a
== a
)
59 with m
.If(rec
.imm_data
.imm_ok
&
60 ~
(rec
.insn_type
== MicrOp
.OP_RLC
)):
61 comb
+= Assert(dut
.o
.b
== rec
.imm_data
.imm
)
63 comb
+= Assert(dut
.o
.b
== b
)
68 class GTCombinerTestCase(FHDLTestCase
):
69 def test_formal(self
):
71 self
.assertFormal(module
, mode
="bmc", depth
=4)
72 self
.assertFormal(module
, mode
="cover", depth
=4)
75 vl
= rtlil
.convert(dut
, ports
=[])
76 with
open("input_stage.il", "w") as f
:
80 if __name__
== '__main__':