如何使用 Chisel 中的另一个寄存器动态索引寄存器 [英] How to dynamically index into a register using another register in Chisel
问题描述
我正在为我被告知是一种漏斗移位器编写 Chisel 代码.基本上它获取大小为 m 位的输入并发送大小为 n 位的输出,其中 m 和 n 可以有任何关系.
I am writing Chisel code for what I am told to be a type of funnel shifter. Basically it gets inputs of size m bits and sends outputs of size n bits where m and n can have any relationship or not.
我将 m 位字保存在缓冲区中,然后需要动态索引缓冲区以获得 n 位.同样,对于写作,我必须在 n 而不是 m 的边界处写作,以免产生某种碎片.为此,我使用 read_pointer 和 write_pointer 寄存器.并且需要使用指针作为索引从缓冲区中选择位.
I am saving the m bit words in a buffer and then need to dynamically index into the buffer to get n bits. Similarly for writing, I must write at the boundary of n rather than m to not have a sort of fragmentation. For this I am using read_pointer and write_pointer registers.and need to select bits from the buffer using the pointers as indices.
但是 Chisel 不允许我使用一个寄存器作为另一个寄存器的索引值.我怎样才能做到这一点 ?代码如下 -
But Chisel is not allowing me to use a register as an index value into another register. How can I do this ? THe code is as -
when (io.pull && !(io.empty))
{
when ((buffer_rp +& out_word_size.U) <= (buffer_size-1).U ) // No wraparound
{
io.data_out := buffer (buffer_rp + (out_word_size - 1).U, buffer_rp)
}
.otherwise // Wraparound
{
}
}
我得到的错误信息是 -
The error message I get is -
cmd24.sc:87:重载的方法值适用于替代方案:(x: BigInt,y: BigInt)chisel3.UInt(x: Int,y: Int)chisel3.UInt不能应用于 (chisel3.UInt, chisel3.UInt)io.data_out := buffer (buffer_rp + (out_word_size - 1).U, buffer_rp)^编译失败
cmd24.sc:87: overloaded method value apply with alternatives: (x: BigInt,y: BigInt)chisel3.UInt (x: Int,y: Int)chisel3.UInt cannot be applied to (chisel3.UInt, chisel3.UInt) io.data_out := buffer (buffer_rp + (out_word_size - 1).U, buffer_rp) ^Compilation Failed
谢谢
推荐答案
Jack Koening 给了我一个
Jack Koening gave me a response for similar question some years ago.
您可以对结果进行动态移位和位提取:
You could dynamically shift and bit extract the result:
io.data_out := (buffer >> buffer_rp)(out_word_size - 1, 0)
这篇关于如何使用 Chisel 中的另一个寄存器动态索引寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!