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
  • Datapath Synthesis14
  • Area, Power and Test14
  • Verification, ECO and Handoff15
  • Flows and Debugging15
    • Scripted Flows and Regression
    • Debugging QoR
    • Simulation-Synthesis Mismatch
      • Sensitivity Lists and Races
      • Blocking and Non-Blocking Assignments
      • X Pessimism, Optimism, and Init
      • Case Priority and Wildcards
      • Directives, Widths, and Gate Simulation
  • Interview and Judgment11
Loading lesson

‹Simulation-Synthesis Mismatch
  1. Topics
  2. Logic Synthesis
  3. Flows and Debugging
  4. Simulation-Synthesis Mismatch
  5. Case Priority and Wildcards

Part 8 · Flows and Debugging · Intermediate

Case Priority and Wildcards

Overlapping case items, casez and casex wildcards, and promises the tool cannot check.

On this page

    Overlap means priority

    When two case items match, the first one in source order wins in simulation. Synthesis builds the same priority, so overlap is a priority encoder rather than parallel logic.

    A designer who assumed one-hot requests reads the overlap vector wrong. The table below fixes the reading for a two-request arbiter.

    {r1, r0}

    First match

    Grant

    One-hot reading

    00

    default

    none

    Idle, agrees

    01

    ?1

    g0

    Agrees

    10

    1?

    g1

    Agrees

    11

    1? first

    g1

    Expects both grants: the surprise

    casez and casex

    casez treats ? in the items as wildcards, which suits masked decodes. casex additionally treats x and z in the selector as wildcards, so an unknown selector can match an unintended item.

    Prefer plain case with a default, or casez with ? only in the items. Avoid casex in synthesizable code.

    Promises the tool trusts

    The sketch below is illustrative and not runnable: directive-style promises vary by flow, and the wording here is generic rather than a command of any tool.

    Diagram
    illustrative promise sketch (not runnable; spelling varies by flow)
    designer promise: exactly one request bit is ever high (one-hot)
    designer promise: the case covers every reachable selector (full case)
    gates built under a parallel promise drop the priority logic and the default arm
    simulation still shows first-match priority, so vector 11 is where the two views part

    If the one-hot promise is wrong even once, the gates answer vector 11 with parallel logic while simulation shows priority. Prove one-hot with an assertion instead of promising it in a comment.

    Demo and proof

    The testbench below builds the arbiter twice: once with a sensitivity bug plus overlapping items, once in the fixed priority form. It expects exactly two stale steps and one overlap surprise, and passes only on those counts.

    arb_fixed.sv
    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
    module arb_fixed (
      input logic r0,
      input logic r1,
      output logic g0,
      output logic g1
    );
      always_comb begin
        g0 = 1'b0;
        g1 = 1'b0;
        if (r1) g1 = 1'b1;
        else if (r0) g0 = 1'b1;
      end
    endmodule
    
    module arb_buggy (
      input logic r0,
      input logic r1,
      output logic g0,
      output logic g1
    );
      always @(r1) begin
        g0 = 1'b0;
        g1 = 1'b0;
        casez ({r1, r0})
          2'b1?: g1 = 1'b1;
          2'b?1: g0 = 1'b1;
          default: begin g0 = 1'b0; g1 = 1'b0; end
        endcase
      end
    endmodule
    

    The Yosys script proves the fixed point: the overlapping casez form is equivalent to the plain priority chain, so the chain is the intent the gates keep.

    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
    40
    read_verilog <<EOV
    module gold(r0, r1, g0, g1);
    input r0;
    input r1;
    output g0;
    output g1;
    reg g0;
    reg g1;
    always @* begin
    g0 = 1'b0;
    g1 = 1'b0;
    if (r1) g1 = 1'b1;
    else if (r0) g0 = 1'b1;
    end
    endmodule
    module gate(r0, r1, g0, g1);
    input r0;
    input r1;
    output g0;
    output g1;
    reg g0;
    reg g1;
    always @* begin
    g0 = 1'b0;
    g1 = 1'b0;
    casez ({r1, r0})
    2'b1?: g1 = 1'b1;
    2'b?1: g0 = 1'b1;
    default: begin g0 = 1'b0; g1 = 1'b0; end
    endcase
    end
    endmodule
    EOV
    hierarchy -check
    proc
    opt
    miter -equiv -flatten -make_outputs gold gate m
    hierarchy -top m
    sat -prove trigger 0 -verify m
    log PASS: overlapping casez matches the priority chain

    Common pitfall

    Reading vector 11 as both grants asserted is the one-hot assumption leaking in. The RTL grants g1 only, and the gates agree unless a parallel promise overrode them.

    Interview

    Likely probe: overlapping items plus a one-hot comment, then vector 11. Answer: first match wins in both views, so state the priority or prove the one-hot claim.

    Check yourself {r1, r0} reads 11 in the casez arbiter. Which grant issues, and why?

    g1. Item 1? matches first, so source order picks it; the second item never sees the vector.

    Check yourself What does the Yosys proof add that the testbench cannot?

    Proof that the casez form and the if-else chain are the same function on every input. The testbench only samples the vectors it runs.

    Related topics

    • Previous: X pessimism, optimism, and init

    • Next: Directives, widths, and gate simulation

    • Muxes, decoders and encoders

    Previous

    127 / 139

    Next: Directives, Widths, and Gate Simulation

    Up next

    Up nextDirectives, Widths, and Gate Simulation

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Sensitivity Lists and Races
    • Blocking and Non-Blocking Assignments