UCSBarchlab / PyRTL

A collection of classes providing simple hardware specification, simulation, tracing, and testing suitable for teaching and research. Simplicity, usability, clarity, and extensibility are the overarching goals, rather than performance or optimization.
http://ucsbarchlab.github.io/PyRTL
BSD 3-Clause "New" or "Revised" License
253 stars 76 forks source link

@wire_struct and wire_matrix help with naming WireVector slices #439

Closed fdxmw closed 5 months ago

fdxmw commented 7 months ago
@wire_struct
class Byte:
    high: 4  # high is the four most significant bits.
    low: 4   # low is the four least significant bits.

This Byte @wire_struct can be instantiated two ways, by providing a value for each component:

  byte = Byte(high=0xA, low=0xB)

or by providing a value for the entire Byte:

  byte = Byte(Byte=0xAB)

After construction, byte is a WireVector representing the entire Byte (all 8 wires), byte.high is a WireVector representing the 4 most significant bits, and byte.low is a WireVector representing the 4 least significant bits.

wire_matrix is similar to @wire_struct, except that the slices are numbered instead of named, and all slices must share the same type:

# Four slices, each slice has bitwidth 8.
Word = wire_matrix(component_schema=8, size=4)
w = Word(values=[0x89ABCDEF])
print(w[0].bitwidth)  # Prints 8.

@wire_struct and wire_matrix can be composed arbitrarily, so you can have a two-dimensional array of Bytes for example.

@wire_struct and wire_matrix have additional features. See the documentation for details.

codecov-commenter commented 6 months ago

Codecov Report

Attention: Patch coverage is 97.57282% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 91.26%. Comparing base (c8a7d75) to head (55044e2).

Files Patch % Lines
pyrtl/wire.py 94.25% 5 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## development #439 +/- ## =============================================== + Coverage 90.92% 91.26% +0.33% =============================================== Files 24 24 Lines 6139 6341 +202 =============================================== + Hits 5582 5787 +205 + Misses 557 554 -3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.