summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/internal
diff options
context:
space:
mode:
authorChick Markley2021-04-27 12:17:17 -0700
committerGitHub2021-04-27 12:17:17 -0700
commit6deb379b1d8bafc81a605f60476bf0f24eac60b4 (patch)
treeb12c7dfaea1948ec9a7fa2f389db0699b3d1daf4 /core/src/main/scala/chisel3/internal
parent23b3fe8a6a2db92599bb0775626425056d47d1de (diff)
Introduce VecLiterals (#1834)
This PR provides for support for Vec literals. They can be one of two forms Inferred: ``` Vec.Lit(0x1.U, 0x2.U) ``` or explicit: ``` Vec(2, UInt(4.W)).Lit(0 -> 0x1.U, 1 -> 0x2.U) ``` - Explicit form allows for partial, or sparse, literals. - Vec literals can be used as Register initializers - Arbitrary nesting (consistent with type constraints is allowed)
Diffstat (limited to 'core/src/main/scala/chisel3/internal')
-rw-r--r--core/src/main/scala/chisel3/internal/Binding.scala4
-rw-r--r--core/src/main/scala/chisel3/internal/firrtl/IR.scala24
2 files changed, 28 insertions, 0 deletions
diff --git a/core/src/main/scala/chisel3/internal/Binding.scala b/core/src/main/scala/chisel3/internal/Binding.scala
index 9e17aded..8a3c4330 100644
--- a/core/src/main/scala/chisel3/internal/Binding.scala
+++ b/core/src/main/scala/chisel3/internal/Binding.scala
@@ -6,6 +6,8 @@ import chisel3._
import chisel3.experimental.BaseModule
import chisel3.internal.firrtl.LitArg
+import scala.collection.immutable.ListMap
+
/** Requires that a node is hardware ("bound")
*/
object requireIsHardware {
@@ -123,3 +125,5 @@ sealed trait LitBinding extends UnconstrainedBinding with ReadOnlyBinding
case class ElementLitBinding(litArg: LitArg) extends LitBinding
// Literal binding attached to the root of a Bundle, containing literal values of its children.
case class BundleLitBinding(litMap: Map[Data, LitArg]) extends LitBinding
+// Literal binding attached to the root of a Vec, containing literal values of its children.
+case class VecLitBinding(litMap: ListMap[Data, LitArg]) extends LitBinding
diff --git a/core/src/main/scala/chisel3/internal/firrtl/IR.scala b/core/src/main/scala/chisel3/internal/firrtl/IR.scala
index 61f97ce6..81b4f7ab 100644
--- a/core/src/main/scala/chisel3/internal/firrtl/IR.scala
+++ b/core/src/main/scala/chisel3/internal/firrtl/IR.scala
@@ -91,6 +91,14 @@ abstract class LitArg(val num: BigInt, widthArg: Width) extends Arg {
elem
}
+ /** Provides a mechanism that LitArgs can have their width adjusted
+ * to match other members of a VecLiteral
+ *
+ * @param newWidth the new width for this
+ * @return
+ */
+ def cloneWithWidth(newWidth: Width): this.type
+
protected def minWidth: Int
if (forcedWidth) {
require(widthArg.get >= minWidth,
@@ -106,6 +114,10 @@ case class ULit(n: BigInt, w: Width) extends LitArg(n, w) {
def name: String = "UInt" + width + "(\"h0" + num.toString(16) + "\")"
def minWidth: Int = 1 max n.bitLength
+ def cloneWithWidth(newWidth: Width): this.type = {
+ ULit(n, newWidth).asInstanceOf[this.type]
+ }
+
require(n >= 0, s"UInt literal ${n} is negative")
}
@@ -115,6 +127,10 @@ case class SLit(n: BigInt, w: Width) extends LitArg(n, w) {
s"asSInt(${ULit(unsigned, width).name})"
}
def minWidth: Int = 1 + n.bitLength
+
+ def cloneWithWidth(newWidth: Width): this.type = {
+ SLit(n, newWidth).asInstanceOf[this.type]
+ }
}
case class FPLit(n: BigInt, w: Width, binaryPoint: BinaryPoint) extends LitArg(n, w) {
@@ -123,6 +139,10 @@ case class FPLit(n: BigInt, w: Width, binaryPoint: BinaryPoint) extends LitArg(n
s"asFixedPoint(${ULit(unsigned, width).name}, ${binaryPoint.asInstanceOf[KnownBinaryPoint].value})"
}
def minWidth: Int = 1 + n.bitLength
+
+ def cloneWithWidth(newWidth: Width): this.type = {
+ FPLit(n, newWidth, binaryPoint).asInstanceOf[this.type]
+ }
}
case class IntervalLit(n: BigInt, w: Width, binaryPoint: BinaryPoint) extends LitArg(n, w) {
@@ -135,6 +155,10 @@ case class IntervalLit(n: BigInt, w: Width, binaryPoint: BinaryPoint) extends Li
IntervalRange.getBound(isClosed = true, BigDecimal(n)), IntervalRange.getRangeWidth(binaryPoint))
}
def minWidth: Int = 1 + n.bitLength
+
+ def cloneWithWidth(newWidth: Width): this.type = {
+ IntervalLit(n, newWidth, binaryPoint).asInstanceOf[this.type]
+ }
}
case class Ref(name: String) extends Arg