complex-numbers - 复数的类型类

标签 complex-numbers chisel

我需要为复杂 DSP 和复杂环操作实现自定义类型类。我知道 DspTools 项目,但故意不考虑它。

我有一个硬件模块,我想用 diff 类型类实例化它:UInt、SInt、FixedPoint、Real 和 Complex(FixedPoint、FixedPoint)。

这是我的最小类(class):

class Complex[A <: Data, B <: Data] (val re:A, val im:B) extends Bundle {
  override def cloneType: this.type = new Complex(re, im).asInstanceOf[this.type]
}

object Complex {    
  def apply[A <: Data, B <: Data](re:A, im:B) = new Complex(re, im)  
  implicit def UInt2Complex(re:UInt, im:UInt) = Complex(re,im)
}

当我使用 Chisel3.Core 中的不同数据类型实例化它时,代码会编译并运行。 但是,当我尝试这样做时:

import chisel3.core.{FixedPoint => FP}
...

  val inType  = Complex ( FP(20.W,10.BP), FP(20.W,10.BP))
  val outType = Complex ( FP(20.W,10.BP), FP(20.W,10.BP))
...

我编译了代码,但 FIRRTL 发出错误:

[信息] 使用 --backend-name verilator [信息] chisel3.core.Binding$RebindingException:尝试将绑定(bind)重新分配到 chisel3.core.FixedPoint@d [信息] 在 chisel3.core.Data.binding_$eq(Data.scala:250)

这有什么问题吗?如何解决这个问题?

最佳答案

问题是 Chisel 在递归调用 cloneType 时需要任何 Data 的新克隆,而您只需传递 reimComplex 构造函数,产生完全相同的对象。说得更具体一点:

val a = Complex(UInt(8.W), UInt(8.W))
val b = a.cloneType
a.re eq b.re // This will be true and it *must* not be

这是一个古老的问题,我们没有很好的解决方案,在您的情况下,您应该在 re 上调用 .cloneType >imComplex.cloneType

我知道您没有使用 DSPTools,但它仍然可以提供引用,他们就是这么做的:https://github.com/ucb-bar/dsptools/blob/fe8f9d08987f3a403f6281ba4face1c26b627b71/src/main/scala/dsptools/numbers/chisel_concrete/DspComplex.scala#L75

关于complex-numbers - 复数的类型类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54136650/

相关文章:

chisel - 如何从训练营示例导入 getVerilog() 函数?

c++ - 使用复 vector 时出错

python - 在 Python 中计算单位的 n 次根

algorithm - 仅使用三个乘法的复数乘积

python - Pytorch 的 Autograd 不支持复杂的矩阵求逆,有没有人有解决方法?

chisel - firrtl_interpreter.InterpreterException : error: ConcreteSInt(303, 9) 宽度错误 9 需要 10

haskell - 复数仿函数和monad的含义和用法?

chisel - 值不是 chisel3.Bundle 的成员

chisel - 如何在凿子中初始化向量