sodor/火箭核心ALU中的凿子测试错误

Chisel testing error in sodor/ rocket core ALU

我正在尝试使用 chisel3 在不同的项目中自定义和使用 Sodor processor/Rocket 核心的 ALU 源文件。 运行 sbt 测试给我以下错误。

[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$$anonfun$apply$$anonfun$apply$mcV$sp.apply(aluTest.scala:41)

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

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

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

[info]   at chisel3.Driver$$anonfun$elaborate.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
}

抛出的异常: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))
}

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