【问题标题】:Chisel testing error in sodor/ rocket core ALUsodor/火箭核心 ALU 中的凿子测试错误
【发布时间】:2016-12-07 16:31:58
【问题描述】:

我正在尝试使用 chisel3 在另一个项目中自定义和使用 Sodor 处理器/Rocket 内核的 ALU 源文件。运行 sbt test 给我以下错误。

[info] - should carry out proper arithmatic and logical operations (with verilator) *** FAILED ***

[info]   chisel3.core.Binding$BindingException: 'this' (chisel3.core.UInt@7): Missing IO() wrapper

[info]   at chisel3.core.Binding$.checkSynthesizable(Binding.scala:185)

[info]   at chisel3.core.Bits.do_apply(Bits.scala:97)

[info]   at chisel3.core.Bits.do_apply(Bits.scala:109)

[info]   at RiscvIoT.ALU$.isSub(alu.scala:44)

[info]   at RiscvIoT.ALU.<init>(alu.scala:68)

[info]   at RiscvIoT.ALUTester$$anonfun$2$$anonfun$apply$1$$anonfun$apply$mcV$sp$1.apply(aluTest.scala:41)

[info]   at RiscvIoT.ALUTester$$anonfun$2$$anonfun$apply$1$$anonfun$apply$mcV$sp$1.apply(aluTest.scala:41)

[info]   at chisel3.core.Module$.do_apply(Module.scala:29)

[info]   at chisel3.Driver$$anonfun$elaborate$1.apply(Driver.scala:191)

[info]   at chisel3.Driver$$anonfun$elaborate$1.apply(Driver.scala:191)

按照 chisel 3 wiki 上关于测试和调试的指南,我相信最初的错误在第 44 行(isSub 函数定义)。但我无法弄清楚问题所在,我所做的也没有解决问题。为了方便起见,我在下面发布了我的完整源文件。

import chisel3._
import chisel3.util._
import Common._

object ALU
{
  val SZ_ALU_FN = 4
  val ALU_X    = Bits(0)
  val ALU_ADD  = Bits(0)
  val ALU_SLL  = Bits(1)
  val ALU_XOR  = Bits(4)
  val ALU_OR   = Bits(6)
  val ALU_AND  = Bits(7)
  val ALU_SRL  = Bits(5)
  val ALU_SUB  = Bits(10)
  val ALU_SRA  = Bits(11)
  val ALU_SLT  = Bits(12)
  val ALU_SLTU = Bits(14)
  val ALU_COPY1= Bits(8)   

  def isMulFN(fn: Bits, cmp: Bits) = fn(1,0) === cmp(1,0)
  def isSub(cmd: Bits) = cmd(3)
  def isSLTU(cmd: Bits) = cmd(0)
}
import ALU._

class ALUIO extends Bundle {
  val xprlen = 32
  val fn = Bits(INPUT, SZ_ALU_FN)
  val in2 = UInt(INPUT, xprlen)
  val in1 = UInt(INPUT, xprlen)
  val out = UInt(OUTPUT, xprlen)
  val adder_out = UInt(OUTPUT, xprlen)
}

class ALU extends Module
{
  val io = new ALUIO
  val xprlen = 32
  val msb = xprlen-1

  // ADD, SUB
  val sum = io.in1 + Mux(isSub(io.fn), -io.in2, io.in2)

  // SLT, SLTU
  val less  = Mux(io.in1(msb) === io.in2(msb), sum(msb),
              Mux(isSLTU(io.fn), io.in2(msb), io.in1(msb)))

  // SLL, SRL, SRA
  val shamt = io.in2(4,0).toUInt
  val shin_r = io.in1(31,0)
  val shin = Mux(io.fn === ALU_SRL  || io.fn === ALU_SRA, shin_r, Reverse(shin_r))
  val shout_r = (Cat(isSub(io.fn) & shin(msb), shin).toSInt >> shamt)(msb,0)
  val shout_l = Reverse(shout_r)

  val bitwise_logic =
    Mux(io.fn === ALU_AND, io.in1 & io.in2,
    Mux(io.fn === ALU_OR,  io.in1 | io.in2,
    Mux(io.fn === ALU_XOR, io.in1 ^ io.in2,
                       io.in1))) // ALU_COPY1

//  val out64 =
  val out_xpr_length =
    Mux(io.fn === ALU_ADD || io.fn === ALU_SUB,  sum,
    Mux(io.fn === ALU_SLT || io.fn === ALU_SLTU, less,
    Mux(io.fn === ALU_SRL || io.fn === ALU_SRA,  shout_r,
    Mux(io.fn === ALU_SLL,                       shout_l,
    bitwise_logic))))

  io.out := out_xpr_length(31,0).toUInt
  io.adder_out := sum
}

【问题讨论】:

    标签: scala chisel


    【解决方案1】:

    抛出的异常:chisel3.core.Binding$BindingException: 'this' (chisel3.core.UInt@7): Missing IO() wrapper是由于在chisel3中,io必须包裹在IO(...)中

    文档中可能有点隐藏(参见https://github.com/ucb-bar/chisel3/wiki/Chisel3-vs-Chisel2#deprecated-usage)

    要修复,请将 ALU 中的 io 声明更改为:

    val io = IO(new ALUIO)
    

    您还应该将 ALUIO 更改为:

    class ALUIO extends Bundle {
      val xprlen = 32
      val fn = Input(Bits(SZ_ALU_FN.W))
      val in2 = Input(UInt(xprlen.W))
      val in1 = Input(UInt(xprlen.W))
      val out = Output(UInt(xprlen.W))
      val adder_out = Output(UInt(xprlen.W))
    }
    

    虽然我认为旧方法已被弃用而不是错误。

    【讨论】:

    • 感谢 jkoenig。很抱歉问了一个愚蠢的问题。我仍然无法从错误消息中识别凿子错误。
    • 真的一点问题都没有! Chisel + Scala 代表了一个陡峭的学习曲线。人们在 Stack Overflow 上提出的问题越多,未来人们就越有可能快速找到问题的解决方案!
    猜你喜欢
    • 1970-01-01
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2022-09-26
    相关资源
    最近更新 更多