Chisel3 - util - Valid

https://mp.weixin.qq.com/s/L5eAwv--WzZdr-CfW2-XNA

Chisel提供的Valid接口。如果valid为置1,则表明输出的bits有效;反之,则输出无效。

参考链接:

https://github.com/freechipsproject/chisel3/blob/master/src/main/scala/chisel3/util/Valid.scala

??

1. Valid是一组用户自定义的输入输出接口

类的声明如下:

class Valid[+T <: Data](gen: T) extends Bundle

类Valid是一个泛型类(generic class),参数类型为T。

首先,T <: Data 表明T在类型结构树(hierarchy)中为Data的子类,就是说传入的T需要是Data类的子类。

其次,+T 在Scala中成为协变(covariance), 意思是,Valid[ChildClassOfT]是Valid[T]的子类,即是Valid[T]的子类型关系,与参数类型T的子类型关系是一致的,所以叫协变。反过来就叫逆变(contravariance),还有个不变(invariance)。有兴趣可以了解一下,没兴趣略过即可。

Valid类继承自Bundle,表明自己是一个用户自定义的复合数据类型。

包含两个数据成员:

val valid = Output(Bool())

val bits = Output(gen)

很好理解,当valid置1时,bits输出有效;当valid置0时,bits输出无效。

2. object Valid提供一个创建Valid接口的工厂方法

Companion object Valid起到的作用是一个工厂方法,可以省略new的使用,直接创建一个valid对象:

val enq = Input(Valid(gen))

3. 附录

Valid.scala:

/** Wrappers for valid interfaces and associated circuit generators using them.
*/

package chisel3.util

import chisel3._
import chisel3.core.CompileOptions
import chisel3.experimental.DataMirror
import chisel3.internal.naming.chiselName // can‘t use chisel3_ version because of compile order

/** An Bundle containing data and a signal determining if it is valid */
class Valid[+T <: Data](gen: T) extends Bundle
{
val valid = Output(Bool())
val bits = Output(gen)
def fire(dummy: Int = 0): Bool = valid
override def cloneType: this.type = Valid(gen).asInstanceOf[this.type]
}

/** Adds a valid protocol to any interface */
object Valid {
def apply[T <: Data](gen: T): Valid[T] = new Valid(gen)
}

原文地址:https://www.cnblogs.com/wjcdx/p/10116955.html

时间: 2024-10-12 22:01:30

Chisel3 - util - Valid的相关文章

Chisel3 - util - Pipe

https://mp.weixin.qq.com/s/WeFesE8k0ORxlaNfLvDzgg 流水线,用于添加延迟. 参考链接: https://github.com/freechipsproject/chisel3/blob/master/src/main/scala/chisel3/util/Valid.scala ?? 1. Pipe object提供了三个工厂方法 ?? 最基本的方法签名如下: def apply[T <: Data](enqValid: Bool, enqBits

Chisel3 - util - RRArbiter

https://docs.qq.com/doc/DUWtwcWZlYm5DWG9n 循环优先级(Round Robin)仲裁器. 参考链接: https://github.com/freechipsproject/chisel3/blob/master/src/main/scala/chisel3/util/Arbiter.scala RRArbiter是一个仲裁器,只是使用RR的逻辑实现优先级.grant是优先级逻辑的结果,所以实现RRArbiter与严格优先级Arbiter的区别在于(仅在于

Chisel3 - Tutorial - Adder4

https://mp.weixin.qq.com/s/X5EStKor2DU0-vS_wIO-fg 四位加法器.通过FullAdder级联实现. 参考链接: https://github.com/ucb-bar/chisel-tutorial/blob/release/src/main/scala/examples/Adder4.scala 1. 引入Chisel3 ?? 2. 继承自Module类 ?? 3. 定义输入输出接口 ?? 创建输入和输出接口: 这些接口都是无符号整型数:val A

hadoop错误org.apache.hadoop.util.DiskChecker$DiskErrorException Could not find any valid local directory for

错误: org.apache.hadoop.util.DiskChecker$DiskErrorException: Could not find any valid local directory for 原因: 两种可能,hadoop.tmp.dir或者data目录存储空间不足 解决办法: 看了一下我的dfs状态,data使用率不到40%,所以推测是hadoop.tmp.dir空间不足,导致无法创建Jog临时文件.查看core-site.xml发现没有配置hadoop.tmp.dir,因此使

LeetCode:Valid Parentheses - 合理的括号搭配

1.题目名称 Valid Parentheses(合理的括号搭配) 2.题目地址 https://leetcode.com/problems/valid-parentheses/ 3.题目内容 英文:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the

LeetCode #20 Valid Parentheses (E)

[Problem] Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "

LeetCode算法01 Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]"

valid bank money number

一直对这种题比较没把握. 没有思路. i 1,000,000.22 34,333.999 define valid(String s,boolean last,boolean first) 1.先s.trim(); if string==null or string.length==0 return false; 2.String[] t = s.spite(','); 得到几组数. if(t.length()==1)   valid(t[0],t,t) else      for() 关于sp

hadoop报错:Does not contain a valid host:port authority

今天用sbin/start-yarn.sh启动yarn的时候,遇到下面的错误 java.lang.IllegalArgumentException: Does not contain a valid host:port authority: master at org.apache.hadoop.net.NetUtils.createSocketAddr(NetUtils.java:211) at org.apache.hadoop.net.NetUtils.createSocketAddr(N