457f89a1b32b31c499db0b1e2539a5ed772f7a77
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 comb
+= dut
.i
.ctx
.op
.eq(rec
)
62 # Assert that op gets copied from the input to output
63 for rec_sig
in rec
.ports():
65 dut_sig
= getattr(dut
.o
.ctx
.op
, name
)
66 comb
+= Assert(dut_sig
== rec_sig
)
71 class SPRMainStageTestCase(FHDLTestCase
):
72 #don't worry about it - tests are run manually anyway. fail is fine.
73 #@skipUnless(getenv("FORMAL_SPR"), "Exercise SPR formal tests [WIP]")
74 def test_formal(self
):
75 self
.assertFormal(Driver(), mode
="bmc", depth
=100)
76 self
.assertFormal(Driver(), mode
="cover", depth
=100)
79 vl
= rtlil
.convert(Driver(), ports
=[])
80 with
open("spr_main_stage.il", "w") as f
:
84 if __name__
== '__main__':