@@ -21,12 +21,13 @@ import chisel3.internal.sourceinfo.{SourceInfoTransform, SourceInfoWhiteboxTrans
2121
2222import scala .collection .immutable .SeqMap
2323import scala .language .experimental .macros
24+ import scala .math .BigDecimal .RoundingMode .RoundingMode
2425import chisel3 .util .Cat
2526
26- object FixedPoint extends NumObject {
27+ object FixedPoint {
2728
2829 /** Create a FixedPoint type with inferred width. */
29- def apply (): FixedPoint = apply(UnknownWidth () , BinaryPoint ())
30+ def apply (): FixedPoint = apply(UnknownWidth , BinaryPoint ())
3031
3132 /** Create a FixedPoint type or port with fixed width. */
3233 def apply (width : Width , binaryPoint : BinaryPoint ): FixedPoint = new FixedPoint (width, binaryPoint)
@@ -42,15 +43,15 @@ object FixedPoint extends NumObject {
4243 * Use PrivateObject to force users to specify width and binaryPoint by name
4344 */
4445 def fromBigInt (value : BigInt , binaryPoint : BinaryPoint = 0 .BP ): FixedPoint = {
45- apply(value, UnknownWidth () , binaryPoint)
46+ apply(value, UnknownWidth , binaryPoint)
4647 }
4748
4849 /** Create a FixedPoint literal with inferred width from BigInt.
4950 * Use PrivateObject to force users to specify width and binaryPoint by name
5051 */
5152 def fromBigInt (value : BigInt , width : Int , binaryPoint : Int ): FixedPoint =
5253 if (width == - 1 ) {
53- apply(value, UnknownWidth () , BinaryPoint (binaryPoint))
54+ apply(value, UnknownWidth , BinaryPoint (binaryPoint))
5455 } else {
5556 apply(value, KnownWidth (width), BinaryPoint (binaryPoint))
5657 }
@@ -60,7 +61,7 @@ object FixedPoint extends NumObject {
6061 */
6162 def fromDouble (value : Double , width : Width , binaryPoint : BinaryPoint ): FixedPoint = {
6263 fromBigInt(
63- toBigInt(value, binaryPoint.get),
64+ FixedPoint . toBigInt(value, binaryPoint.get),
6465 width = width,
6566 binaryPoint = binaryPoint
6667 )
@@ -71,7 +72,7 @@ object FixedPoint extends NumObject {
7172 */
7273 def fromBigDecimal (value : BigDecimal , width : Width , binaryPoint : BinaryPoint ): FixedPoint = {
7374 fromBigInt(
74- toBigInt(value, binaryPoint.get),
75+ FixedPoint . toBigInt(value, binaryPoint.get),
7576 width = width,
7677 binaryPoint = binaryPoint
7778 )
@@ -83,6 +84,14 @@ object FixedPoint extends NumObject {
8384 new FixedPoint (_width, binaryPoint).Lit (_.data -> value.S (_width))
8485 }
8586
87+ // Delegate to `chisel3.Num` methods that used to be in `chisel3.NumObject` trait. See chipsalliance/chisel#4768.
88+ def toBigInt (x : Double , binaryPoint : Int ): BigInt = Num .toBigInt(x, binaryPoint)
89+ def toBigInt (x : BigDecimal , binaryPoint : Int ): BigInt = Num .toBigInt(x, binaryPoint)
90+ def toBigInt (x : BigDecimal , binaryPoint : Int , roundingMode : RoundingMode ): BigInt =
91+ Num .toBigInt(x, binaryPoint, roundingMode)
92+ def toDouble (i : BigInt , binaryPoint : Int ): Double = Num .toDouble(i, binaryPoint)
93+ def toBigDecimal (value : BigInt , binaryPoint : Int ): BigDecimal = Num .toBigDecimal(value, binaryPoint)
94+
8695 /** Create a FixedPoint bundle with its data port connected to an SInt literal
8796 */
8897 private [fixedpoint] def fromData (
@@ -103,7 +112,7 @@ object FixedPoint extends NumObject {
103112 }
104113
105114 private [fixedpoint] def recreateWidth [T <: Data ](d : T ): Width = {
106- d.widthOption.fold[Width ](UnknownWidth () )(_.W )
115+ d.widthOption.fold[Width ](UnknownWidth )(_.W )
107116 }
108117
109118 /** Align all FixedPoints in a (possibly heterogeneous) sequence by width and binary point
@@ -145,7 +154,7 @@ object FixedPoint extends NumObject {
145154
146155 implicit class fromDoubleToLiteral (double : Double ) {
147156 def F (binaryPoint : BinaryPoint ): FixedPoint = {
148- FixedPoint .fromDouble(double, UnknownWidth () , binaryPoint)
157+ FixedPoint .fromDouble(double, UnknownWidth , binaryPoint)
149158 }
150159
151160 def F (width : Width , binaryPoint : BinaryPoint ): FixedPoint = {
@@ -155,7 +164,7 @@ object FixedPoint extends NumObject {
155164
156165 implicit class fromBigDecimalToLiteral (bigDecimal : BigDecimal ) {
157166 def F (binaryPoint : BinaryPoint ): FixedPoint = {
158- FixedPoint .fromBigDecimal(bigDecimal, UnknownWidth () , binaryPoint)
167+ FixedPoint .fromBigDecimal(bigDecimal, UnknownWidth , binaryPoint)
159168 }
160169
161170 def F (width : Width , binaryPoint : BinaryPoint ): FixedPoint = {
@@ -223,8 +232,6 @@ sealed class FixedPoint private[fixedpoint] (width: Width, private var _inferred
223232
224233 def do_unary_- (implicit sourceInfo : SourceInfo ): FixedPoint = FixedPoint .fromData(binaryPoint, - data)
225234
226- def do_unary_-% (implicit sourceInfo : SourceInfo ): FixedPoint = FixedPoint .fromData(binaryPoint, data.unary_-% )
227-
228235 override def do_* (that : FixedPoint )(implicit sourceInfo : SourceInfo ): FixedPoint =
229236 FixedPoint .fromData(binaryPoint + that.binaryPoint, data * that.data)
230237
@@ -325,8 +332,10 @@ sealed class FixedPoint private[fixedpoint] (width: Width, private var _inferred
325332
326333 override def bulkConnect (that : Data )(implicit sourceInfo : SourceInfo ): Unit = connectOp(that, _ <> _)
327334
328- override def connectFromBits (that : Bits )(implicit sourceInfo : SourceInfo ): Unit = {
329- this .data := that.asTypeOf(this .data)
335+ override protected def _fromUInt (that : UInt )(implicit sourceInfo : SourceInfo ): Data = {
336+ val _w = Wire (this .cloneType)
337+ _w.data := that.asTypeOf(this .data)
338+ _w
330339 }
331340
332341 def apply (x : BigInt ): Bool = data.apply(x)
0 commit comments