What makes an inferred latch? how To avoid creating inferred latches? when do you know you need latches?

What makes an inferred latch?
For combinatorial logic, the output of the circuit is a function of input only and should not contain any memory or internal state (latch).

In Verilog, a variable will keep its previous value if it is not assigned a value in an always block. A latch must be created to store this present value.

An incomplete if-else statement will generate latches. An if-else statement is considered "incomplete" if the output state is not defined for all possible input conditions. The same goes for an incomplete case statement, or a case statement that does not have a default: item.

Why are inferred latches bad?
Inferred latches can serve as a ‘warning sign‘ that the logic design might not be implemented as intended. A crucial if-else or case statement might be missing from the design.

Latches can lead to timing issues and race conditions. They may lead to combinatorial feedback - routing of the output back to the input - which can be unpredictable.

To avoid creating inferred latches:

Include all the branches of an if or case statement
    Assign a value to every output signal in every branch
    Use default assignments at the start of the procedure, so every signal will be assigned.

Some parts paraphrased from "FPGA Prototyping by Verilog Examples" by P. Chu

when do you know you need latches?

Which, as you implied, is a subjective question. Expect more opinion than fact as answers. That being said, here is my opinion:

I, like you, often find better ways to use flip-flops thus avoiding latches. The resulting logic is often more elegant and robust. But there are times where I don‘t have enough control over the logic to avoid latches. For example, I might be interfacing to a processor bus that requires latches to meet the desired specifications. Since I can‘t redesign the CPU or the bus, I‘m stuck with the latch.

In the past 13+ years, that is the only time I have needed latches.

时间: 2024-10-22 18:27:55

What makes an inferred latch? how To avoid creating inferred latches? when do you know you need latches?的相关文章

Effective Java 英文 第二版 读书笔记 Item 5:Avoid creating unnecessary objects.

It is often appropriate to reuse a single object instead of creating a new functionally equivalent object each time it is needed.Reuse can be both faster and more stylish.An object can always be reused if it is immutable. String s=new String(“no”); 

Java之创建对象>5.Avoid creating unnecessary objects

String s = new String("stringette"); // DON'T DO THIS! The improved version is simply the following: String s = "stringette"; 根据生日来判断是否是婴儿潮时期出生的,isBabyBoomer()是一个糟糕的设计,每次调用这个方法都会创建Calendar,TimeZone以及2个Date对象实例,当此方法被频繁调用时将会非常地影响性能. publ

[Javascript] Avoid Creating floats if they are not needed

https://channel9.msdn.com/Series/Practical-Performance-Tips-to-Make-Your-HTMLJavaScript-Faster/06?WT.mc_id=13400-DEV-sitepoint-article24

latch: shared pool latch: library cache 诊断脚本(latchprofx.sql,latchprof.sql)

执行方式如下: @d:\latchprofx.sql  sid,name,laddr % cache 10000 @d:\latchprof.sql  sid,name,laddr % cache 10000 脚本出处:http://www.tanelpoder.com latchprofx.sql -------------------------------------------------------------------------------- -- -- File name: l

Python学习笔记——基础篇【第六周】——shutil模块

常用模块之shutil 高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length]) 将文件内容拷贝到另一个文件中,可以部分内容 1 def copyfileobj(fsrc, fdst, length=16*1024): 2 """copy data from file-like object fsrc to file-like object fdst""" 3 while 1: 4

Python学习第六天

模块: shutil 模块: 高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length])将文件内容拷贝到另一个文件中,可以部分内容 1 def copyfileobj(fsrc, fdst, length=16*1024): 2 """copy data from file-like object fsrc to file-like object fdst""" 3 while 1:

【python之旅】python的模块

一.定义模块: 模块:用来从逻辑上组织python代码(变量.函数.类.逻辑:实现一个功能),本质就是以.py结尾的python文件(文件名:test.py ,对应的模块名就是test) 包:用来从逻辑上组织模块的,本质就是一个目录(必须带有__init__.py的文件)二.导入方法: 1.import module_guyun 1 #命名为module_guyun.py 2 #需要导入的模块内容 3 #!/usr/bin/env python 4 # -*- coding: utf-8 -*-

Python shutil模块

高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length])将文件内容拷贝到另一个文件中,可以部分内容 1 def copyfileobj(fsrc, fdst, length=16*1024): 2 """copy data from file-like object fsrc to file-like object fdst""" 3 while 1: 4 buf = fsrc.re

Git for Windows v2.11.0 Release Notes

homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December 1st 2016 Introduction These release notes describe issues specific to the Git for Windows release. The release notes covering the history of the core