From 9431d9fb3e7f2c35df2300adb23f3557596da2e8 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Tue, 11 Jun 2024 11:36:25 -0700 Subject: [PATCH 1/2] Add a test for issue 4159 --- src/test/scala/chiselTests/ChiselEnum.scala | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/scala/chiselTests/ChiselEnum.scala b/src/test/scala/chiselTests/ChiselEnum.scala index a64db67446c..6d250c2ab05 100644 --- a/src/test/scala/chiselTests/ChiselEnum.scala +++ b/src/test/scala/chiselTests/ChiselEnum.scala @@ -401,6 +401,30 @@ class ChiselEnumSpec extends ChiselFlatSpec with Utils { assertTesterPasses(new CastToUIntTester) } + // This is a bug but fixing it may break user code + // See https://github.com/chipsalliance/chisel/issues/4159 + it should "preserve legacy width behavior" in { + val verilog = ChiselStage.emitSystemVerilog(new RawModule { + val out1, out2, out3 = IO(Output(UInt(8.W))) + val e = EnumExample.e1 + val x = e.asUInt + val y = e.asTypeOf(UInt()) + val z = e.asTypeOf(UInt(e.getWidth.W)) + out1 := Cat(1.U, x) + out2 := Cat(1.U, y) + out3 := Cat(1.U, z) + // The bug is that the width of x is 7 but the value of out1 is 3 + x.getWidth should be(7) + x.getWidth should be(EnumExample.getWidth) + y.widthOption should be(None) + z.getWidth should be(7) + }) + // The bug is that all of these should be the same as out3, or the widths above are wrong + verilog should include("assign out1 = 8'h3;") + verilog should include("assign out2 = 8'h3;") + verilog should include("assign out3 = 8'h81;") + } + it should "cast literal UInts to enums correctly" in { assertTesterPasses(new CastFromLitTester) } From 992eaf755ecd0cfcf8c065697f27562852b7999b Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Tue, 11 Jun 2024 15:59:31 -0700 Subject: [PATCH 2/2] Update src/test/scala/chiselTests/ChiselEnum.scala Co-authored-by: Schuyler Eldridge --- src/test/scala/chiselTests/ChiselEnum.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/scala/chiselTests/ChiselEnum.scala b/src/test/scala/chiselTests/ChiselEnum.scala index 6d250c2ab05..a22b9016367 100644 --- a/src/test/scala/chiselTests/ChiselEnum.scala +++ b/src/test/scala/chiselTests/ChiselEnum.scala @@ -401,8 +401,8 @@ class ChiselEnumSpec extends ChiselFlatSpec with Utils { assertTesterPasses(new CastToUIntTester) } - // This is a bug but fixing it may break user code - // See https://github.com/chipsalliance/chisel/issues/4159 + // This is a bug, but fixing it may break user code. + // See: https://github.com/chipsalliance/chisel/issues/4159 it should "preserve legacy width behavior" in { val verilog = ChiselStage.emitSystemVerilog(new RawModule { val out1, out2, out3 = IO(Output(UInt(8.W)))