Hardware module that is used to sequence n producers into 1 consumer.
Hardware module that is used to sequence n producers into 1 consumer. Priority is given to lower producer.
val arb = Module(new Arbiter(UInt(), 2)) arb.io.in(0) <> producer0.io.out arb.io.in(1) <> producer1.io.out consumer.io.in <> arb.io.out
IO bundle definition for an Arbiter, which takes some number of ready-valid inputs and outputs (selects) at most one.
Bit patterns are literals with masks, used to represent values with don't care bits.
Bit patterns are literals with masks, used to represent values with don't care bits. Equality comparisons will ignore don't care bits.
"b10101".U === BitPat("b101??") // evaluates to true.B "b10111".U === BitPat("b101??") // evaluates to true.B "b10001".U === BitPat("b101??") // evaluates to false.B
Used to generate an inline (logic directly in the containing Module, no internal Module is created) hardware counter.
Used to generate an inline (logic directly in the containing Module, no internal Module is created) hardware counter.
Typically instantiated with apply methods in object Counter
Does not create a new Chisel Module
// Using Scala Range API val (counterValue, counterWrap) = Counter(0 until 10 by 2) when (counterValue === 4.U) { ... }
val countOn = true.B // increment counter every clock cycle val (counterValue, counterWrap) = Counter(countOn, 4) when (counterValue === 3.U) { ... }
A concrete subclass of ReadyValidIO signaling that the user expects a "decoupled" interface: 'valid' indicates that the producer has put valid data in 'bits', and 'ready' indicates that the consumer is ready to accept the data this cycle.
A concrete subclass of ReadyValidIO signaling that the user expects a "decoupled" interface: 'valid' indicates that the producer has put valid data in 'bits', and 'ready' indicates that the consumer is ready to accept the data this cycle. No requirements are placed on the signaling of ready or valid.
Defines a set of unique UInt constants
Defines a set of unique UInt constants
Unpack with a list to specify an enumeration. Usually used with switch to describe a finite state machine.
val state_on :: state_off :: Nil = Enum(2) val current_state = WireDefault(state_off) switch (current_state) { is (state_on) { ... } is (state_off) { ... } }
A concrete subclass of ReadyValidIO that promises to not change the value of 'bits' after a cycle where 'valid' is high and 'ready' is low.
A concrete subclass of ReadyValidIO that promises to not change the value of 'bits' after a cycle where 'valid' is high and 'ready' is low. Additionally, once 'valid' is raised it will never be lowered until after 'ready' has also been raised.
A hardware array of elements that can hold values of different types/widths, unlike Vec which can only hold elements of the same type/width.
A hardware array of elements that can hold values of different types/widths, unlike Vec which can only hold elements of the same type/width.
val v = Wire(MixedVec(Seq(UInt(8.W), UInt(16.W), UInt(32.W)))) v(0) := 100.U(8.W) v(1) := 10000.U(16.W) v(2) := 101.U(32.W)
Pipeline module generator parameterized by data type and latency.
Pipeline module generator parameterized by data type and latency.
This defines a module with one input, enq
, and one output, deq
. The input and output are Valid interfaces
that wrap some Chisel type, e.g., a UInt or a Bundle. This generator will then chain together a number of
pipeline stages that all advance when the input Valid enq
fires. The output deq
Valid will fire only
when valid data has made it all the way through the pipeline.
As an example, to construct a 4-stage pipe of 8-bit UInts and connect it to a producer and consumer, you can use the following:
val foo = Module(new Pipe(UInt(8.W)), 4) pipe.io.enq := producer.io consumer.io := pipe.io.deq
If you already have the Valid input or the components of a Valid interface, it may be simpler to use the Pipe factory companion object. This, which Pipe internally utilizes, will automatically connect the input for you.
The ShiftRegister factory to generate a pipe without a Valid interface
Queue and the Queue factory for actual queues
Valid interface
Pipe factory for an alternative API
A hardware module implementing a Queue
A hardware module implementing a Queue
val q = Module(new Queue(UInt(), 16)) q.io.enq <> producer.io.out consumer.io.in <> q.io.deq
An I/O Bundle for Queues
Hardware module that is used to sequence n producers into 1 consumer.
Hardware module that is used to sequence n producers into 1 consumer. Producers are chosen in round robin order.
val arb = Module(new RRArbiter(UInt(), 2)) arb.io.in(0) <> producer0.io.out arb.io.in(1) <> producer1.io.out consumer.io.in <> arb.io.out
An I/O Bundle containing 'valid' and 'ready' signals that handshake the transfer of data stored in the 'bits' subfield.
An I/O Bundle containing 'valid' and 'ready' signals that handshake the transfer of data stored in the 'bits' subfield. The base protocol implied by the directionality is that the producer uses the interface as-is (outputs bits) while the consumer uses the flipped interface (inputs bits). The actual semantics of ready/valid are enforced via the use of concrete subclasses.
Implementation details for switch.
A Bundle that adds a valid
bit to some data.
A Bundle that adds a valid
bit to some data. This indicates that the user expects a "valid" interface between
a producer and a consumer. Here, the producer asserts the valid
bit when data on the bits
line contains valid
data. This differs from DecoupledIO or IrrevocableIO as there is no ready
line that the consumer can use
to put back pressure on the producer.
In most scenarios, the Valid
class will not be used directly. Instead, users will create Valid
interfaces
using the Valid factory.
the type of the data
Valid factory for concrete examples
Synonyms, moved from main package object - maintain scope.
Concatenates elements of the input, in order, together.
Concatenates elements of the input, in order, together.
Cat("b101".U, "b11".U) // equivalent to "b101 11".U Cat(myUIntWire0, myUIntWire1) Cat(Seq("b101".U, "b11".U)) // equivalent to "b101 11".U Cat(mySeqOfBits)
This factory adds a decoupled handshaking protocol to a data bundle.
Consumer - drives (outputs) ready, inputs valid and bits.
Producer - drives (outputs) valid and bits, inputs ready.
Create repetitions of the input using a tree fanout topology.
Create repetitions of the input using a tree fanout topology.
Fill(2, "b1000".U) // equivalent to "b1000 1000".U Fill(2, "b1001".U) // equivalent to "b1001 1001".U Fill(2, myUIntWire) // dynamic fill
Creates repetitions of each bit of the input in order.
Creates repetitions of each bit of the input in order.
FillInterleaved(2, "b1 0 0 0".U) // equivalent to "b11 00 00 00".U FillInterleaved(2, "b1 0 0 1".U) // equivalent to "b11 00 00 11".U FillInterleaved(2, myUIntWire) // dynamic interleaved fill FillInterleaved(2, Seq(true.B, false.B, false.B, false.B)) // equivalent to "b11 00 00 00".U FillInterleaved(2, Seq(true.B, false.B, false.B, true.B)) // equivalent to "b11 00 00 11".U
Implicit conversions to automatically convert scala.Boolean and scala.Int to Bool and UInt respectively
Factory adds an irrevocable handshaking protocol to a data bundle.
For each element in a list, muxes (looks up) between cases (one per list element) based on a common address.
For each element in a list, muxes (looks up) between cases (one per list element) based on a common address.
ListLookup(2.U, // address for comparison List(10.U, 11.U, 12.U), // default "row" if none of the following cases match Array(BitPat(2.U) -> List(20.U, 21.U, 22.U), // this "row" hardware-selected based off address 2.U BitPat(3.U) -> List(30.U, 31.U, 32.U)) ) // hardware-evaluates to List(20.U, 21.U, 22.U) // Note: if given address 0.U, the above would hardware evaluate to List(10.U, 11.U, 12.U)
This appears to be an odd, specialized operator that we haven't seen used much, and seems to be a holdover from chisel2. This may be deprecated and removed, usage is not recommended.
Returns the base-2 integer logarithm of an UInt.
Returns the base-2 integer logarithm of an UInt.
Log2(8.U) // evaluates to 3.U Log2(13.U) // evaluates to 3.U (truncation) Log2(myUIntWire)
The result is truncated, so e.g. Log2(13.U) === 3.U
Muxes between cases based on whether an address matches any pattern for a case.
Muxes between cases based on whether an address matches any pattern for a case. Similar to MuxLookup, but uses BitPat for address comparison.
This appears to be an odd, specialized operator that we haven't seen used much, and seems to be a holdover from chisel2. This may be deprecated and removed, usage is not recommended.
Create a MixedVec type, given element types.
Create a MixedVec type, given element types. Inputs must be Chisel types which have no value (not hardware types).
MixedVec with the given types.
Create a MixedVec wire with default values as specified, and type of each element inferred from those default values.
Create a MixedVec wire with default values as specified, and type of each element inferred from those default values.
This is analogous to VecInit.
MixedVec with given values assigned
MixedVecInit(Seq(100.U(8.W), 10000.U(16.W), 101.U(32.W)))
Builds a Mux tree out of the input signal vector using a one hot encoded select signal.
Builds a Mux tree out of the input signal vector using a one hot encoded select signal. Returns the output of the Mux tree.
val hotValue = chisel3.util.Mux1H(Seq( io.selector(0) -> 2.U, io.selector(1) -> 4.U, io.selector(2) -> 8.U, io.selector(4) -> 11.U, ))
results unspecified unless exactly one select signal is high
Given an association of values to enable signals, returns the first value with an associated high enable signal.
Given an association of values to enable signals, returns the first value with an associated high enable signal.
MuxCase(default, Array(c1 -> a, c2 -> b))
Creates a cascade of n Muxs to search for a key value.
Creates a cascade of n Muxs to search for a key value.
MuxLookup(idx, default, Array(0.U -> a, 1.U -> b))
Returns the bit position of the sole high bit of the input bitvector.
Returns the bit position of the sole high bit of the input bitvector.
Inverse operation of UIntToOH.
OHToUInt("b0100".U) // results in 2.U
assumes exactly one high bit, results undefined otherwise
A factory to generate a hardware pipe.
A factory to generate a hardware pipe. This can be used to delay Valid data by a design-time configurable number of cycles.
Here, we construct three different pipes using the different provided apply
methods and hook them up together. The
types are explicitly specified to show that these all communicate using Valid interfaces:
val in: Valid[UInt] = Wire(Valid(UInt(2.W))) /* A zero latency (combinational) pipe is connected to 'in' */ val foo: Valid[UInt] = Pipe(in.valid, in.bits, 0) /* A one-cycle pipe is connected to the output of 'foo' */ val bar: Valid[UInt] = Pipe(foo.valid, foo.bits) /* A two-cycle pipe is connected to the output of 'bar' */ val baz: Valid[UInt] = Pipe(bar, 2)
The ShiftRegister factory to generate a pipe without a Valid interface
Queue and the Queue factory for actual queues
Valid interface
Pipe class for an alternative API
Returns the number of bits set (value is 1 or true) in the input signal.
Returns the number of bits set (value is 1 or true) in the input signal.
PopCount(Seq(true.B, false.B, true.B, true.B)) // evaluates to 3.U PopCount(Seq(false.B, false.B, true.B, false.B)) // evaluates to 1.U PopCount("b1011".U) // evaluates to 3.U PopCount("b0010".U) // evaluates to 1.U PopCount(myUIntWire) // dynamic count
Returns the bit position of the least-significant high bit of the input bitvector.
Returns the bit position of the least-significant high bit of the input bitvector.
PriorityEncoder("b0110".U) // results in 1.U
Multiple bits may be high in the input.
Returns a bit vector in which only the least-significant 1 bit in the input vector, if any, is set.
Returns a bit vector in which only the least-significant 1 bit in the input vector, if any, is set.
PriorityEncoderOH(Seq(false.B, true.B, true.B, false.B)) // results in Seq(false.B, true.B, false.B, false.B)
Builds a Mux tree under the assumption that multiple select signals can be enabled.
Builds a Mux tree under the assumption that multiple select signals can be enabled. Priority is given to the first select signal.
val hotValue = chisel3.util.PriorityMux(Seq( io.selector(0) -> 2.U, io.selector(1) -> 4.U, io.selector(2) -> 8.U, io.selector(4) -> 11.U, ))
Returns the output of the Mux tree.
Factory for a generic hardware queue.
Factory for a generic hardware queue.
output (dequeue) interface from the queue
consumer.io.in <> Queue(producer.io.out, 16)
Returns the input in bit-reversed order.
Returns the input in bit-reversed order. Useful for little/big-endian conversion.
Reverse("b1101".U) // equivalent to "b1011".U Reverse("b1101".U(8.W)) // equivalent to "b10110000".U Reverse(myUIntWire) // dynamic reverse
The purpose of TransitName
is to improve the naming of some object created in a different scope by "transiting"
the name from the outer scope to the inner scope.
The purpose of TransitName
is to improve the naming of some object created in a different scope by "transiting"
the name from the outer scope to the inner scope.
Consider the example below. This shows three ways of instantiating MyModule
and returning the IO. Normally, the
instance will be named MyModule
. However, it would be better if the instance was named using the name of the val
that user provides for the returned IO. TransitName
can then be used to "transit" the name from the IO to
the module:
/* Assign the IO of a new MyModule instance to value "foo". The instance will be named "MyModule". */ val foo = Module(new MyModule).io /* Assign the IO of a new MyModule instance to value "bar". The instance will be named "bar". */ val bar = { val x = Module(new MyModule) TransitName(x.io, x) // TransitName returns the first argument } /* Assign the IO of a new MyModule instance to value "baz". The instance will be named "baz_generated". */ val baz = { val x = Module(new MyModule) TransitName.withSuffix("_generated")(x.io, x) // TransitName returns the first argument }
TransitName
helps library writers following the Factory
Method Pattern where modules may be instantiated inside an enclosing scope. For an example of this, see how the
Queue factory uses TransitName
in
Decoupled.scala factory.
Returns the one hot encoding of the input UInt.
Returns the one hot encoding of the input UInt.
UIntToOH(2.U) // results in "b0100".U
Factory for generating "valid" interfaces.
Factory for generating "valid" interfaces. A "valid" interface is a data-communicating interface between a producer and a consumer where the producer does not wait for the consumer. Concretely, this means that one additional bit is added to the data indicating its validity.
As an example, consider the following Bundle, MyBundle
:
class MyBundle extends Bundle { val foo = Output(UInt(8.W)) }
To convert this to a "valid" interface, you wrap it with a call to the Valid
companion object's
apply method:
val bar = Valid(new MyBundle)
The resulting interface is structurally equivalent to the following:
class MyValidBundle extends Bundle { val valid = Output(Bool()) val bits = Output(new MyBundle) }
In addition to adding the valid
bit, a Valid.fire method is also added that returns the valid
bit. This
provides a similarly named interface to DecoupledIO's fire.
Use to specify cases in a switch block, equivalent to a when block comparing to the condition variable.
Returns whether a Scala integer is a power of two.
Returns whether a Scala integer is a power of two.
isPow2(1) // returns true isPow2(2) // returns true isPow2(3) // returns false isPow2(4) // returns true
Compute the log2 of a Scala integer, rounded up.
Compute the log2 of a Scala integer, rounded up. Useful for getting the number of bits needed to represent some number of states (in - 1). To get the number of bits needed to represent some number n, use log2Ceil(n + 1).
Note: can return zero, and should not be used in cases where it may generate unsupported zero-width wires.
log2Ceil(1) // returns 0 log2Ceil(2) // returns 1 log2Ceil(3) // returns 2 log2Ceil(4) // returns 2
Compute the log2 of a Scala integer, rounded down, with min value of 1.
Compute the log2 of a Scala integer, rounded down, with min value of 1.
log2Down(1) // returns 1 log2Down(2) // returns 1 log2Down(3) // returns 1 log2Down(4) // returns 2
Compute the log2 of a Scala integer, rounded down.
Compute the log2 of a Scala integer, rounded down.
Can be useful in computing the next-smallest power of two.
log2Floor(1) // returns 0 log2Floor(2) // returns 1 log2Floor(3) // returns 1 log2Floor(4) // returns 2
Compute the log2 of a Scala integer, rounded up, with min value of 1.
Compute the log2 of a Scala integer, rounded up, with min value of 1. Useful for getting the number of bits needed to represent some number of states (in - 1), To get the number of bits needed to represent some number n, use log2Up(n + 1). with the minimum value preventing the creation of currently-unsupported zero-width wires.
Note: prefer to use log2Ceil when in is known to be > 1 (where log2Ceil(in) > 0). This will be deprecated when zero-width wires is supported.
log2Up(1) // returns 1 log2Up(2) // returns 1 log2Up(3) // returns 2 log2Up(4) // returns 2
Conditional logic to form a switch block.
Conditional logic to form a switch block. See is for the case API.
switch (myState) { is (state1) { // some logic here that runs when myState === state1 } is (state2) { // some logic here that runs when myState === state2 } }
(Since version 3.2) The unless conditional is deprecated, use when(!condition){...} instead
The util package provides extensions to core chisel for common hardware components and utility functions