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

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
    • Reset Puzzles
    • Clock Gating & Clock Mux Puzzles
    • CDC Basics Puzzles
      • MTBF Of Two Flops Versus Three
      • Back-to-Back Events Through a Toggle Synchroniser
      • Why Gray Code Across Clock Domains
      • A Four-Phase Handshake For a Bus
      • Full or Not in a Gray-Coded FIFO
      • Valid Crossed, Data Did Not
    • Verifying CDC & Reset Puzzles
    • Clock, Reset & CDC Puzzles: Tricky Q&A
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←CDC Basics Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Clock, Reset & CDC Puzzles
  4. CDC Basics Puzzles
  5. Full or Not in a Gray-Coded FIFO
On this page

    VLSI DV Interview PuzzlesAll levels

    Full or Not in a Gray-Coded FIFO

    An 8-deep asynchronous FIFO uses 4-bit pointers (one extra wrap bit) kept in gray code. In the write domain the binary write pointer is 9 and the synchronised read pointer is the gray code of 1. Is the FIFO full, and what exact comparison do you write? If the read side has meanwhile moved to 2, is the flag wrong?

    Puzzle

    Difficulty: Hard · Puzzle 5 of 6 · Topic: CDC Basics Puzzles

    An 8-deep asynchronous FIFO uses 4-bit pointers (one extra wrap bit) kept in gray code. In the write domain the binary write pointer is 9 and the synchronised read pointer is the gray code of 1. Is the FIFO full, and what exact comparison do you write? If the read side has meanwhile moved to 2, is the flag wrong?

    Hint

    Full means the pointers differ by 8: the two top gray bits are inverted and the rest are equal.

    Step-by-step solution

    Diagram
    1) Gray of 9 (1001) is 1101; gray of 1 (0001) is 0001.
    2) Full means write is exactly one lap ahead: (w - r) mod 16 = 8. In gray code that is: wgray equals rgray with the top two bits inverted.
    3) rgray = 0001: inverting the top two bits gives 1101, which equals wgray. So the FIFO looks full: 9 - 1 = 8 entries.
    4) Empty is simply wgray == rgray (compared in the read domain with the synchronised write pointer).
    5) If the read pointer has really moved to 2, the true occupancy is 7: not full. But the write side only sees the old pointer, so its full flag stays on a little too long. That is conservative (a later write, never an overwrite), and it is the correct direction of error; the empty flag is conservative in the same way.

    Answer

    Answer: Yes, full: wgray 1101 equals rgray 0001 with its top two bits inverted. The compare holds for every one of the 256 pointer pairs (it matches (w - r) mod 16 == 8). If the read pointer has already moved to 2 the true occupancy is 7, so the flag is stale but safe: it can only delay a write, never allow an overflow.

    How this was checked

    Checked by running a model of the rule in a Python model. A Python model checks the gray-code full and empty tests against binary occupancy for every pointer pair.

    Why candidates get it wrong

    Comparing the gray pointers for plain equality to detect full (that is the empty test) or decoding them in the other domain. The one extra wrap bit is what tells full from empty; the top-two-bits-inverted compare is the gray-code form of 'one lap ahead'. Stale pointers err on the safe side by design.

    Interviewer follow-up

    Why can the FIFO depth not be 6? Model answer: gray code only changes one bit per step if the number of states is a power of two; with six states the wrap from the last state to the first changes several bits, so the pointer crossing is no longer safe.

    Related topics

    • Back to CDC Basics Puzzles

    • Clock, Reset & CDC Puzzles section

    Previous

    252 / 293

    Next: Valid Crossed, Data Did Not

    Up next

    Up nextValid Crossed, Data Did Not

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • MTBF Of Two Flops Versus Three
    • Back-to-Back Events Through a Toggle Synchroniser
    • Why Gray Code Across Clock Domains