01 · Value systems and objects
Separate what a value can represent from how an object is driven.
The fastest route to correct SystemVerilog is to make two decisions independently: the value domain of the data and the object semantics of the name that carries it.
Two independent axes
Value domain is not object kind
- 014-state variablelogic
Stores 0, 1, X, or Z; normally one procedural owner.
- 024-state netwire logic
Carries resolved values from continuous or module drivers.
- 032-state variablebit
Stores binary values; assigning X/Z collapses diagnostic state.
- 042-state netwire bit
A resolved connection with a 2-state data type; contention information is coerced at the declared boundary.
Stores 0, 1, X, or Z; normally one procedural owner.
- int
- 32-bit · 2-state
- A compact simulation value when X/Z observability is not required.
- integer
- 32-bit · 4-state
- A legacy 4-state integral type; it is not an alias for int.
- logic
- 4-state variable type
- Object context still determines whether the declaration is a net or variable.
Read declarations in two passes: first the data type and value domain, then the object kind and driver model.
Observe
List the values that must remain observable, the number of drivers, and whether resolution is part of the interface contract.
Decide
Use 4-state logic where X/Z exposes initialization, contention, or tri-state behavior; use 2-state types where those states are intentionally collapsed.
Failure
A 2-state conversion can hide an X, while a variable with multiple procedural writers creates an ownership error rather than net resolution.
Prove
Lint driver ownership, assert knownness at protocol boundaries, and test conversions with 0, 1, X, and Z—not only nominal binary values.
The four-state model is diagnostic information
X can mean uninitialized, conflicting, unknown, or intentionally pessimistic data; Z represents high impedance on resolved connectivity. Those meanings are valuable at control and interface boundaries. A 2-state assignment cannot preserve them, so conversion is a deliberate loss of information.
| Type | Width | States | Default signedness | Typical use |
|---|---|---|---|---|
| bit | user-shaped | 2 | unsigned | Compact models and flags |
| logic / reg | user-shaped | 4 | unsigned | RTL state and observability |
| byte | 8 | 2 | signed | Characters and small arithmetic |
| shortint | 16 | 2 | signed | Compact arithmetic |
| int | 32 | 2 | signed | Loop variables and models |
| integer | 32 | 4 | signed | Legacy 4-state arithmetic |
| longint | 64 | 2 | signed | Wide arithmetic |
Nets resolve; variables retain
A net represents connectivity and may combine multiple drivers according to its net type. A variable stores the last assignment and should have a clear writer. In ports, spell out both object and data type when ambiguity would affect ownership.
- Use wire logic for an explicitly four-state net and logic for a procedurally assigned variable.
- Continuous assignments and module outputs naturally drive nets; procedural blocks assign variables.
- wand and wor encode wired resolution, but ordinary datapaths should not rely on accidental multi-driver resolution.
- Treat signedness as part of the interface: unsized literals and mixed signed expressions can change extension and comparison behavior.
wire logic resolved_irq;
logic sampled_irq;
bit model_enable;
assign resolved_irq = irq_a;
assign resolved_irq = irq_b; // net resolution is intentional
always_ff @(posedge clk) begin
sampled_irq <= resolved_irq; // one procedural owner
end
assert property (@(posedge clk) model_enable |-> !$isunknown(sampled_irq));Explain it out loud
Interview reasoning checkpoints
No. logic is a four-state variable data type. A declaration can still be a net or a variable depending on syntax and context, and that object kind controls driving and resolution.
- Identify the data domain: four-state logic preserves X and Z.
- Identify the object: a net models connectivity; a variable models stored procedural state.
- Check ownership: multiple procedural writers are not made safe by changing reg to logic.
A strong answer separates data type from object kind and mentions driver ownership.
Saying “logic can always be driven from anywhere” ignores port defaults, continuous drivers, and single-writer intent.
Both are 32-bit signed integral types, but int is 2-state and integer is 4-state. Choose based on whether X/Z observability is part of the model.
- A four-state source assigned to int loses X/Z information.
- That loss may be useful for performance in a reference model but dangerous at a verification boundary.
- Use explicit casts and knownness assertions when crossing the domains.
The key distinction is state domain, not width or signedness.
Calling int four-state because logic is commonly used beside it.
