1 # FIXME: This file is on the pytest ignore list in pyproject.toml because it has borked imports
2 from random
import randint
3 from nmigen
import Module
, Signal
4 from nmigen
.compat
.sim
import run_simulation
6 from ieee754
.fpcommon
.fpbase
import FPNum
8 class FPNumModShiftMulti
:
9 def __init__(self
, width
):
11 self
.ediff
= Signal((self
.a
.e_width
, True))
13 def elaborate(self
, platform
=None):
16 #m.d.sync += self.a.decode(self.a.v)
17 m
.d
.sync
+= self
.a
.shift_down_multi(self
.ediff
)
21 def check_case(dut
, width
, e_width
, m
, e
, i
):
32 print (e
, bin(m
), out_e
, calc_e
, bin(out_m
), i
, ed
)
34 calc_m
= ((m
>> (i
+1)) << 1) |
(m
& 1)
39 assert out_e
== calc_e
, "Output e 0x%x != expected 0x%x" % (out_e
, calc_e
)
40 assert out_m
== calc_m
, "Output m 0x%x != expected 0x%x" % (out_m
, calc_m
)
43 m_width
= dut
.a
.m_width
44 e_width
= dut
.a
.e_width
47 m
= randint(0, (1<<m_width
)-1)
48 zeros
= randint(0, 31)
49 for i
in range(zeros
):
51 e
= randint(-e_max
, e_max
)
53 yield from check_case(dut
, m_width
, e_width
, m
, e
, i
)
55 if __name__
== '__main__':
56 dut
= FPNumModShiftMulti(width
=32)
57 run_simulation(dut
, testbench(dut
), vcd_name
="test_multishift.vcd")
59 #dut = MultiShiftModL(width=32)
60 #run_simulation(dut, testbench(dut), vcd_name="test_multishift.vcd")