gpt4 book ai didi

scala - Chisel 既不为 verilog 也不为 C++ 合成

转载 作者:行者123 更新时间:2023-12-01 07:27:50 25 4
gpt4 key购买 nike

对于以下片段,Chisel 没有合成:

import Chisel._
import Node._
import scala.collection.mutable.HashMap

class PseudoLRU(val num_ways: Int) extends Module
{

val num_levels = log2Up(num_ways)

val io = new Bundle {
val last_used_cline = UInt(INPUT, width = num_levels)
val update_state = Bool(INPUT)
}

val state = Reg(Vec.fill(num_ways-1){Bool()})

private val msb = num_levels - 1

when (io.update_state) {

// process level 0
state(0) := !io.last_used_cline(msb, msb) // get the most significant bit

// process other levels
for (level <- 1 until num_levels) {
val offset = UInt((1 << level) - 1, width = log2Up(num_ways-1))
val bit_index = io.last_used_cline(msb, msb - level + 1) + offset
val pos = msb - level
val bit = io.last_used_cline(pos, pos)
state(bit_index) := !bit
}
}
}

object test_driver {
def main(args: Array[String]): Unit = {
val plru_inst = () => Module(new PseudoLRU(num_ways = 16))
chiselMain(args, plru_inst)

}
}

如果手动展开循环 for (level <- 1 until num_levels) 并折叠常量,则同样的行为:

when (io.update_state) {
state( 0 ) := !io.last_used_cline(3, 3)
state( io.last_used_cline(3, 3) + UInt(1, width = 3) ) := !io.last_used_cline(2, 2)
state( io.last_used_cline(3, 2) + UInt(3, width = 3) ) := !io.last_used_cline(1, 1)
state( io.last_used_cline(3, 1) + UInt(7, width = 3) ) := !io.last_used_cline(0, 0)
}

为两个片段(原始和展开/实例化的 16 种情况)生成的 verilog(和类似的 C++ 代码):

module PseudoLRU(input reset,
input [3:0] io_last_used_cline,
input io_update_state
);

wire T0;
wire[151:0] T1;

assign T0 = ! reset;
endmodule

不太明白为什么只有虚拟结构我应该怎么做才能强制执行逻辑综合?谢谢!

最佳答案

如果信号没有连接到任何东西,Chisel 将积极修剪您设计中的信号。

在您的情况下,您似乎没有来自 PsuedoLRU 的输出,只有输入“last_used_cline”和“update_state”。这就像在 C/C++ 中编写一个函数而不对函数的结果做任何事情。

现在在 C 中,您可以将变量标记为“volatile”以欺骗编译器保留您的代码(您 promise 其他人将使用该变量的值)。在 Chisel 中,您可以使用“debug()”强制信号存在。

我相信要强制你的 Vec of Regs 存在,你可以这样做:

for (i <- 0 until num_ways)
debug(state(i))

关于scala - Chisel 既不为 verilog 也不为 C++ 合成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com