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

前端 未结 3 1477
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 18:26

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

3条回答
  •  借酒劲吻你
    2020-11-27 18:38

    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.

提交回复
热议问题