SparseVec

chisel3.util.SparseVec
See theSparseVec companion object
class SparseVec[A <: Data](size: Int, gen: => A, indices: Seq[Int], defaultValue: Type = ..., outOfBoundsValue: Type = ...) extends Record

A sparse vector. Under the hood, this is a Record that can be dynamically indexed as if it were a dense Vec.

SparseVec has the usual trappings of a Vec. It has a size and a gen type. However, it also has an indices argument. This indicates the indices at which the SparseVec is allowed to have data. Additionally, the behavior of a SparseVec around what happens if a value is read from a value not in the indices:

  • defaultValue sets the default value that is read from an index between the zeroth index and the largest value in indices that is not in the indices.
  • outOfBoundsValue sets the behavior when reading a value larger than the largest value in indices.

The reason for this configurability is to enable exact compatibility with an equivalent dense Vec of the same size and initialized to a given value. Specifically, use SparseVec.DefaultValueBehavior.DynamicIndexEquivalent and SparseVec.OutOfBoundsBehavior.First to make this behave as such:

  1. The SparseVec has a default value of how a FIRRTL compiler compiles DontCare for a dynamic index.

  2. The SparseVec out-of-bounds behavior returns the zeroth element if a zeroth element exists. Otherwise, it returns a DontCare.

Note that this DontCare is likely not a true "don't care" that will be optimized to any value. Instead, it is a value equal to how a FIRRTL compiler chooses to optimize a dynamic index into a wire vector initialized with a DontCare. This has historically been zero.

Once created, a SparseVec can be written or read from as a Record. It may also be read from using a dynamic index, but not written to. Neither the default value nor the out-of-bounds value may be written to. The dynamic index type is conifgurable and may be one of:

A SparseVec will take up storage equal to the size of the provided mapping argument with one additional slot for the default value, if one is needed.

Value parameters

defaultValue

the default value behavior when accessing an index not in the indices

gen

the element type of the vector

indices

the indices of the vector which are valid

outOfBoundsValue

the out-of-bounds behavior when accessing an index larger than the largest value in indices

size

the apparent size of the vector

Attributes

Companion
object
Source
SparseVec.scala
Graph
Supertypes
class Record
trait Selectable
trait Aggregate
class Data
trait InstanceId
class Object
trait Matchable
class Any
Show all

Members list

Grouped members

connection

final def :=(that: => Data)(implicit sourceInfo: SourceInfo): Unit

The "strong connect" operator.

The "strong connect" operator.

For chisel3._, this operator is mono-directioned; all sub-elements of this will be driven by sub-elements of that.

  • Equivalent to this :#= that

For Chisel._, this operator connections bi-directionally via emitting the FIRRTL.<=

  • Equivalent to this :<>= that

Value parameters

that

the Data to connect from

Attributes

Inherited from:
Data
Source
Data.scala
final def <>(that: => Data)(implicit sourceInfo: SourceInfo): Unit

The "bulk connect operator", assigning elements in this Vec from elements in a Vec.

The "bulk connect operator", assigning elements in this Vec from elements in a Vec.

