{"id":4,"date":"2015-08-19T07:37:19","date_gmt":"2015-08-19T07:37:19","guid":{"rendered":"http:\/\/www.verilogpro.com\/?p=4"},"modified":"2022-06-27T00:44:49","modified_gmt":"2022-06-27T07:44:49","slug":"systemverilog-verilog-x-optimism","status":"publish","type":"post","link":"https:\/\/www.verilogpro.com\/systemverilog-verilog-x-optimism\/","title":{"rendered":"SystemVerilog and Verilog X Optimism – You May Not Be Simulating What You Think"},"content":{"rendered":"\n

Verilog and SystemVerilog define 4 different logic values for modeling hardware: 1, 0, X, and Z. 1 and 0 are obviously real logic levels that can exist in silicon. Z and X, however, are modeling abstractions: Z represents a high-impedance (an un-driven or tri-stated signal) state, while X represents an unknown or indeterminate logic value.<\/p>\n\n\n\n

X’s can be created intentionally or unintentionally. The most common occurrence of X is in uninitialized registers or memories; X is used to represent the unknown value of these memory elements prior to a reset. Other conditions that can generate X include signals that are being simultaneously driven to different logic values by different drivers, to indicate logic that is shutdown in low power simulations, out of range bit selects and array indices. Some designers assign X to signals to show that they are “don’t care” values, as a hint to the synthesis tool so it can assign either 1 or 0 to the signals during logic optimization. To aid debug, some designers also assign X to signals in code paths that are impossible to reach, causing the simulator to flag erroneous execution of these paths by corrupting signals to X. Intentionally assigning X to signals is a controversial practice, however, and may be flagged by linting tools.<\/p>\n\n\n\n

Verilog X optimism refers to how simulations may incorrectly exhibit determinate behaviour even when inputs to logic are X and have indeterminate value. It can be dangerous and can mask real RTL bugs.<\/p>\n\n\n\n

The first example of Verilog X optimism is a simple if…else<\/b> statement:<\/p>\n\n\n\n

always_ff @(posedge clk) begin\n  if (cond)\n    c <= a;\n  else\n    c <= b;\nend\n<\/pre>\n\n\n\n