Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is inferred latch and how it is created when it is missing else statement in if condition. Can anybody explain briefly?

Tags:

verilog

I tried to figure out the inferred latch and why it is needed internally, but I couldn't find any resources with enough detail.

like image 447
user3429606 Avatar asked Mar 17 '14 16:03

user3429606


People also ask

What is inferred latch and how it is created?

A latch is inferred when the output of combinatorial logic has undefined states, that is it must hold its previous value. Combinatorial logic does not have any flip-flop to hold state therefore the output should always be defined by the inputs.

Why latch is inferred?

Latch inference refers to the condition whereby latches are inserted by synthesis tool to enable a signal to maintain its previous value. Inferring latches in a design is not desirable as it unnecessarily increases the size of the design. A bigger design will translate to a higher cost.

How does latch gets inferred in RTL design?

Latches are inferred in VHDL by using the IF statement without its matching ELSE. This causes the synthesis to make the logical decision to “hold” the value of a signal when not told to do anything else with it. The inferred latch is a transparent latch.

What causes latches to be created in the synthesized design?

Latches are created when you create a combinational process or conditional assignment (in VHDL) or a combinational always block (in Verilog) with an output that is not assigned under all possible input conditions. This creates what is known as incomplete assignment by the synthesis tools.


1 Answers

A latch is inferred when the output of combinatorial logic has undefined states, that is it must hold its previous value.

Combinatorial logic does not have any flip-flop to hold state therefore the output should always be defined by the inputs.

A short example might be:

always @* begin
  if (a == 1'b1) begin
    b =  x|y|z;
  end
end

What is b when a == 1'b0. b is not being overridden so it would hold its value. How can something hold its value when it does not have the concept of state. You have to introduce state by inferring a latch. This is normally a really bad thing.

You can imply latches and be carefull about the timing etc but inferred latches are nominally from buggy code.

like image 193
Morgan Avatar answered Sep 28 '22 16:09

Morgan