Does CHISEL allows only a single bit of a bit vector be updated? I would like to do something like :
val x = 12
val slot = UInt(0,width=80)
slot(x) := UInt(1)
but the compiler gives the following error:
ambiguous reference to overloaded definition,
[error] both method := in class Bool of type (src: Chisel.Bits)Unit
[error] and method := in class UInt of type (src: Chisel.UInt)Unit
[error] match argument types (Chisel.UInt)
[error] slot(x) := UInt(1)
[error] ^
Is there a better or proper way to do this in CHISEL?
I don't think there is a way to update a single bit at the moment in Chisel.
EDITED: As of 2014 June, Chisel now allows you to access individual bits of a Reg(UInt())
, but not a UInt()
wire.
The way I handle bit vectors is to turn them into a Vec() of Bools/UInts and update them individually that way.
val x = 12
val slot = Vec(80).fill{Bool(false)}
slot(x) := Bool(true)
val slot_in_bits = slot.toBits
You can then use .toBits and .fromBits to move between treating it as a Vec() and treating it as Bits().
HW-wise, treating a bit vector as a Vec() of bool is equivalent (Unfortunately, in terms of emulation in say C++, it is not super efficient as suddenly each element is its own variable).