What is Unintended latch?
A latch created by synthesis when a description intended as combinational logic fails to assign an output under some condition, so the value must be held.
Japanese name: 意図しないラッチ
A latch created by synthesis when a description intended as combinational logic fails to assign an output under some condition, so the value must be held.
Japanese name: 意図しないラッチ
The output of a combinational circuit is set by the present inputs and does not depend on earlier values. In 'always @(*) if (en) y = d;', however, nothing is specified for y when en is 0. In an HDL, a variable that is not assigned keeps its previous value. Keeping a value requires memory, so synthesis creates a latch. The result is a circuit that passes d while en is 1 and holds the value once en becomes 0. The same thing happens when a case statement leaves out some of the cases.
A latch responds to the level of a signal, not to a clock edge. While it is open, changes at its input pass straight to the output, so glitches at the input pass too. Timing analysis is also more complicated than for flip-flops. A latch the designer is unaware of tends to be left out of verification and test. Synthesis tools normally report the latches they create, so the log is worth checking.
The basic rule is that the output is assigned a value on every path through the block. An if gets an else, and a case gets a default branch. Assigning a default value to each output at the top of the block is another common method. A 2-bit sel has 4 possible values. If 3 of them are written and the fourth is not, the value has to be held for the remaining 1. Even with a default branch, an output forgotten in one branch becomes a latch. With always_comb in SystemVerilog, tools can issue a warning.
Answer: B. Assign default values to every output signal at the top of the block before the conditional logic
Putting defaults such as "y = 0; valid = 0;" at the top ensures every output is assigned at least its default on whatever path the later branches take, so nothing needs to hold its value and no latch forms. This is especially helpful for state machine outputs with many conditions. With SystemVerilog's always_comb, tools also warn if a latch is inferred.
No. In a block triggered by a clock edge, a signal that is not assigned is held by the flip-flop itself. The result is a flip-flop with an enable, which captures a new value when the condition is true.
Not when they are intended. They are used in practice, for example inside clock-gating cells. In SystemVerilog the intent can be stated by writing always_latch.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.