def __init__(self, id_wid):
self.id_wid = id_wid
if self.id_wid:
- self.in_mid = Signal(width, reset_less)
- self.out_mid = Signal(width, reset_less)
+ self.in_mid = Signal(id_wid, reset_less=True)
+ self.out_mid = Signal(id_wid, reset_less=True)
else:
self.in_mid = None
self.out_mid = None
def idsync(self, m):
- if self.id_wid:
+ if self.id_wid is not None:
m.d.sync += self.out_mid.eq(self.in_mid)
m.d.comb += self.mod.in_b.copy(in_b)
#m.d.comb += self.out_z.v.eq(self.mod.out_z.v)
m.d.comb += self.out_do_z.eq(self.mod.out_do_z)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
m.submodules.denormalise = self.mod
m.d.comb += self.mod.in_a.copy(in_a)
m.d.comb += self.mod.in_b.copy(in_b)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
#m.d.comb += self.out_a.copy(self.mod.out_a)
#m.d.comb += self.out_b.copy(self.mod.out_b)
m.d.comb += self.exp_eq.eq(self.mod.exp_eq)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
m.submodules.align = self.mod
m.d.comb += self.mod.in_a.copy(in_a)
m.d.comb += self.mod.in_b.copy(in_b)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
m.submodules.add0 = self.mod
m.d.comb += self.mod.in_a.copy(in_a)
m.d.comb += self.mod.in_b.copy(in_b)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
m.d.sync += self.norm_stb.eq(0) # sets to zero when not in add1 state
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
m.d.comb += self.stb.eq(norm_stb)
m.d.sync += self.ack.eq(0) # sets to zero when not in normalise_1 state
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
m.d.comb += self.mod.in_z.copy(in_z)
m.d.comb += self.mod.in_roundz.eq(roundz)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
"""
m.submodules.corrections = self.mod
m.d.comb += self.mod.in_z.copy(in_z)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
"""
m.submodules.pack = self.mod
m.d.comb += self.mod.in_z.copy(in_z)
- if self.in_mid:
+ if self.in_mid is not None:
m.d.comb += self.in_mid.eq(in_mid)
def action(self, m):
self.out_mid = out_mid
def action(self, m):
+ if self.in_mid is not None:
+ m.d.sync += self.out_mid.eq(self.in_mid)
m.d.sync += [
self.out_z.v.eq(self.in_z.v)
]
with m.If(self.out_z.stb & self.out_z.ack):
- if self.in_mid:
- m.d.sync += self.out_mid.eq(self.in_mid)
m.d.sync += self.out_z.stb.eq(0)
m.next = "get_a"
with m.Else():
if __name__ == "__main__":
- alu = FPADD(width=32, single_cycle=True)
- main(alu, ports=alu.in_a.ports() + alu.in_b.ports() + alu.out_z.ports())
+ alu = FPADD(width=32, in_wid=5, single_cycle=True)
+ main(alu, ports=alu.in_a.ports() + \
+ alu.in_b.ports() + \
+ alu.out_z.ports() + \
+ [alu.in_mid, alu.out_mid])
# works... but don't use, just do "python fname.py convert -t v"
(x == y)
)
-def get_case(dut, a, b):
+def get_case(dut, a, b, mid):
+ yield dut.in_mid.eq(mid)
yield dut.in_a.v.eq(a)
yield dut.in_a.stb.eq(1)
yield
yield
continue
out_z = yield dut.out_z.v
+ out_mid = yield dut.out_mid
yield dut.out_z.ack.eq(0)
yield
break
- return out_z
+ return out_z, out_mid
-def check_case(dut, a, b, z):
- out_z = yield from get_case(dut, a, b)
+def check_case(dut, a, b, z, mid=None):
+ if mid is None:
+ mid = randint(0, 6)
+ out_z, out_mid = yield from get_case(dut, a, b, mid)
assert out_z == z, "Output z 0x%x not equal to expected 0x%x" % (out_z, z)
+ assert out_mid == mid, "Output mid 0x%x != expected 0x%x" % (out_mid, mid)
def run_test(dut, stimulus_a, stimulus_b, op):
expected_responses = []
actual_responses = []
for a, b in zip(stimulus_a, stimulus_b):
+ mid = randint(0, 6)
af = Float32.from_bits(a)
bf = Float32.from_bits(b)
z = op(af, bf)
- expected_responses.append(z.get_bits())
+ expected_responses.append((z.get_bits(), mid))
#print (af, bf, z)
- actual = yield from get_case(dut, a, b)
+ actual = yield from get_case(dut, a, b, mid)
actual_responses.append(actual)
if len(actual_responses) < len(expected_responses):
for expected, actual, a, b in zip(expected_responses, actual_responses,
stimulus_a, stimulus_b):
- passed = match(expected, actual)
+ passed = match(expected[0], actual[0])
+ if expected[1] != actual[1]: # check mid
+ print ("MID failed", expected[1], actual[1])
+ sys.exit(0)
if not passed: