From: Luke Kenneth Casson Leighton Date: Fri, 15 Feb 2019 09:26:24 +0000 (+0000) Subject: add simulation test code X-Git-Tag: ls180-24jan2020~1986 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e5c82b7a6b4802ea22bddd2d9d26e04f9ba7aafa;p=ieee754fpu.git add simulation test code --- diff --git a/src/add/test_add.py b/src/add/test_add.py new file mode 100644 index 00000000..7769bb28 --- /dev/null +++ b/src/add/test_add.py @@ -0,0 +1,54 @@ +from nmigen import Module, Signal +from nmigen.compat.sim import run_simulation + +from nmigen_add_experiment import FPADD + +class ORGate: + def __init__(self): + self.a = Signal() + self.b = Signal() + self.x = Signal() + + def get_fragment(self, platform=None): + + m = Module() + m.d.comb += self.x.eq(self.a | self.b) + + return m + +def check_case(dut, a, b, x): + yield dut.in_a.eq(a) + yield dut.in_a_stb.eq(1) + yield + yield + a_ack = (yield dut.in_a_ack) + assert a_ack == 0 + yield dut.in_b.eq(b) + yield dut.in_b_stb.eq(1) + b_ack = (yield dut.in_b_ack) + assert b_ack == 0 + + while True: + yield + out_z_stb = (yield dut.out_z_stb) + if not out_z_stb: + continue + yield dut.in_a_stb.eq(0) + yield dut.in_b_stb.eq(0) + yield dut.out_z_ack.eq(1) + yield + yield dut.out_z_ack.eq(0) + yield + yield + break + +def testbench(dut): + yield from check_case(dut, 0, 0, 0) + yield from check_case(dut, 0x3F800000, 0x40000000, 0x40400000) + #yield from check_case(dut, 1, 0, 1) + #yield from check_case(dut, 1, 1, 1) + +if __name__ == '__main__': + dut = FPADD(width=32) + run_simulation(dut, testbench(dut), vcd_name="test_add.vcd") +