chisel - Chisel3: Partial assignment to a multi-bit slice of a Vector IO -
it possible make partial assignment vector io follows:
import chisel3._ class example_1 extends module { val io = io(new bundle { val in1 = input(vec(4, bool()) val out1 = output(vec(4, bool()) }) (i <- 0 3){ io.out1(i) := io.in1(i) } }
is possible make partial assignment multi-bit slice of vector. following code doesn't work
import chisel3._ class example_1 extends module { val io = io(new bundle { val in1 = input(vec(4, bool()) val out1 = output(vec(4, bool()) }) (i <- 0 1){ io.out1((i*2)+2-1, i*2) := io.in1((i*2)+2-1, i*2) } }
one assume should possible using slice, however, whilst slice works referencing slice of io.in1 vector
val in1_sl = io.in1.slice(0, 2)
it not possible use slice on lhs of assignment create slice of io.out1:
io.out1.slice(0, 2) := io.in1.slice(0, 2)
the example i've used here demonstration purposes.
i don't think there way in chisel. using slice on lhs means collection returned splice not supports connect method. being said, following seems work, though haven't considered implications of it.
class slicer extends module { implicit class seqhelper(val seq: seq[bits]) { /** * promotes seq of bits class supports connect operator */ def := (other: seq[bits]): unit = { seq.zip(other).foreach { case (a, b) => := b} } } val io = io(new bundle { val in1 = input(vec(4, bool())) val out1 = output(vec(4, bool())) }) io.out1.slice(0, 2) := io.in1.slice(0, 2) }
you put slicerhelper in package object making accessible. less exotic idioms consider might be.
io.out1.slice(0, 2).zip(io.in1.slice(0, 2)).foreach { case (a, b) => a:= b }
or
io.out1.zip(io.in1).slice(0, 2).foreach { case (a, b) => a:= b }
Comments
Post a Comment