Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
    • SRAM and ROM
    • Register Files
    • Valid/Ready Handshake
    • AXI-Lite
    • AXI-Stream
    • Bus Integration
    • Synchronous FIFO
      • Contract and Invariants
      • Pointers, Occupancy and Flags
      • Portable Registered-Output FIFO
      • Simultaneous Push and Pop
      • Standard vs Fall-Through Output
      • Almost Flags and Parameter Edges
      • Verification and Signoff
    • Register-Map and CSR RTL
    • Memory Reliability
    • Peripheral RTL Integration
    • Full AXI4: RTL Roadmap
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹Synchronous FIFO
  1. Topics
  2. RTL Design
  3. Memory & Buses
  4. Synchronous FIFO
  5. Contract and Invariants

Part 7 · Memory & Buses · Intermediate

Contract and Invariants

Define what push, pop, full, empty, and output data mean before writing the storage array.

On this page

    Why this matters

    A FIFO that moves its pointers on a raw push or pop request, instead of an accepted one, overwrites unread data or returns words that were never written. Four invariants and one written contract prevent that.

    After this lesson you can: state the four FIFO invariants, define an accepted operation, and write the interface contract for the full and empty edges.

    Requests are not necessarily transactions

    push_i and pop_i are requests. A request changes FIFO state only when the corresponding operation is accepted.

    Event

    Conservative acceptance rule

    Effect

    Push

    push_i && !full_o

    Write one word and advance the write pointer.

    Pop

    pop_i && !empty_o

    Return one word and advance the read pointer.

    Both accepted

    Both guards are true

    Pointers both advance; occupancy is unchanged.

    Push while full

    Rejected

    No write and no write-pointer movement.

    Pop while empty

    Rejected

    No read and no read-pointer movement.

    External logic may raise requests at a boundary, but the FIFO must never overwrite unread data or return a word that was never written. Count accepted operations, not request levels.

    For the telemetry FIFO, a push observed at full is rejected even when a pop occurs on that edge. That conservative choice costs one slot opportunity but avoids depending on same-address memory collision behavior.

    The four invariants

    1. Conservation: occupancy equals accepted pushes minus accepted pops since reset.

    2. Bounds: occupancy is always between zero and DEPTH, inclusive.

    3. Ordering: accepted pop N returns accepted push N; no duplication, loss, or reordering.

    4. Pointer discipline: a pointer advances exactly once for its accepted operation and otherwise holds.

    Make the interface contract explicit

    Question

    This topic's baseline answer

    What happens to an illegal push or pop?

    It is ignored and may raise an error pulse or assertion in a stricter wrapper.

    Is output data combinational?

    No. The baseline has registered output data updated by an accepted pop.

    Can full accept a replacement push with a simultaneous pop?

    Not in the conservative baseline; an elastic variant is covered separately.

    Does reset clear memory?

    No. Reset clears pointers, occupancy, flags, and output-valid state; stale memory is unreachable while empty.

    Each slot is one clock cycle, numbered from 0. An operation takes effect at the edge that ends its slot, so occupancy and the pointers change one slot later.

    • Slots 0 and 1: only push_i is high. Occupancy climbs to 2 and wptr follows; rptr stays at 0.

    • Slots 2 and 3: push_i and pop_i are both high. Occupancy holds at 2, yet wptr and rptr both advance every cycle, and wptr wraps from 3 to 0. One word enters and one leaves, and the stream continues at one word per cycle.

    • Slot 4: a push alone lifts occupancy to 3 in slot 5.

    • Slot 5: a pop alone brings occupancy back to 2 in slot 6.

    Common pitfall

    Do not update pointers from raw push_i and pop_i. A push requested while full must not advance the write pointer, and a pop requested while empty must not advance the read pointer.

    Check yourself Occupancy is 5. Push and pop are both accepted on the same edge. What changes?

    Occupancy remains 5, but both pointers advance. One old word leaves and one new word enters; treating this as 'nothing happened' would corrupt ordering.

    Check yourself Why is clearing the memory array on reset unnecessary?

    Empty prevents all pre-reset words from being read. Clearing the array adds reset logic to every storage bit and can prevent SRAM inference; reset only the control state.

    Remember

    • Count accepted operations, not request levels. A push seen at full is rejected, even if a pop happens on the same edge.

    • Conservation, bounds, ordering and pointer discipline are the four invariants.

    • With push and pop together, occupancy holds but both pointers still advance.

    Rule of thumb: pointers and occupancy change on accepted operations only, never on raw requests.

    Keep going

    • Practice: Synchronous FIFO RTL design, blocking on full and empty

    • Code lab: Synchronous FIFO, 4 entries

    • Interview: run a mock interview on this topic

    Related topics

    • Pointers, occupancy and flags

    • Valid/ready acceptance rules

    Previous

    216 / 350

    Next: Pointers, Occupancy and Flags

    Up next

    Up nextPointers, Occupancy and Flags

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Portable Registered-Output FIFO
    • Simultaneous Push and Pop
    • Standard vs Fall-Through Output
    clkpush_ipop_iwptr012301rptr0123occupancy01232
    A depth-4 FIFO: a push and a pop in the same cycle keep occupancy flat while both pointers advance