1 # Proof of correctness for FPCMP module
2 # Copyright (C) 2020 Michael Nolan <mtnolan2640@gmail.com>
4 from nmigen
import Module
, Signal
, Elaboratable
, Mux
5 from nmigen
.asserts
import Assert
, AnyConst
6 from nmigen
.test
.utils
import FHDLTestCase
8 from ieee754
.fpcommon
.fpbase
import FPNumDecode
, FPNumBaseRecord
9 from ieee754
.fpcmp
.fpcmp
import FPCMPPipeMod
10 from ieee754
.pipeline
import PipelineSpec
14 # This defines a module to drive the device under test and assert
15 # properties about its outputs
16 class FPCMPDriver(Elaboratable
):
17 def __init__(self
, pspec
):
21 def elaborate(self
, platform
):
23 width
= self
.pspec
.width
25 # setup the inputs and outputs of the DUT as anyconst
29 opc
= Signal(self
.pspec
.op_wid
)
30 muxid
= Signal(self
.pspec
.id_wid
)
31 m
.d
.comb
+= [a
.eq(AnyConst(width
)),
32 b
.eq(AnyConst(width
)),
33 opc
.eq(AnyConst(self
.pspec
.op_wid
)),
34 muxid
.eq(AnyConst(self
.pspec
.id_wid
))]
36 m
.submodules
.dut
= dut
= FPCMPPipeMod(self
.pspec
)
38 # Decode the inputs and outputs so they're easier to work with
39 a1
= FPNumBaseRecord(width
, False)
40 b1
= FPNumBaseRecord(width
, False)
41 z1
= FPNumBaseRecord(width
, False)
42 m
.submodules
.sc_decode_a
= a1
= FPNumDecode(None, a1
)
43 m
.submodules
.sc_decode_b
= b1
= FPNumDecode(None, b1
)
44 m
.submodules
.sc_decode_z
= z1
= FPNumDecode(None, z1
)
45 m
.d
.comb
+= [a1
.v
.eq(a
),
49 m
.d
.comb
+= Assert((z1
.v
== 0) |
(z1
.v
== 1))
53 with m
.If(a1
.is_zero
& b1
.is_zero
):
54 m
.d
.comb
+= a_lt_b
.eq(0)
55 with m
.Elif(a1
.s
!= b1
.s
):
56 m
.d
.comb
+= a_lt_b
.eq(a1
.s
> b1
.s
)
57 with m
.Elif(a1
.s
== 0):
58 m
.d
.comb
+= a_lt_b
.eq(a1
.v
[0:width
-1] < b1
.v
[0:width
-1])
60 m
.d
.comb
+= a_lt_b
.eq(a1
.v
[0:width
-1] > b1
.v
[0:width
-1])
63 m
.d
.comb
+= a_eq_b
.eq((a1
.v
== b1
.v
) |
(a1
.is_zero
& b1
.is_zero
))
66 with m
.If(a1
.is_nan | b1
.is_nan
):
67 m
.d
.comb
+= Assert(z1
.v
== 0)
71 m
.d
.comb
+= Assert((z1
.v
== a_eq_b
))
73 m
.d
.comb
+= Assert(z1
.v
== (a_lt_b
))
75 m
.d
.comb
+= Assert(z1
.v
== (a_lt_b | a_eq_b
))
80 # connect up the inputs and outputs.
81 m
.d
.comb
+= dut
.i
.a
.eq(a
)
82 m
.d
.comb
+= dut
.i
.b
.eq(b
)
83 m
.d
.comb
+= dut
.i
.ctx
.op
.eq(opc
)
84 m
.d
.comb
+= dut
.i
.muxid
.eq(muxid
)
85 m
.d
.comb
+= z
.eq(dut
.o
.z
)
93 class FPCMPTestCase(FHDLTestCase
):
95 for bits
in [32, 16, 64]:
96 module
= FPCMPDriver(PipelineSpec(bits
, 2, 2))
97 self
.assertFormal(module
, mode
="bmc", depth
=4)
100 if __name__
== '__main__':