HDL & Verification
What is the difference between Verilog's equality operators "==" and "==="?
- A== yields X when the known bits alone cannot decide whether the operands match, while === compares X and Z literally as values and always yields 0 or 1
- B== and === behave identically
- C=== compares three values at once
Show answer and explanation
Answer: A. == yields X when the known bits alone cannot decide whether the operands match, while === compares X and Z literally as values and always yields 0 or 1
== behaves like a hardware comparator, so if X or Z bits in either operand leave it undecided whether the operands match, the result is X (unknown). === is called case equality and compares X as X and Z as Z literally, so a testbench can use it to check whether an output has become X. Real circuits cannot distinguish X or Z, so synthesis tools either reject === or treat it like ==. === is therefore mainly a testbench operator.
- A. Correct. === is used mainly in testbenches.
- B. They treat X and Z differently.
- C. It compares two values.