Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migen.genlib: Improve "first word fall through" docs. #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions migen/genlib/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class _FIFOInterface:
Bit width for the data.
depth : int
Depth of the FIFO.
fwft : bool (optional)
Enable the FIFO to have "first word fall through". The first
word written to an otherwise empty FIFO will be put on the
output without doing a read first.

Attributes
----------
Expand All @@ -48,7 +52,8 @@ class _FIFOInterface:
Acknowledge `dout`. If asserted, the next entry will be
available on the next cycle (if `readable` is high then).
"""
def __init__(self, width, depth):

def __init__(self, width, depth, fwft=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIFOInterface does not use fwft and therefore should not have this parameter.

self.we = Signal()
self.writable = Signal() # not full
self.re = Signal()
Expand Down Expand Up @@ -94,7 +99,7 @@ class SyncFIFO(Module, _FIFOInterface):
__doc__ = __doc__.format(interface=_FIFOInterface.__doc__)

def __init__(self, width, depth, fwft=True):
_FIFOInterface.__init__(self, width, depth)
_FIFOInterface.__init__(self, width, depth, fwft)

self.level = Signal(max=depth+1)
self.replace = Signal()
Expand Down Expand Up @@ -146,11 +151,18 @@ def __init__(self, width, depth, fwft=True):


class SyncFIFOBuffered(Module, _FIFOInterface):
"""Has an interface compatible with SyncFIFO with fwft=True,
but does not use asynchronous RAM reads that are not compatible
with block RAMs. Increases latency by one cycle."""
def __init__(self, width, depth):
_FIFOInterface.__init__(self, width, depth)
"""SyncFIFO compatible with "first word fall through" without using async memory.

The SyncFIFOBuffered has an interface compatible with SyncFIFO with
`fwft=True` but does not use asynchronous RAM reads that are not compatible
with block RAMs. Increases latency by one cycle.

This is useful for providing a SyncFIFO when the FPGA part doesn't provide
block ram with an asynchronous read port, like the Lattice iCE40 parts.
"""
def __init__(self, width, depth, fwft=True):
assert fwft, "fwft should be set, otherwise just use a SyncFIFO."
_FIFOInterface.__init__(self, width, depth, False)
self.submodules.fifo = fifo = SyncFIFO(width, depth, False)

self.writable = fifo.writable
Expand Down Expand Up @@ -182,8 +194,9 @@ class AsyncFIFO(Module, _FIFOInterface):
"""
__doc__ = __doc__.format(interface=_FIFOInterface.__doc__)

def __init__(self, width, depth):
_FIFOInterface.__init__(self, width, depth)
def __init__(self, width, depth, fwft=False):
assert not fwft, "fwft is not supported on the AsyncFIFO."
_FIFOInterface.__init__(self, width, depth, fwft=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This AsyncFIFO is always FWFT (in general there is no reason for an async FIFO not to be FWFT).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a sync FIFO it's either:

  • non-FWFT
  • asynchronous reads (lots of resources used, timing issues)
  • 2 cycles of latency instead of 1

The async FIFO does not have to make this compromise (the latency is already high enough from the CDC and hides the memory latency).


###

Expand Down Expand Up @@ -235,8 +248,8 @@ class AsyncFIFOBuffered(Module, _FIFOInterface):
"""Improves timing when it breaks due to sluggish clock-to-output
delay in e.g. Xilinx block RAMs. Increases latency by one cycle."""
def __init__(self, width, depth):
_FIFOInterface.__init__(self, width, depth)
self.submodules.fifo = fifo = AsyncFIFO(width, depth)
_FIFOInterface.__init__(self, width, depth, fwft=False)
self.submodules.fifo = fifo = AsyncFIFO(width, depth, fwft)

self.writable = fifo.writable
self.din = fifo.din
Expand Down