Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Fix cat of zero-width SInt #2116

Merged
merged 1 commit into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/scala/firrtl/passes/ZeroWidth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ object ZeroWidth extends Transform with DependencyAPIMigration {
}
}
nonZeros match {
case Nil => UIntLiteral(ZERO, IntWidth(BigInt(1)))
case Seq(x) => x
case Nil => UIntLiteral(ZERO, IntWidth(BigInt(1)))
// We may have an SInt, Cat has type UInt so cast
case Seq(x) => castRhs(tpe, x)
case seq => DoPrim(Cat, seq, consts, tpe).map(onExp)
}
case DoPrim(Andr, Seq(x), _, _) if (bitWidth(x.tpe) == 0) => UIntLiteral(1) // nothing false
Expand Down
17 changes: 17 additions & 0 deletions src/test/scala/firrtlTests/ZeroWidthTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ class ZeroWidthTests extends FirrtlFlatSpec {
| x <= UInt<1>(1)""".stripMargin
(parse(exec(input))) should be(parse(check))
}

"Cat of SInt with zero-width" should "keep type correctly" in {
val input =
"""circuit Top :
| module Top :
| input x : SInt<0>
| input y : SInt<1>
| output z : UInt<1>
| z <= cat(y, x)""".stripMargin
val check =
"""circuit Top :
| module Top :
| input y : SInt<1>
| output z : UInt<1>
| z <= asUInt(y)""".stripMargin
(parse(exec(input))) should be(parse(check))
}
}

class ZeroWidthVerilog extends FirrtlFlatSpec {
Expand Down