1 # Proof of correctness for trap pipeline, main stage
6 * https://bugs.libre-soc.org/show_bug.cgi?id=421
12 from nmigen
import Cat
, Const
, Elaboratable
, Module
13 from nmigen
.asserts
import Assert
, AnyConst
14 from nmigen
.cli
import rtlil
16 from nmutil
.formaltest
import FHDLTestCase
18 from soc
.decoder
.power_enums
import MicrOp
20 from soc
.fu
.trap
.main_stage
import TrapMainStage
21 from soc
.fu
.trap
.pipe_data
import TrapPipeSpec
24 def is_ok(sig
, value
):
26 Answers with a list of assertions that checks for valid data on
27 a pipeline stage output. sig.data must have the anticipated value,
28 and sig.ok must be asserted. The `value` is constrained to the width
29 of the sig.data field it's verified against, so it's safe to add, etc.
30 offsets to Nmigen signals without having to worry about inequalities from
31 differing signal widths.
34 Assert(sig
.data
== value
[0:len(sig
.data
)]),
39 def full_function_bits(msr
):
41 Answers with a numeric constant signal with all "full functional"
42 bits filled in, but all partial functional bits zeroed out.
44 See src/soc/fu/trap/main_stage.py:msr_copy commentary for details.
46 zeros16_21
= Const(0, (22 - 16))
47 zeros27_30
= Const(0, (31 - 27))
48 return Cat(msr
[0:16], zeros16_21
, msr
[22:27], zeros27_30
, msr
[31:64])
51 class Driver(Elaboratable
):
55 def elaborate(self
, platform
):
59 pspec
= TrapPipeSpec(id_wid
=2)
61 m
.submodules
.dut
= dut
= TrapMainStage(pspec
)
63 # frequently used aliases
67 with m
.Switch(op
.insn_type
):
68 with m
.Case(MicrOp
.OP_SC
):
70 is_ok(dut
.o
.nia
, Const(0xC00)),
71 is_ok(dut
.o
.srr0
, dut
.i
.cia
+ 4),
72 is_ok(dut
.o
.srr1
, full_function_bits(dut
.i
.msr
)),
75 comb
+= dut
.i
.ctx
.matches(dut
.o
.ctx
)
80 class TrapMainStageTestCase(FHDLTestCase
):
81 def test_formal(self
):
82 self
.assertFormal(Driver(), mode
="bmc", depth
=10)
83 self
.assertFormal(Driver(), mode
="cover", depth
=10)
86 vl
= rtlil
.convert(Driver(), ports
=[])
87 with
open("trap_main_stage.il", "w") as f
:
91 if __name__
== '__main__':