Skip to content

Commit e93b665

Browse files
committed
Add an RFC for arbitrary Memory shapes.
1 parent 14e0a61 commit e93b665

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

text/0000-arbitrary-memory-shape.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
- Start Date: (fill me in with today's date, YYYY-MM-DD)
2+
- RFC PR: [amaranth-lang/rfcs#0000](https://github.com/amaranth-lang/rfcs/pull/0000)
3+
- Amaranth Issue: [amaranth-lang/amaranth#0000](https://github.com/amaranth-lang/amaranth/issues/0000)
4+
5+
# Arbitrary `Memory` shapes
6+
7+
## Summary
8+
[summary]: #summary
9+
10+
Extend `Memory` to support arbitrary element shapes.
11+
12+
## Motivation
13+
[motivation]: #motivation
14+
15+
`Memory` currently only supports plain unsigned elements, with the width set by the `width` argument.
16+
Extending this to allow arbitrary shapes eliminates the need for manual conversion when used to store signed data and value-castables.
17+
18+
## Guide-level explanation
19+
[guide-level-explanation]: #guide-level-explanation
20+
21+
The `width` argument to `Memory()` is replaced with `shape`, accepting anything that is `ShapeLike`.
22+
Since a plain bit width is `ShapeLike`, this is a direct superset of existing functionality.
23+
24+
If `shape` is shape-castable, each element passed to the `init` argument is passed through `shape.const()`.
25+
26+
Example:
27+
```python
28+
RGB = StructLayout({"r": 8, "g": 8, "b": 8})
29+
30+
palette = Memory(shape = RGB, depth = 16, init = [
31+
{"r": 0, "g": 0, "b": 0},
32+
{"r": 255, "g": 0, "b": 0},
33+
# ...
34+
])
35+
```
36+
37+
## Reference-level explanation
38+
[reference-level-explanation]: #reference-level-explanation
39+
40+
`Memory.__init__()` gets a new `shape` argument, accepting any `ShapeLike`.
41+
42+
The `width` argument to `Memory.__init__()` deprecated and removed in a later Amaranth version. Passing both `width` and `shape` is an error.
43+
44+
The `Memory.shape` attribute is added.
45+
46+
The `Memory.width` attribute is deprecated and removed in a later Amaranth version.
47+
48+
`ReadPort.data` and `WritePort.data` are updated to be `Signal(memory.shape)`.
49+
50+
`DummyPort.__init__()` gets a new `data_shape` argument. `data_width` is deprecated and removed in a later Amaranth version.
51+
52+
## Drawbacks
53+
[drawbacks]: #drawbacks
54+
55+
Churn.
56+
57+
## Rationale and alternatives
58+
[rationale-and-alternatives]: #rationale-and-alternatives
59+
60+
- This could also be accomplished by adding a wrapper around `Memory`.
61+
- A wrapper would result in more code to maintain than simply updating `Memory`, since both the memory object itself and the port objects would have to be wrapped.
62+
63+
## Prior art
64+
[prior-art]: #prior-art
65+
66+
None.
67+
68+
## Unresolved questions
69+
[unresolved-questions]: #unresolved-questions
70+
71+
- `Memory.width` is still meaningful, but is it useful enough that we should consider keeping it?
72+
73+
## Future possibilities
74+
[future-possibilities]: #future-possibilities
75+
76+
Once `Memory` is extended to support arbitrary shapes, it is natural that higher level constructs building on `Memory` like FIFOs gets the same treatment.

0 commit comments

Comments
 (0)