【问题标题】:Are Vec can be reduced in Chisel?Vec 可以在 Chisel 中减少吗?
【发布时间】:2021-08-31 13:13:41
【问题描述】:

我正在尝试在 UInt 中减少 Vec 的 Bundle,但出现错误:

class DiffPair extends Bundle {
    val p = Bool()
    val n = Bool()
}

class TMDS extends Bundle {
    val clk  = new DiffPair()
    val data = Vec(3, new DiffPair())
}
val io = IO(new Bundle {
 //...
 val tmds = Output(new TMDS())
})

val O_tmds_data_p = IO(Output(UInt(3.W)))

如果我使用这个reduce 代码:

O_tmds_data_p := gbHdmi.io.tmds.data.reduce((a,b) => Cat(a.p, b.p))

我遇到了这个错误:

[info] compiling 1 Scala source to /home/user/GbHdmi/target/scala-2.12/classes ...
[error] /home/user/GbHdmi/src/main/scala/topgbhdmi.scala:72:67: type mismatch;
[error]  found   : chisel3.UInt
[error]  required: gbhdmi.DiffPair
[error]       O_tmds_data_p := gbHdmi.io.tmds.data.reduce((a,b) => Cat(a.p, b.p))
[error]                                                                   ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 31 août 2021, 15:04:08

我知道abDiffPair,但a.pb.pBool 不是吗?

【问题讨论】:

    标签: scala chisel


    【解决方案1】:

    我找到的解决方案是在减少之前用map 取“p”值:

    O_tmds_data_p := gbHdmi.io.tmds.data.map(_.p.asUInt).reduce((a,b) => Cat(a,b))
    

    或者,以简化的方式:

    O_tmds_data_p := gbHdmi.io.tmds.data.map(_.p.asUInt).reduce(_ ## _)
    

    而且,这种方式行不通,原因不明:

    O_tmds_data_p := gbHdmi.io.tmds.data.reduce(_.p.asUInt ## _.p.asUInt)
    

    错误:

    sbt:GbHdmi> runMain gbhdmi.TopGbHdmiDriver
    [info] compiling 1 Scala source to /home/user/GbHdmi/target/scala-2.12/classes ...
    [error] /home/user/GbHdmi/src/main/scala/topgbhdmi.scala:71:63: type mismatch;
    [error]  found   : chisel3.UInt
    [error]  required: gbhdmi.DiffPair
    [error]       O_tmds_data_p :=  gbHdmi.io.tmds.data.reduce(_.p.asUInt ## _.p.asUInt)
    [error]                                                               ^
    [error] one error found
    [error] (Compile / compileIncremental) Compilation failed
    [error] Total time: 0 s, completed Sep 1, 2021, 9:17:15 AM
    

    【讨论】:

      【解决方案2】:

      你试过了吗

      O_tmds_data_p := gbHdmi.io.tmds.data.asUInt
      

      我认为这应该适合你。

      【讨论】:

      • 我会遇到问题,因为数据是 n 和 p 的 DiffPair 否?
      • 看看scastie.scala-lang.org/3IUJxnJWQf6Uamq8i9mrkA 我认为这表明它有效
      • 是的,但我只需要从 DiffPair 中获取 p。
      • 对不起,我错过了,但看起来你找到了写方法,比如 out := VecInit(x.map(_.p)).asUInt
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多