summaryrefslogtreecommitdiff
path: root/chiselFrontend
diff options
context:
space:
mode:
authorducky2016-11-17 11:21:59 -0800
committerducky2016-11-21 13:31:12 -0800
commitb0cc0c93a80aec5bed54cfb11923636c09b7e180 (patch)
tree5d3edabd4010cfb0e8dce125f39e89ee904143a0 /chiselFrontend
parent9e32a39bda3fba11e6b0990e6ad5e7e17b5d8364 (diff)
SInt conversion finished, everything builds again
Diffstat (limited to 'chiselFrontend')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala17
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/package.scala65
2 files changed, 63 insertions, 19 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index 7e467b88..aa73abf5 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -134,7 +134,7 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg])
}
val w = x - y + 1
if (isLit()) {
- ((litValue >> y) & ((BigInt(1) << w) - 1)).asUInt(w)
+ ((litValue >> y) & ((BigInt(1) << w) - 1)).asUInt(w.W)
} else {
Binding.checkSynthesizable(this, s"'this' ($this)")
pushOp(DefPrim(sourceInfo, UInt(Width(w)), BitsExtractOp, this.ref, ILit(x), ILit(y)))
@@ -403,7 +403,7 @@ sealed class UInt private[core] (width: Width, lit: Option[ULit] = None)
private[chisel3] def toType = s"UInt$width"
override private[chisel3] def fromInt(value: BigInt, width: Int): this.type =
- value.asUInt(width).asInstanceOf[this.type]
+ value.asUInt(width.W).asInstanceOf[this.type]
// TODO: refactor to share documentation with Num or add independent scaladoc
final def unary_- (): UInt = macro SourceInfoTransform.noArg
@@ -563,13 +563,13 @@ sealed class SInt private[core] (width: Width, lit: Option[SLit] = None)
private[chisel3] def toType = s"SInt$width"
override private[chisel3] def fromInt(value: BigInt, width: Int): this.type =
- SInt(value, width).asInstanceOf[this.type]
+ value.asSInt(width.W).asInstanceOf[this.type]
final def unary_- (): SInt = macro SourceInfoTransform.noArg
final def unary_-% (): SInt = macro SourceInfoTransform.noArg
- def unary_- (implicit sourceInfo: SourceInfo): SInt = SInt(0) - this
- def unary_-% (implicit sourceInfo: SourceInfo): SInt = SInt(0) -% this
+ def unary_- (implicit sourceInfo: SourceInfo): SInt = 0.S - this
+ def unary_-% (implicit sourceInfo: SourceInfo): SInt = 0.S -% this
/** add (default - no growth) operator */
override def do_+ (that: SInt)(implicit sourceInfo: SourceInfo): SInt =
@@ -637,7 +637,7 @@ sealed class SInt private[core] (width: Width, lit: Option[SLit] = None)
final def abs(): UInt = macro SourceInfoTransform.noArg
- def do_abs(implicit sourceInfo: SourceInfo): UInt = Mux(this < SInt(0), (-this).asUInt, this.asUInt)
+ def do_abs(implicit sourceInfo: SourceInfo): UInt = Mux(this < 0.S, (-this).asUInt, this.asUInt)
override def do_<< (that: Int)(implicit sourceInfo: SourceInfo): SInt =
binop(sourceInfo, SInt(this.width + that), ShiftLeftOp, that)
@@ -675,8 +675,7 @@ trait SIntFactory {
}
/** Create an SInt literal with specified width. */
- protected def Lit(value: BigInt, width: Width): SInt = {
-
+ protected[chisel3] def Lit(value: BigInt, width: Width): SInt = {
val lit = SLit(value, width)
val result = new SInt(lit.width, Some(lit))
// Bind result to being an Literal
@@ -685,6 +684,8 @@ trait SIntFactory {
}
}
+object SInt extends SIntFactory
+
// REVIEW TODO: Why does this extend UInt and not Bits? Does defining airth
// operations on a Bool make sense?
/** A data type for booleans, defined as a single bit indicating true or false.
diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala
index 554e6238..7fb05c75 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/package.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala
@@ -18,23 +18,62 @@ package chisel3 {
* Prefer storing the result and then extracting from it.
*/
implicit class fromIntToLiteral(val x: Int) {
- def U: UInt = UInt.Lit(BigInt(x), Width()) // scalastyle:ignore method.name
- def S: SInt = SInt(BigInt(x), Width()) // scalastyle:ignore method.name
+ /** Int to UInt conversion, recommended style for constants.
+ */
+ def U: UInt = UInt.Lit(BigInt(x), Width()) // scalastyle:ignore method.name
+ /** Int to SInt conversion, recommended style for constants.
+ */
+ def S: SInt = SInt.Lit(BigInt(x), Width()) // scalastyle:ignore method.name
+ /** Int to UInt conversion, recommended style for variables.
+ */
def asUInt(): UInt = UInt.Lit(x, Width())
- def asSInt(): SInt = SInt(x, Width())
- def asUInt(width: Int): UInt = UInt.Lit(x, Width(width))
- def asSInt(width: Int): SInt = SInt(x, Width(width))
+ /** Int to SInt conversion, recommended style for variables.
+ */
+ def asSInt(): SInt = SInt.Lit(x, Width())
+ /** Int to UInt conversion with specified width, recommended style for variables.
+ */
+ def asUInt(width: Width): UInt = UInt.Lit(x, width)
+ /** Int to SInt conversion with specified width, recommended style for variables.
+ */
+ def asSInt(width: Width): SInt = SInt.Lit(x, width)
+
+ /** Int to UInt conversion with specified width, recommended style for variables.
+ */
+ //def asUInt(width: Int): UInt = UInt.Lit(x, Width(width))
+ /** Int to SInt conversion with specified width, recommended style for variables.
+ */
+ //def asSInt(width: Int): SInt = SInt(x, Width(width))
+
}
implicit class fromBigIntToLiteral(val x: BigInt) {
- def U: UInt = UInt.Lit(x, Width()) // scalastyle:ignore method.name
- def S: SInt = SInt(x, Width()) // scalastyle:ignore method.name
+ /** Int to UInt conversion, recommended style for constants.
+ */
+ def U: UInt = UInt.Lit(x, Width()) // scalastyle:ignore method.name
+ /** Int to SInt conversion, recommended style for constants.
+ */
+ def S: SInt = SInt.Lit(x, Width()) // scalastyle:ignore method.name
+ /** Int to UInt conversion, recommended style for variables.
+ */
def asUInt(): UInt = UInt.Lit(x, Width())
- def asSInt(): SInt = SInt(x, Width())
- def asUInt(width: Int): UInt = UInt.Lit(x, Width(width))
- def asSInt(width: Int): SInt = SInt(x, width)
+ /** Int to SInt conversion, recommended style for variables.
+ */
+ def asSInt(): SInt = SInt.Lit(x, Width())
+ /** Int to UInt conversion with specified width, recommended style for variables.
+ */
+ def asUInt(width: Width): UInt = UInt.Lit(x, width)
+ /** Int to SInt conversion with specified width, recommended style for variables.
+ */
+ def asSInt(width: Width): SInt = SInt.Lit(x, width)
+
+ /** Int to UInt conversion with specified width, recommended style for variables.
+ */
+ // def asUInt(width: Int): UInt = UInt.Lit(x, Width(width))
+ /** Int to SInt conversion with specified width, recommended style for variables.
+ */
+ // def asSInt(width: Int): SInt = SInt(x, width)
}
implicit class fromStringToLiteral(val x: String) {
@@ -65,11 +104,15 @@ package chisel3 {
}
implicit class fromBooleanToLiteral(val x: Boolean) {
- def B: Bool = Bool(x) // scalastyle:ignore method.name
+ def B: Bool = Bool(x) // scalastyle:ignore method.name
}
implicit class fromDoubleToLiteral(val x: Double) {
def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(x, binaryPoint = binaryPoint)
}
+
+ implicit class fromIntToWidth(val x: Int) {
+ def W: Width = Width(x) // scalastyle:ignore method.name
+ }
}
} \ No newline at end of file