From bffc8b9e851af88128f1c683e67634ebde25c14b Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Thu, 24 May 2018 11:46:32 -0700 Subject: Fix UIntToOH for output widths larger than 2^(input width) (#823) * Add test for UIntToOH * Pad UIntToOH inputs to support oversized output widthds * Optimize Bits.pad in case of known widths * Add missing import and fix test in OneHotMuxSpec --- chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'chiselFrontend/src') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index 51f5f5ec..b3091db3 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -190,8 +190,10 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg]) */ final def pad(that: Int): this.type = macro SourceInfoTransform.thatArg - def do_pad(that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): this.type = - binop(sourceInfo, cloneTypeWidth(this.width max Width(that)), PadOp, that) + def do_pad(that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): this.type = this.width match { + case KnownWidth(w) if w >= that => this + case _ => binop(sourceInfo, cloneTypeWidth(this.width max Width(that)), PadOp, that) + } /** Returns this wire bitwise-inverted. */ final def unary_~ (): Bits = macro SourceInfoWhiteboxTransform.noArg -- cgit v1.2.3