简体   繁体   English

如何在凿子中对寄存器的向量进行参数化

[英]How to Paramatrized vector of registers in chisel

I need an example on how to paramtrize Vector of registers in terms of bit-width and initial values which are not '0' and are different for each register. 我需要一个示例,说明如何根据位宽和初始值(不是0且每个寄存器都不同)对寄存器的Vector进行配置。

My use-case is a generic filter coefficients bank with some unique reset values to each, and off course an option to override values. 我的用例是一个通用滤波器系数库,每个滤波器系数库都有一些唯一的重置值,并且当然可以选择覆盖值。 I thought of something like the below code (not really sure how to write the iteration, so this is kind of pseudo): 我想到了类似下面的代码(不太确定如何编写迭代,所以有点伪):

class Coeffbank(bitWidth : UInt ,ncoeff : UInt, rstVal : Vec(SInt)) extends Module {
    // how do iterate through the reset vector ?? //
    val coeffs   = Vec.fill(ncoeff) {Reg(init = SInt(rstVal(i),width = bitwidth))
}

Also, when new'ing the above (instantiating this module how do I pass the list of reset value in the argument list? 另外,在对上面的内容进行初始化时(如何初始化此模块,我如何在参数列表中传递重置值列表?

Hoping to get some help on how to write it properly. 希望获得有关如何正确编写它的帮助。

The explanation should probably be a bit more thorough, but basically you need to create a Reg of Vec . 解释可能应该更全面一些,但是基本上您需要创建Reg of Vec Something like should do it: 应该采取以下措施:

val coeffs = RegInit(rstVal)

In this case, since you already have the Vec of reset values, you can just pass it to the Reg constructor. 在这种情况下,由于您已经具有重置值的Vec,因此可以将其传递给Reg构造函数。

I'm assuming that the size of rstVal is equal to ncoeff , otherwise you'll need to reduce the size of rstVal with something like rstVal.take(ncoeff) . 我假设rstVal的大小等于ncoeff ,否则您需要使用rstVal.take(ncoeff)类的东西来减小rstVal的大小。 Also note that I'm using RegInit which is the preferred way to create a register with a reset value. 还要注意,我使用的是RegInit ,这是使用复位值创建寄存器的首选方法。

Let's start with the easy case. 让我们从简单的案例开始。 This would be much easier if instead of a Vec of SInt s your rstVa l array was instead a scala collection ( Seq , Array , ...) of regular SInt. 如果您的rstVa l数组不是常规SInt的scala集合( SeqArray ,...),而不是SIntVec ,则这会容易得多。 When possible it is best to save generation of actual hardware until you directly need them. 在可能的情况下,最好保留实际硬件的生成,直到您直接需要它们为止。 If rstVal contains Int's. 如果rstVal包含Int。 Your code would become 您的代码将成为

 val newRstVals = VecInit(Seq.tabulate(ncoeff) { index => rstVals(index).S(bitWidth.W) })
 val reg = RegInit(newRstVals)

If you really need to pass in a Vec then the right approach is to create a separate type instance and use the two argument call to RegInit 如果您确实需要传递Vec,那么正确的方法是创建一个单独的类型实例,并使用对RegInit的两个参数调用

val vecType = Vec(ncoeff, SInt(bitWidth.W))
val newRstVals1 = VecInit(Seq.tabulate(ncoeff) { index => newRstVals(index) })
val reg = RegInit(vecType, newRstVals1)

There might be problems if the bitWidth you pass in is not big enough to contain the constants you have passed in. You probably should have some checks for that. 如果传入的bitWidth不足以容纳传入的常量,可能会出现问题。您可能应该对此进行一些检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM