diff options
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Data.scala | 11 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/FixedPointSpec.scala | 18 |
2 files changed, 27 insertions, 2 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala index 66720f7c..c9cfe27b 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala @@ -48,8 +48,15 @@ private[core] object cloneSupertype { case (elt1: UInt, elt2: UInt) => if (elt1.width == (elt1.width max elt2.width)) elt1 else elt2 // TODO: perhaps redefine Widths to allow >= op? case (elt1: SInt, elt2: SInt) => if (elt1.width == (elt1.width max elt2.width)) elt1 else elt2 case (elt1: FixedPoint, elt2: FixedPoint) => { - require(elt1.binaryPoint == elt2.binaryPoint, s"can't create $createdType with FixedPoint with differing binaryPoints") - if (elt1.width == (elt1.width max elt2.width)) elt1 else elt2 + (elt1.binaryPoint, elt2.binaryPoint, elt1.width, elt2.width) match { + case (KnownBinaryPoint(bp1), KnownBinaryPoint(bp2), KnownWidth(w1), KnownWidth(w2)) => + val maxBinaryPoint = bp1 max bp2 + val maxIntegerWidth = (w1 - bp1) max (w2 - bp2) + FixedPoint((maxIntegerWidth + maxBinaryPoint).W, (maxBinaryPoint).BP) + case (KnownBinaryPoint(bp1), KnownBinaryPoint(bp2), _, _) => + FixedPoint(Width(), (bp1 max bp2).BP) + case _ => FixedPoint() + } } case (elt1, elt2) => throw new AssertionError(s"can't create $createdType with heterogeneous Bits types ${elt1.getClass} and ${elt2.getClass}") diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index 85f20d97..5047ac62 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -78,6 +78,21 @@ class FixedPointFromBitsTester extends BasicTester { stop() } +class FixedPointMuxTester extends BasicTester { + val largeWidthLowPrecision = 6.0.F(3.W, 0.BP) + val smallWidthHighPrecision = 0.25.F(2.W, 2.BP) + val unknownWidthLowPrecision = 6.0.F(0.BP) + val unknownFixed = Wire(FixedPoint()) + unknownFixed := smallWidthHighPrecision + + assert(Mux(true.B, largeWidthLowPrecision, smallWidthHighPrecision) === 6.0.F(0.BP)) + assert(Mux(false.B, largeWidthLowPrecision, smallWidthHighPrecision) === 0.25.F(2.BP)) + assert(Mux(false.B, largeWidthLowPrecision, unknownFixed) === 0.25.F(2.BP)) + assert(Mux(true.B, unknownWidthLowPrecision, smallWidthHighPrecision) === 6.0.F(0.BP)) + + stop() +} + class SBP extends Module { val io = IO(new Bundle { val in = Input(FixedPoint(6.W, 2.BP)) @@ -106,4 +121,7 @@ class FixedPointSpec extends ChiselPropSpec { property("should allow fromBits") { assertTesterPasses { new FixedPointFromBitsTester } } + property("should mux different widths and binary points") { + assertTesterPasses { new FixedPointMuxTester } + } } |
