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

  • Logic Synthesis Glossary
  • Logic Synthesis Cheatsheet
  • Synthesis Foundations14
  • Logic Optimisation and Mapping20
  • Constraints and Timing15
  • Sequential, FSM and Memory19
    • Flops, Resets and Enables
    • FSM Synthesis
      • Coding Styles
      • State Encoding
      • Unreachable States
      • Output Registering
      • Yosys FSM Passes
    • Memory and Macro Inference
    • Retiming and Pipelining
  • Datapath Synthesis14
  • Area, Power and Test14
  • Verification, ECO and Handoff15
  • Flows and Debugging15
  • Interview and Judgment11
Loading lesson

‹FSM Synthesis
  1. Topics
  2. Logic Synthesis
  3. Sequential, FSM and Memory
  4. FSM Synthesis
  5. Yosys FSM Passes

Part 4 · Sequential, FSM and Memory · Intermediate

Yosys FSM Passes

How fsm_detect, fsm_extract and fsm_recode handle an FSM in Yosys.

On this page

    Detect, extract, recode

    Yosys handles an FSM in three named steps after elaboration. Detection only marks candidates; extraction packs one machine into one cell; recoding reassigns its state codes.

    Pass

    What it does

    What to check

    fsm_detect

    Marks state-register candidates from the clocked-register plus case pattern

    No visible change; unrecognised registers stay plain flops.

    fsm_extract

    Packs each detected machine into one $fsm cell

    Here: zero $fsm cells, so this machine was not recognised.

    fsm_recode

    Reassigns the state codes inside each $fsm cell

    Acts only on $fsm cells; with none present there is nothing to recode.

    fsm

    The meta pass: optimises and maps $fsm cells to flops and gates

    Here: nothing was extracted, so the design stays coarse; the assertions pin the 13-cell mix.

    Running the passes on one machine

    The script below runs a 4-state machine, written with a 2-bit binary code, through detection, extraction and recoding. Detection does not claim this machine: the script ends with zero $fsm cells, one 2-bit $dffe state register, and twelve combinational coarse cells.

    Its assertions pin that exact mix. The honest reading comes first: recognition is pattern-based and never guaranteed, so always assert the $fsm count before relying on recoding.

    yosys
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    read_verilog <<EOV
    module seq4 (
      input wire clk,
      input wire go,
      output reg ready
    );
      reg [1:0] state;
      reg [1:0] next;
      initial state = 2'b00;
      always @(posedge clk) state <= next;
      always @(*) begin
        next = state;
        ready = 1'b0;
        case (state)
          2'b00: begin if (go) next = 2'b01; end
          2'b01: begin next = 2'b10; end
          2'b10: begin next = 2'b11; end
          2'b11: begin ready = 1'b1; if (go) next = 2'b00; end
        endcase
      end
    endmodule
    EOV
    hierarchy -top seq4
    proc
    opt
    fsm_detect
    fsm_extract
    fsm_recode
    fsm
    select -assert-none t:$fsm
    select -assert-count 1 t:$dffe
    select -assert-count 3 t:$eq
    select -assert-count 2 t:$ne
    select -assert-count 2 t:$mux
    select -assert-count 2 t:$pmux
    select -assert-count 1 t:$logic_not
    select -assert-count 1 t:$reduce_and
    select -assert-count 1 t:$reduce_or
    log PASS: 4-state machine keeps a 2-bit coarse state flop and no $fsm cell

    Reading the result

    Zero $fsm cells mean the machine was not recognised as a unit. The state stayed in RTL-like form: one 2-bit $dffe plus comparators and multiplexers for the next-state logic.

    No generic flops appear because the script never runs techmap or the fine part of synthesis. Coarse cells ($dffe, $eq, $mux) exist only before that lowering, so asserting generic types at this stage finds nothing.

    Detect and extract stages with the pinned cell counts.
    Detection leaves this machine unpacked: one coarse state flop and twelve combinational cells, with no $fsm cell.

    Common mistakes

    Common pitfall

    Assuming detection always fires. Recognition is pattern-based, so an unrecognised machine stays as ordinary flops and gates; assert the $fsm count before relying on recoding. Also match the asserted cell family to the passes that ran: coarse types before techmap, generic types after.

    Interview

    Likely probes: what each pass contributes, and what the counts prove.

    • Detection marks, extraction packs into one cell, recoding reassigns codes, but only for recognised machines.

    • Zero $fsm cells plus one $dffe proves this machine stayed unpacked.

    • Assert the cell family each stage produces: coarse before mapping, generic after.

    Check yourself The script ends with zero $fsm cells and one $dffe. What does that say about detection and recoding?

    Detection did not claim the machine, so extraction produced no cell and recoding had no target. The state register stayed a plain coarse flop.

    Check yourself Why does the script assert coarse types like $dffe instead of generic $_DFF_P_?

    It never runs techmap, so lowering to generic flops never happens. The pinned mix is all coarse cells, and asserting a generic type there finds zero.

    Related topics

    • Up: FSM Synthesis

    • Coding styles

    • Equivalence Checking

    Previous

    61 / 139

    Next: Memory and Macro Inference

    Up next

    Up nextMemory and Macro Inference

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Coding Styles
    • State Encoding
    • Unreachable States