接收器和源是不同长度的Vecs

时间:2018-07-30 11:21:47

标签: concatenation chisel

以下代码将两个字符串连接起来。它正在编译,但在详细说明后显示错误。

代码:

package problems

import chisel3._
import chisel3.util._

class Compare1 extends Module {
  val io = IO(new Bundle {
    val in1 = Input(Vec(5, UInt(3.W)))
    val in2 = Input(Vec(5, UInt(3.W)))
    val out = Output(Vec(6, UInt(3.W)))
  })

  val L = 5

  io.out := io.in2 

  val ml = 4

  for (l <- 0 until ml) {    
    when (io.in2(l) === io.in1(L - ml + l)) {
      io.out(l) := io.in1(l) 
    }
  }

  val m = (2*L) - ml
  for (i <- ml until m) {
    io.out(i) := io.in2(i - (L - ml))
  }
}

测试台:

我正在拨 19333 23599 ,并期望 154671

错误:

总而言之,这就是我所得到的

Errors: 1: in the following tutorials
Tutorial Compare1: exception Connection between sink (Vec(chisel3.core.UInt@80, chisel3.core.UInt@82, chisel3.core.UInt@84, chisel3.core.UInt@86, chisel3.core.UInt@88, chisel3.core.UInt@8a)) and source (Vec(chisel3.core.UInt@6a, chisel3.core.UInt@6c, chisel3.core.UInt@6e, chisel3.core.UInt@70, chisel3.core.UInt@72)) failed @: Sink and Source are different length Vecs.

1 个答案:

答案 0 :(得分:2)

错误与以下行有关:io.out := io.in2,io.out是长度为6的Vec,而io.in2是长度为5的Vec。如错误所示,您无法连接不同长度的Vecs在一起。

如果您希望将io.in2的索引0到4连接到io.out,请尝试

for (i <- 0 until io.in2.size) { io.out(i) := io.in2(i) }