Search code examples
concatenationchisel

Sink and Source are different length Vecs


The following code is to concatenate two strings. It is getting compiled but shows errors after elaboration.

Code:

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))
  }
}

Testbench:

I am poking 19333 and 23599 and expecting 154671

Error:

To sum it up, this is what I get

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.

Solution

  • The error is with the line: io.out := io.in2, io.out is a Vec of length 6 while io.in2 is a Vec of length 5. As the error says, you cannot connect Vecs of different lengths together.

    If you wish to connect indices 0 to 4 of io.in2 to io.out, try

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