For chisel3._, uses the chisel3.internal.BiConnect algorithm; sub-elements of thatmay end up driving sub-elements ofthis`

  • Complicated semantics, hard to write quickly, will likely be deprecated in the future

For Chisel._, emits the FIRRTL.<- operator

  • Equivalent to this :<>= that without the restrictions that bundle field names and vector sizes must match

Value parameters

that

the Data to connect from

Attributes

Inherited from:
Data
Source
Data.scala

Value members

Constructors

final def this(gen: => A, indices: Seq[Int], defaultValue: Type, outOfBoundsValue: Type)

An alternative constructure to SparseVec where the size of the vector is automatically set to the maximum value in the indices.

An alternative constructure to SparseVec where the size of the vector is automatically set to the maximum value in the indices.

Value parameters

defaultValue

the default value behavior when accessing an index not in the indices

gen

the element type of the vector

indices

the indices of the vector which are valid

outOfBoundsValue

the out-of-bounds behavior when accessing an index larger than the largest value in indices

Attributes

Source
SparseVec.scala

Concrete methods

def apply(addr: UInt, lookupType: Type = ...)(implicit sourceinfo: SourceInfo): A

Read a value from a SparseVec using one of several possible lookup types. The returned value is read-only.

Read a value from a SparseVec using one of several possible lookup types. The returned value is read-only.

Value parameters

addr

the address of the value to read from the vec

lookupType

the type of lookup, e.g., binary, one-hot, or when-based

sourceinfo

implicit source locator information

Attributes

Returns

a read-only value from the specified address

Throws
ChiselException

if the returned value is written to

Source
SparseVec.scala

Inherited methods

protected def _cloneTypeImpl: Record

Implementation of cloneType that is [optionally for Record] overridden by the compiler plugin

Implementation of cloneType that is [optionally for Record] overridden by the compiler plugin

Attributes

Note

This should never be overridden or called in user-code

Inherited from:
Record
Source
Aggregate.scala
override protected def _fromUInt(that: UInt)(implicit sourceInfo: SourceInfo): Data

Return a value of this type from a UInt type. Internal implementation for asTypeOf.

Return a value of this type from a UInt type. Internal implementation for asTypeOf.

Protected so that it can be implemented by the external FixedPoint library

Attributes

Definition Classes
Inherited from:
Aggregate
Source
Aggregate.scala
protected def _typeNameConParams: Iterable[Any]

The list of parameter accessors used in the constructor of this chisel3.Record.

The list of parameter accessors used in the constructor of this chisel3.Record.

Attributes

Note

This is automatically overridden via the compiler plugin for user-defined bundles that mix-in chisel3.experimental.HasAutoTypename, and is meant for internal Chisel use only. Can not be manually overridden by users, or else an error will be thrown.

This lives in Record rather than the chisel3.experimental.HasAutoTypename trait, due to compiler implementation details preventing us from overriding a definition within a trait via the compiler plugin

Inherited from:
Record
Source
Aggregate.scala
def asTypeOf[T <: Data](that: T)(using SourceInfo): T

Does a reinterpret cast of the bits in this node into the format that provides. Returns a new Wire of that type. Does not modify existing nodes.

Does a reinterpret cast of the bits in this node into the format that provides. Returns a new Wire of that type. Does not modify existing nodes.

x.asTypeOf(that) performs the inverse operation of x := that.toBits.

Attributes

Note

bit widths are NOT checked, may pad or drop bits from input

that should have known widths

Inherited from:
DataIntf (hidden)
Source
DataIntf.scala
def asUInt: UInt

Reinterpret cast to UInt.

Reinterpret cast to UInt.

Attributes

Note

value not guaranteed to be preserved: for example, a SInt of width 3 and value -1 (0b111) would become an UInt with value 7

Aggregates are recursively packed with the first element appearing in the least-significant bits of the result.

Inherited from:
DataIntf (hidden)
Source
DataIntf.scala
override def autoSeed(name: String): Data.this.type

Takes the last seed suggested. Multiple calls to this function will take the last given seed, unless this HasId is a module port (see overridden method in Data.scala).

Takes the last seed suggested. Multiple calls to this function will take the last given seed, unless this HasId is a module port (see overridden method in Data.scala).

If the final computed name conflicts with the final name of another signal, the final name may get uniquified by appending a digit at the end of the name.

Is a lower priority than suggestName, in that regardless of whether autoSeed was called, suggestName will always take precedence if it was called.

Value parameters

seed

Seed for the name of this component

Attributes

Returns

this object

Definition Classes
Data -> HasId
Inherited from:
Data
Source
Data.scala
protected def checkingLitOption(checkForDontCares: Boolean): Option[BigInt]

Attributes

Inherited from:
Aggregate
Source
Aggregate.scala
def className: String

Name for Pretty Printing

Name for Pretty Printing

Attributes

Inherited from:
Record
Source
Aggregate.scala
override def cloneType: Record.this.type

Internal API; Chisel users should look at chisel3.chiselTypeOf(...).

Internal API; Chisel users should look at chisel3.chiselTypeOf(...).

cloneType must be defined for any Chisel object extending Data. It is responsible for constructing a basic copy of the object being cloned.

Attributes

Returns

a copy of the object.

Definition Classes
Inherited from:
Record
Source
Aggregate.scala
override def containsAFlipped: Boolean

Attributes

Definition Classes
Inherited from:
Record
Source
Aggregate.scala
override def equals(that: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
HasId -> Any
Inherited from:
HasId (hidden)
Source
Builder.scala
override def getElements: Seq[Data]

Returns a Seq of the immediate contents of this Aggregate, in order.

Returns a Seq of the immediate contents of this Aggregate, in order.

Attributes

Definition Classes
Inherited from:
Record
Source
Aggregate.scala
final def getWidth: Int

Returns the width, in bits, if currently known.

Returns the width, in bits, if currently known.

Attributes

Inherited from:
Data
Source
Data.scala
def hasSeed: Boolean

Attributes

Returns

Whether either autoName or suggestName has been called

Inherited from:
HasId (hidden)
Source
Builder.scala
override def hashCode: Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
HasId -> Any
Inherited from:
HasId (hidden)
Source
Builder.scala
def instanceName: String

Attributes

Inherited from:
HasId (hidden)
Source
Builder.scala
def isLit: Boolean

Attributes

Inherited from:
Data
Source
Data.scala
final def isWidthKnown: Boolean

Returns whether the width is currently known.

Returns whether the width is currently known.

Attributes

Inherited from:
Data
Source
Data.scala
override def litOption: Option[BigInt]

Return an Aggregate's literal value if it is a literal, None otherwise. If any element of the aggregate is not a literal (or DontCare), the result isn't a literal.

Return an Aggregate's literal value if it is a literal, None otherwise. If any element of the aggregate is not a literal (or DontCare), the result isn't a literal.

Attributes

Returns

an Aggregate's literal value if it is a literal, None otherwise.

Note

DontCare is allowed and will be replaced with 0. Use litValue to disallow DontCare.

Definition Classes
Inherited from:
Aggregate
Source
Aggregate.scala
override def litValue: BigInt

Return an Aggregate's literal value if it is a literal, otherwise an exception is thrown. If any element of the aggregate is not a literal with a defined width, the result isn't a literal.

Return an Aggregate's literal value if it is a literal, otherwise an exception is thrown. If any element of the aggregate is not a literal with a defined width, the result isn't a literal.

Attributes

Returns

an Aggregate's literal value if it is a literal, exception otherwise.

Definition Classes
Inherited from:
Aggregate
Source
Aggregate.scala
def parentModName: String

Attributes

Inherited from:
HasId (hidden)
Source
Builder.scala
def parentPathName: String

Attributes

Inherited from:
HasId (hidden)
Source
Builder.scala
def pathName: String

Attributes

Inherited from:
HasId (hidden)
Source
Builder.scala
def suggestName(seed: => String): HasId.this.type

Takes the first seed suggested. Multiple calls to this function will be ignored. If the final computed name conflicts with another name, it may get uniquified by appending a digit at the end.

Takes the first seed suggested. Multiple calls to this function will be ignored. If the final computed name conflicts with another name, it may get uniquified by appending a digit at the end.

Is a higher priority than autoSeed, in that regardless of whether autoSeed was called, suggestName will always take precedence.

Value parameters

seed

The seed for the name of this component

Attributes

Returns

this object

Inherited from:
HasId (hidden)
Source
Builder.scala

Returns a FIRRTL IsMember that refers to the absolute path to this object in the elaborated hardware graph

Returns a FIRRTL IsMember that refers to the absolute path to this object in the elaborated hardware graph

Attributes

Inherited from:
NamedComponent (hidden)
Source
Builder.scala
final def toNamed: ComponentName

Returns a FIRRTL ComponentName that references this object

Returns a FIRRTL ComponentName that references this object

Attributes

Note

Should not be called until circuit elaboration is complete

Inherited from:
NamedComponent (hidden)
Source
Builder.scala

Default "pretty-print" implementation Analogous to printing a Map Results in "$className(elt0.name -> elt0.value, ...)"

Default "pretty-print" implementation Analogous to printing a Map Results in "$className(elt0.name -> elt0.value, ...)"

Attributes

Inherited from:
Record
Source
Aggregate.scala
final def toRelativeTarget(root: Option[BaseModule]): ReferenceTarget

Returns a FIRRTL ReferenceTarget that references this object, relative to an optional root.

Returns a FIRRTL ReferenceTarget that references this object, relative to an optional root.

If root is defined, the target is a hierarchical path starting from root.

If root is not defined, the target is a hierarchical path equivalent to toAbsoluteTarget.

Attributes

Note

If root is defined, and has not finished elaboration, this must be called within atModuleBodyEnd.

The NamedComponent must be a descendant of root, if it is defined.

This doesn't have special handling for Views.

Inherited from:
NamedComponent (hidden)
Source
Builder.scala

Returns a FIRRTL ReferenceTarget that references this object, relative to an optional root.

Returns a FIRRTL ReferenceTarget that references this object, relative to an optional root.

If root is defined, the target is a hierarchical path starting from root.

If root is not defined, the target is a hierarchical path equivalent to toAbsoluteTarget.

Attributes

Note

If root is defined, and has not finished elaboration, this must be called within atModuleBodyEnd.

The NamedComponent must be a descendant of root, if it is defined.

This doesn't have special handling for Views.

Inherited from:
NamedComponent (hidden)
Source
Builder.scala
override def toString: String

The collection of chisel3.Data

The collection of chisel3.Data

This underlying datastructure is a ListMap because the elements must remain ordered for serialization/deserialization. Elements added later are higher order when serialized (this is similar to Vec). For example:

 // Assume we have some type MyRecord that creates a Record from the ListMap
 val record = MyRecord(ListMap("fizz" -> UInt(16.W), "buzz" -> UInt(16.W)))
 // "buzz" is higher order because it was added later than "fizz"
 record("fizz") := "hdead".U
 record("buzz") := "hbeef".U
 val uint = record.asUInt
 assert(uint === "hbeefdead".U) // This will pass

Attributes

Definition Classes
Record -> Any
Inherited from:
Record
Source
Aggregate.scala

Returns a FIRRTL ReferenceTarget that references this object

Returns a FIRRTL ReferenceTarget that references this object

Attributes

Note

Should not be called until circuit elaboration is complete

Inherited from:
NamedComponent (hidden)
Source
Builder.scala
def typeName: String

A non-ambiguous name of this Data for use in generated Verilog names

A non-ambiguous name of this Data for use in generated Verilog names

Attributes

Inherited from:
Data
Source
Data.scala
final def widthOption: Option[Int]

Returns Some(width) if the width is known, else None.

Returns Some(width) if the width is known, else None.

Attributes

Inherited from:
Data
Source
Data.scala

Concrete fields

final override val elements: VectorMap[String, A]

Attributes

Source
SparseVec.scala