# Copyright (C) Jonathan P Dawson 2013
# 2013-12-12
-from nmigen import Signal, Cat, Const, Mux, Module
+from nmigen import Signal, Cat, Const, Mux, Module, Elaboratable
from math import log
from operator import or_
from functools import reduce
+from singlepipe import PrevControl, NextControl
from pipeline import ObjectProxy
return res
-class FPNumBase:
+class FPNumBase: #(Elaboratable):
""" Floating-point Base Number Class
"""
def __init__(self, width, m_extra=True):
def _is_denormalised(self):
return (self.exp_n126) & (self.m_msbzero)
+ def __iter__(self):
+ yield self.s
+ yield self.e
+ yield self.m
+
def eq(self, inp):
return [self.s.eq(inp.s), self.e.eq(inp.e), self.m.eq(inp.m)]
return self.create2(s, self.N127, self.mzero)
-class MultiShiftRMerge:
+class MultiShiftRMerge(Elaboratable):
""" shifts down (right) and merges lower bits into m[0].
m[0] is the "sticky" bit, basically
"""
return m
-class FPNumShift(FPNumBase):
+class FPNumShift(FPNumBase, Elaboratable):
""" Floating-point Number Class for shifting
"""
def __init__(self, mainm, op, inv, width, m_extra=True):
self.m.eq(sm.lshift(self.m, maxslen))
]
-class Trigger:
+class Trigger(Elaboratable):
def __init__(self):
self.stb = Signal(reset=0)
return [self.stb, self.ack]
-class FPOp(Trigger):
+class FPOpIn(PrevControl):
def __init__(self, width):
- Trigger.__init__(self)
+ PrevControl.__init__(self)
self.width = width
- self.v = Signal(width)
+ @property
+ def v(self):
+ return self.data_i
def chain_inv(self, in_op, extra=None):
stb = in_op.stb
in_op.ack.eq(self.ack), # send ACK
]
- def eq(self, inp):
- return [self.v.eq(inp.v),
- self.stb.eq(inp.stb),
- self.ack.eq(inp.ack)
+
+class FPOpOut(NextControl):
+ def __init__(self, width):
+ NextControl.__init__(self)
+ self.width = width
+
+ @property
+ def v(self):
+ return self.data_o
+
+ def chain_inv(self, in_op, extra=None):
+ stb = in_op.stb
+ if extra is not None:
+ stb = stb & extra
+ return [self.v.eq(in_op.v), # receive value
+ self.stb.eq(stb), # receive STB
+ in_op.ack.eq(~self.ack), # send ACK
]
- def ports(self):
- return [self.v, self.stb, self.ack]
+ def chain_from(self, in_op, extra=None):
+ stb = in_op.stb
+ if extra is not None:
+ stb = stb & extra
+ return [self.v.eq(in_op.v), # receive value
+ self.stb.eq(stb), # receive STB
+ in_op.ack.eq(self.ack), # send ACK
+ ]
-class Overflow:
+class Overflow: #(Elaboratable):
def __init__(self):
self.guard = Signal(reset_less=True) # tot[2]
self.round_bit = Signal(reset_less=True) # tot[1]
self.roundz = Signal(reset_less=True)
+ def __iter__(self):
+ yield self.guard
+ yield self.round_bit
+ yield self.sticky
+ yield self.m0
+
def eq(self, inp):
return [self.guard.eq(inp.guard),
self.round_bit.eq(inp.round_bit),
"""
res = v.decode2(m)
ack = Signal()
- with m.If((op.ack) & (op.stb)):
+ with m.If((op.ready_o) & (op.valid_i_test)):
m.next = next_state
# op is latched in from FPNumIn class on same ack/stb
m.d.comb += ack.eq(0)
m.d.sync += [
out_z.v.eq(z.v)
]
- with m.If(out_z.stb & out_z.ack):
- m.d.sync += out_z.stb.eq(0)
+ with m.If(out_z.valid_o & out_z.ready_i_test):
+ m.d.sync += out_z.valid_o.eq(0)
m.next = next_state
with m.Else():
- m.d.sync += out_z.stb.eq(1)
+ m.d.sync += out_z.valid_o.eq(1)
class FPState(FPBase):