9b083a54564bf241a36fa419a227c813f6854559
1 # Proof of correctness for partitioned equal signal combiner
2 # Copyright (C) 2020 Michael Nolan <mtnolan2640@gmail.com>
5 * https://bugs.libre-soc.org/show_bug.cgi?id=340
8 from nmigen
import (Module
, Signal
, Elaboratable
, Mux
, Cat
, Repl
,
10 from nmigen
.asserts
import Assert
, AnyConst
, Assume
, Cover
11 from nmutil
.formaltest
import FHDLTestCase
12 from nmigen
.cli
import rtlil
14 from soc
.fu
.shift_rot
.main_stage
import ShiftRotMainStage
15 from soc
.fu
.alu
.pipe_data
import ALUPipeSpec
16 from soc
.fu
.alu
.alu_input_record
import CompALUOpSubset
17 from soc
.decoder
.power_enums
import InternalOp
21 # This defines a module to drive the device under test and assert
22 # properties about its outputs
23 class Driver(Elaboratable
):
28 def elaborate(self
, platform
):
32 rec
= CompALUOpSubset()
33 # Setup random inputs for dut.op
35 comb
+= p
.eq(AnyConst(p
.width
))
37 pspec
= ALUPipeSpec(id_wid
=2)
38 m
.submodules
.dut
= dut
= ShiftRotMainStage(pspec
)
40 # convenience variables
44 carry_in
= dut
.i
.xer_ca
[0]
45 carry_in32
= dut
.i
.xer_ca
[1]
46 carry_out
= dut
.o
.xer_ca
50 comb
+= [a
.eq(AnyConst(64)),
52 carry_in
.eq(AnyConst(1)),
53 carry_in32
.eq(AnyConst(1)),
56 comb
+= dut
.i
.ctx
.op
.eq(rec
)
58 # Assert that op gets copied from the input to output
59 for rec_sig
in rec
.ports():
61 dut_sig
= getattr(dut
.o
.ctx
.op
, name
)
62 comb
+= Assert(dut_sig
== rec_sig
)
64 # signed and signed/32 versions of input a
65 a_signed
= Signal(signed(64))
66 a_signed_32
= Signal(signed(32))
67 comb
+= a_signed
.eq(a
)
68 comb
+= a_signed_32
.eq(a
[0:32])
74 # main assertion of arithmetic operations
75 with m
.Switch(rec
.insn_type
):
77 with m
.Case(InternalOp
.OP_SHL
):
78 comb
+= Assume(ra
== 0)
79 with m
.If(rec
.is_32bit
):
80 comb
+= Assert(o
[0:32] == ((a
<< b
[0:6]) & 0xffffffff))
81 comb
+= Assert(o
[32:64] == 0)
83 comb
+= Assert(o
== ((a
<< b
[0:7]) & ((1 << 64)-1)))
85 with m
.Case(InternalOp
.OP_SHR
):
86 comb
+= Assume(ra
== 0)
87 with m
.If(~rec
.is_signed
):
88 with m
.If(rec
.is_32bit
):
89 comb
+= Assert(o
[0:32] == (a
[0:32] >> b
[0:6]))
90 comb
+= Assert(o
[32:64] == 0)
92 comb
+= Assert(o
== (a
>> b
[0:7]))
94 with m
.If(rec
.is_32bit
):
95 comb
+= Assert(o
[0:32] == (a_signed_32
>> b
[0:6]))
96 comb
+= Assert(o
[32:64] == Repl(a
[31], 32))
98 comb
+= Assert(o
== (a_signed
>> b
[0:7]))
100 with m
.Case(InternalOp
.OP_RLC
):
102 with m
.Case(InternalOp
.OP_RLCR
):
104 with m
.Case(InternalOp
.OP_RLCL
):
109 # check that data ok was only enabled when op actioned
110 comb
+= Assert(dut
.o
.o
.ok
== o_ok
)
115 class ALUTestCase(FHDLTestCase
):
116 def test_formal(self
):
118 self
.assertFormal(module
, mode
="bmc", depth
=2)
119 self
.assertFormal(module
, mode
="cover", depth
=2)
120 def test_ilang(self
):
122 vl
= rtlil
.convert(dut
, ports
=[])
123 with
open("main_stage.il", "w") as f
:
127 if __name__
== '__main__':