From 4cccd877c25116a1f0b90824aabfc689d7fe50ea Mon Sep 17 00:00:00 2001 From: Wesley W. Terpstra Date: Mon, 18 Jun 2018 19:40:17 +0200 Subject: Fixed UIntToOH(x, 1) invocation with x.width == 0 (#778) --- src/main/scala/chisel3/util/OneHot.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/scala/chisel3/util/OneHot.scala b/src/main/scala/chisel3/util/OneHot.scala index 8a0bb9fc..a6af0d99 100644 --- a/src/main/scala/chisel3/util/OneHot.scala +++ b/src/main/scala/chisel3/util/OneHot.scala @@ -45,9 +45,10 @@ object UIntToOH { def apply(in: UInt): UInt = 1.U << in def apply(in: UInt, width: Int): UInt = width match { case 0 => 0.U(0.W) + case 1 => 1.U(1.W) case _ => val shiftAmountWidth = log2Ceil(width) - val shiftAmount = in.pad(shiftAmountWidth)((shiftAmountWidth - 1) max 0, 0) + val shiftAmount = in.pad(shiftAmountWidth)(shiftAmountWidth - 1, 0) (1.U << shiftAmount)(width - 1, 0) } } -- cgit v1.2.3