Chisel3中的BlackBox功能

时间:2018-09-17 10:31:08

标签: chisel

我想尝试一下凿子中的BlackBox功能,但是我没有得到警告信息,并且无法通过峰值/戳测试:

Total FIRRTL Compile Time: 237.8 ms
WARNING: external module "BlackBoxSwap"(swap:BlackBoxSwap)was not matched with an implementation
WARNING: external module "BlackBoxSwap"(:BlackBoxSwap)was not matched with an implementation
WARNING: external module "BlackBoxSwap"(:BlackBoxSwap)was not matched with an implementation
WARNING: external module "BlackBoxSwap"(:BlackBoxSwap)was not matched with an implementation
file loaded in 0.398085417 seconds, 25 symbols, 15 statements

源代码如下:     打包gcd

import chisel3._
import chisel3.util._

class BlackBoxSwap extends BlackBox with HasBlackBoxInline  {
//class BlackBoxRealSwap extends BlackBox with HasBlackBoxResource {
  val io = IO(new Bundle() {
    //val clk = Input(Clock())
      //val reset = Input(Bool())
    val out2 = Output(UInt(16.W))
    val out1 = Output(UInt(16.W))
    val in2 = Input(UInt(16.W))
    val in1 = Input(UInt(16.W))
  })


  //setResource("/real_swap.v")

  setInline("BlackBoxSwap.v",
    s"""
       |module BlackBoxSwap (
       |  input  [15:0] in1,
       |  input  [15:0] in2,
       |  output [15:0] out1,
       |  output [15:0] out2
       |);
       |
       |assign out1 = in2;
       |assign out2 = in1;
       |
       |endmodule
    """.stripMargin)

}

/**
  * Compute GCD using subtraction method.
  * Subtracts the smaller from the larger until register y is zero.
  * value in register x is then the GCD
  */
class GCD extends Module {
  val io = IO(new Bundle {
    val value1        = Input(UInt(16.W))
    val value2        = Input(UInt(16.W))
    val loadingValues = Input(Bool())
    val outputGCD     = Output(UInt(16.W))
    val outputValid   = Output(Bool())
  })

  val x  = Reg(UInt())
  val y  = Reg(UInt())

  val swap = Module(new BlackBoxSwap)

  when(x > y) { x := x - y }
    .otherwise { y := y - x }

  when(io.loadingValues) {
    //x := io.value1
    //y := io.value2
    swap.io.in1 := io.value1
    swap.io.in2 := io.value2

    x := swap.io.out1
    y := swap.io.out2
  }

  io.outputGCD := x
  io.outputValid := y === 0.U
}

我检查了生成的RTL,看来是正确的。你能帮上忙吗? 非常感谢!

2 个答案:

答案 0 :(得分:3)

在我看来,您似乎正在尝试将带有verilog黑盒的firrtl-解释器后端使用。 Verilog黑匣子只能与基于Verilog的后端(如verilator或VCS)一起使用。如果您不清楚如何设置后端,请在chisel-template中查找示例。

有一种在firrtl-解释器后端使用黑盒模拟的方法,但这需要您编写黑盒的scala实现。

答案 1 :(得分:0)

Chisel3具有多个后端,每个后端生成自己的输出。 Chisel 3.1具有默认的 treadle 后端,因此,如果需要合并Verilog,请执行以下操作:

sbt“ test:runMain gcd.GCDMain --is-verbose --backend-name verilator”