Track 01 · SystemVerilog Primer

Data Types, logic, bit, and the Cost of an Unknown

~12 min Hands-on lab 1 exercise Verilator
Page 03 of 20
15%
01
Four State and Two State
SystemVerilog signals come in two families. A four state type can hold four values: zero, one, unknown, and high impedance. A two state type can hold only zero and one. The type logic is four state. The type bit is two state. That single difference — whether a signal can represent an unknown — drives almost every type decision you will make in verification.
02
Why logic Is the Verification Default
In verification you are hunting for bugs, and many bugs first appear as an unknown value: an uninitialised register, a bus nobody is driving, a reset that has not arrived yet. If your signal can hold an unknown, you can see that bug. If it cannot, the bug is invisible to you. That is why logic is the default type in a testbench: it tells you the truth, including the uncomfortable truth that something is unknown.
03
Why bit Exists — The Cost Tradeoff
If logic always tells the truth, why does bit exist at all? Speed. A two state type is cheaper to simulate, and on large, hot paths where a value genuinely can never be unknown — for example a loop counter you fully control — bit can make a simulation meaningfully faster. The tradeoff is real: bit buys performance by giving up the ability to represent an unknown. Use it only where you are certain no unknown can occur.
04
Key Insight — The Silent Mask
Here is the trap. If you declare a signal bit and an unknown is driven onto it, the unknown does not raise an error. It is silently coerced to a definite value, usually zero. Your test then passes, your waveform looks clean, and the real bug — an uninitialised value that should have been caught — sails straight through. A wrong type choice does not crash. It hides. That is what makes it dangerous, and it is exactly what this lab will show you.
Lab — Choose the Right Type for Each Signal

Each signal below has a job described in its comment. Declare each one as either logic or bit, choosing the type its job requires. Submit when you are ready. The checker verifies your type choices — because a wrong type choice does not crash, it hides.

Grading method: this lab checks your declared types. A signal declared bit where the job requires catching an unknown will receive a fail verdict, with the AI mentor explaining the real-world consequence.
Checking your types…
Pass
Correct. Your type choices let every unknown be seen where it mattered. The signals that needed to catch an unknown were declared four state, so nothing was hidden.
Type Mismatch — Unknown Hidden
Your code has the right structure, but a type choice hid an unknown. One of the signals that should have caught an unknown was declared two state, so the unknown would be silently turned into a known value and the bug it represented would disappear. The AI mentor below explains which one and why it matters.
Checker output
Compile Error
The checker found a syntax issue before it could evaluate your type choices. Resolve the error below and resubmit.
Checker output
Engine Error
Something went wrong on our end. Please try submitting again in a moment.
📲 Join 20K+ Engineers