CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Combinational Logic

Casex Danger

HardLogic CircuitAnalyze

Many digital design houses strictly ban the casex statement in their RTL coding guidelines. While intended to simplify pattern matching, casex introduces severe risks by masking uninitialized logic states during simulation that will ultimately fail in physical silicon.

The snippet below represents an address decoder using a casex statement to match a 4-bit addr input. The designer expects the default case to catch any unmapped addresses. During simulation, an upstream bug causes an uninitialized signal to feed into the lowest bit of addr, causing the expression to evaluate as 4'b101X. One of the valid case items in the block is written as 4'b1011.

Determine how the simulator and the synthesis tool interpret this input differently. Identify the resulting hardware mismatch and the correct alternative construct.

Constraints

  • Assume standard IEEE 1364 Verilog semantics for casex and casez.
  • Assume the synthesis tool, such as Yosys, optimizes away X and Z states as unreachable in physical hardware.
  • Physical hardware evaluates only to logic 0 or logic 1.

Topics

synthesisverilogsimulation-mismatchcoding-guidelines

Solve this problem

Place the gates, wire them up and watch the signals settle. Every submission runs on the same simulation engine that grades it.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Related problems

  • Binary to HexEasy
  • 1-to-4 Demultiplexer from AND and NOT GatesEasy
  • 2-to-4 Line Decoder with Active-High EnableEasy
  • Full Adder from Half AddersEasy
  • Odd Parity Bit Generator for 3-bit DataEasy
  • Hex Nibble to BinaryEasy
  • Extract Expression from a Two-Level AND-OR Circuit with Fan-OutEasy
  • The Two Zeros Problem in Sign-MagnitudeEasy

Browse all problems · Learning tracks