1 # Proof of correctness for SPR pipeline, main stage
6 * https://bugs.libre-soc.org/show_bug.cgi?id=418
9 from nmigen
import (Elaboratable
, Module
)
10 from nmigen
.asserts
import Assert
, AnyConst
, Assume
11 from nmigen
.cli
import rtlil
13 from nmutil
.formaltest
import FHDLTestCase
15 from soc
.fu
.spr
.main_stage
import SPRMainStage
16 from soc
.fu
.spr
.pipe_data
import SPRPipeSpec
17 from soc
.fu
.spr
.spr_input_record
import CompSPROpSubset
18 from soc
.decoder
.power_enums
import MicrOp
22 class Driver(Elaboratable
):
24 Defines a module to drive the device under test and assert properties
28 def elaborate(self
, platform
):
32 # cookie-cutting most of this from alu formal proof_main_stage.py
34 rec
= CompSPROpSubset()
35 # Setup random inputs for dut.op
38 comb
+= p
.eq(AnyConst(width
))
40 pspec
= SPRPipeSpec(id_wid
=2)
41 m
.submodules
.dut
= dut
= SPRMainStage(pspec
)
43 # convenience variables
45 ca_in
= dut
.i
.xer_ca
[0] # CA carry in
46 ca32_in
= dut
.i
.xer_ca
[1] # CA32 carry in 32
47 so_in
= dut
.i
.xer_so
# SO sticky overflow
49 ca_o
= dut
.o
.xer_ca
.data
[0] # CA carry out
50 ca32_o
= dut
.o
.xer_ca
.data
[1] # CA32 carry out32
51 ov_o
= dut
.o
.xer_ov
.data
[0] # OV overflow
52 ov32_o
= dut
.o
.xer_ov
.data
[1] # OV32 overflow32
56 comb
+= [a
.eq(AnyConst(64)),
57 ca_in
.eq(AnyConst(0b11)),
58 so_in
.eq(AnyConst(1))]
60 # and for the context muxid
61 width
= dut
.i
.ctx
.muxid
.width
62 comb
+= dut
.i
.ctx
.muxid
.eq(AnyConst(width
))
64 # assign the PowerDecode2 operation subset
65 comb
+= dut
.i
.ctx
.op
.eq(rec
)
67 # check that the operation (op) is passed through (and muxid)
68 comb
+= Assert(dut
.o
.ctx
.op
== dut
.i
.ctx
.op
)
69 comb
+= Assert(dut
.o
.ctx
.muxid
== dut
.i
.ctx
.muxid
)
74 class SPRMainStageTestCase(FHDLTestCase
):
75 #don't worry about it - tests are run manually anyway. fail is fine.
76 #@skipUnless(getenv("FORMAL_SPR"), "Exercise SPR formal tests [WIP]")
77 def test_formal(self
):
78 self
.assertFormal(Driver(), mode
="bmc", depth
=100)
79 self
.assertFormal(Driver(), mode
="cover", depth
=100)
82 vl
= rtlil
.convert(Driver(), ports
=[])
83 with
open("spr_main_stage.il", "w") as f
:
87 if __name__
== '__main__':