From ac641fb183e3a8866e6bd72123801cfb04a0c893 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Mon, 19 Oct 2020 12:35:26 -0400 Subject: Enable Cat of Zero Element Vec (#1623) * Return 0.U for asUInt of a zero-element Seq Add a condition to SeqUtils.asUInt to have it return an unspecified width 0.U when applied to an empty sequence. This enables the ability to do a Cat of a zero-element sequence. Signed-off-by: Schuyler Eldridge * Test elaboration of Cat on zero-element Seq Signed-off-by: Schuyler Eldridge --- core/src/main/scala/chisel3/SeqUtils.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/main/scala/chisel3/SeqUtils.scala b/core/src/main/scala/chisel3/SeqUtils.scala index 64904e51..e263810a 100644 --- a/core/src/main/scala/chisel3/SeqUtils.scala +++ b/core/src/main/scala/chisel3/SeqUtils.scala @@ -15,12 +15,15 @@ private[chisel3] object SeqUtils { * in the sequence forms the most significant bits. * * Equivalent to r(n-1) ## ... ## r(1) ## r(0). + * @note This returns a `0.U` if applied to a zero-element `Vec`. */ def asUInt[T <: Bits](in: Seq[T]): UInt = macro SourceInfoTransform.inArg /** @group SourceInfoTransformMacros */ def do_asUInt[T <: Bits](in: Seq[T])(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = { - if (in.tail.isEmpty) { + if (in.isEmpty) { + 0.U + } else if (in.tail.isEmpty) { in.head.asUInt } else { val left = prefix("left") { -- cgit v1.2.3