Skip to content

Commit 5a76f84

Browse files
authored
Merge pull request #4643 from oharboe/asap7-tinyrocket-memories
asap7/tinyRocket: behavioral models of the memories the generator leaves out
2 parents ef42174 + 1b5c6a0 commit 5a76f84

7 files changed

Lines changed: 121 additions & 122 deletions

File tree

‎docs/user/AutoMemories.md‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ To overrule the gate, list a `.memories` file in `ADDITIONAL_MEMORIES`:
8181
"version": 1,
8282
"memories": [
8383
{
84-
"name": "tag_array",
84+
"name": "small_array",
8585
"idiomatic": true,
86-
"reason": "forced: the RTL provides no behavioral fallback"
86+
"reason": "forced: a macro despite the floors"
8787
}
8888
]
8989
}
@@ -92,11 +92,7 @@ To overrule the gate, list a `.memories` file in `ADDITIONAL_MEMORIES`:
9292
Entries merge by name onto the detected set: fields the override
9393
carries win, everything else (geometry, pins) is kept from detection. A
9494
`.memories` entry naming a module the scanner never found is taken
95-
whole — it must then describe its pins itself. The
96-
`designs/asap7/tinyRocket` design demonstrates the forced-conversion
97-
case: its `tag_array` wrapper is 4 entries deep (rejected by the gate)
98-
but instantiates a module the sources never define, so flops are not an
99-
option and the design forces conversion.
95+
whole — it must then describe its pins itself.
10096

10197
## Generated views
10298

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
tinyRocket on asap7
2+
-------------------
3+
4+
Rocket Chip's `TinyConfig` tile (`RocketTile`): a 32-bit Rocket core
5+
with its instruction and data caches. It is the one ORFS design that
6+
takes `AUTO_MEMORIES` end to end, and the quickest way to see what it
7+
does with a real core: synthesis to global route in minutes.
8+
9+
What makes it unique among the designs:
10+
11+
- **Its memories are found, not hand-mapped.** The Rocket Chip generator
12+
leaves the cache arrays as black boxes (`*_ext`); `memories.v` gives
13+
them behavioral models in firtool's read-write port convention, and
14+
`AUTO_MEMORIES` infers them, checks them against its macro floors and
15+
generates FakeRAM `.lib`/`.lef` views for those that pass. Nothing is
16+
mapped by hand, unlike nangate45's tinyRocket (a platform file mapping
17+
each `*_ext` onto a fakeram macro) or the designs that instantiate
18+
their macros explicitly.
19+
- **SRAMs and a register file in one design, both identified by yosys.**
20+
`results/.../memories.json`, the inventory, lists every memory yosys
21+
infers and what became of it:
22+
23+
| memory | shape | becomes |
24+
|---|---|---|
25+
| `data_arrays_0_ext` (dcache data) | 64 x 32, one read-write port, 4 byte lanes | FakeRAM macro |
26+
| `data_arrays_0_0_ext` (icache data) | 64 x 32, one read-write port | FakeRAM macro |
27+
| `tag_array_ext` (icache tags) | 4 x 25 | flip-flops: below the macro floors |
28+
| `Rocket._T_288`, the integer register file | 31 x 32, two combinational reads, one write | flip-flops: an array inline in the core, the shape no SRAM model describes |
29+
| TileLink queue entries | 2 words each | flip-flops |
30+
31+
So the design exercises the SRAM path and shows the register file a
32+
CPU core really has, side by side, which no other design does.
33+
- **Fast turnaround.** A real core with macros, yet small enough to
34+
iterate on: synthesis is about half a minute, floorplan to global route
35+
a few minutes.
36+
37+
To see the inventory and the generated views after synthesis:
38+
39+
make DESIGN_CONFIG=designs/asap7/tinyRocket/config.mk synth
40+
cat results/asap7/tinyRocket/base/memories.json
41+
ls results/asap7/tinyRocket/base/memories/
42+
43+
`docs/user/AutoMemories.md` describes `AUTO_MEMORIES`.

‎flow/designs/asap7/tinyRocket/config.mk‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@ export DESIGN_NICKNAME = tinyRocket
22
export DESIGN_NAME = RocketTile
33
export PLATFORM = asap7
44

5-
# The generic tinyRocket sources only: unlike the nangate45 tinyRocket
6-
# there is no hand-written platform memory-mapping file and no
7-
# checked-in fakeram .lib/.lef — AUTO_MEMORIES detects the memory
8-
# wrapper modules and generates macro views for them instead.
5+
# The generic tinyRocket sources and behavioral models of the memories
6+
# the generator leaves as black boxes (memories.v): unlike the nangate45
7+
# tinyRocket there is no hand-written platform memory-mapping file and
8+
# no checked-in fakeram .lib/.lef -- AUTO_MEMORIES detects the memories
9+
# and generates macro views for them instead.
910
export VERILOG_FILES = $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/AsyncResetReg.v \
1011
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider2.v \
1112
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider3.v \
1213
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/plusarg_reader.v \
13-
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/freechips.rocketchip.system.TinyConfig.v
14+
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/freechips.rocketchip.system.TinyConfig.v \
15+
$(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/memories.v
1416

1517
export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/constraint.sdc
1618

1719
export AUTO_MEMORIES = 1
18-
# tag_array (4x25) falls below the idiomatic-macro floors, but this RTL
19-
# provides no behavioral fallback (the wrapper instantiates a
20-
# tag_array_ext module the sources never define), so its conversion is
21-
# forced via a .memories override.
22-
export ADDITIONAL_MEMORIES = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/tag_array.memories
23-
2420
export CORE_UTILIZATION = 40
2521
export CORE_MARGIN = 2
2622

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
current_design RocketTile
22

3-
create_clock -name core_clock -period 1600 [get_ports {clock}]
3+
create_clock -name core_clock -period 600 [get_ports {clock}]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Behavioral models of the memories the Rocket Chip generator leaves as
2+
// black boxes (`*_ext`, firtool's read-write port convention), so the
3+
// generic sources elaborate and AUTO_MEMORIES detects each memory and
4+
// replaces it with a generated macro. nangate45 maps the same modules
5+
// onto hand-made fakeram macros instead.
6+
//
7+
// One read-write port, written as firtool writes one: a write on the
8+
// clock when enabled and in write mode, under the write mask; a read
9+
// registers its address on the clock and reads from it, which yosys
10+
// infers as a clocked read port, the SRAM shape AUTO_MEMORIES converts.
11+
12+
module data_arrays_0_ext(
13+
input RW0_clk,
14+
input [5:0] RW0_addr,
15+
input RW0_en,
16+
input RW0_wmode,
17+
input [3:0] RW0_wmask,
18+
input [31:0] RW0_wdata,
19+
output [31:0] RW0_rdata
20+
);
21+
reg [31:0] Memory [0:63];
22+
reg [5:0] raddr;
23+
always @(posedge RW0_clk) begin : port
24+
integer i;
25+
if (RW0_en && !RW0_wmode) raddr <= RW0_addr;
26+
if (RW0_en && RW0_wmode)
27+
for (i = 0; i < 4; i = i + 1)
28+
if (RW0_wmask[i]) Memory[RW0_addr][i*8 +: 8] <= RW0_wdata[i*8 +: 8];
29+
end
30+
assign RW0_rdata = Memory[raddr];
31+
endmodule
32+
33+
module data_arrays_0_0_ext(
34+
input RW0_clk,
35+
input [5:0] RW0_addr,
36+
input RW0_en,
37+
input RW0_wmode,
38+
input [0:0] RW0_wmask,
39+
input [31:0] RW0_wdata,
40+
output [31:0] RW0_rdata
41+
);
42+
reg [31:0] Memory [0:63];
43+
reg [5:0] raddr;
44+
always @(posedge RW0_clk) begin
45+
if (RW0_en && !RW0_wmode) raddr <= RW0_addr;
46+
if (RW0_en && RW0_wmode && RW0_wmask[0]) Memory[RW0_addr] <= RW0_wdata;
47+
end
48+
assign RW0_rdata = Memory[raddr];
49+
endmodule
50+
51+
module tag_array_ext(
52+
input RW0_clk,
53+
input [1:0] RW0_addr,
54+
input RW0_en,
55+
input RW0_wmode,
56+
input [0:0] RW0_wmask,
57+
input [24:0] RW0_wdata,
58+
output [24:0] RW0_rdata
59+
);
60+
reg [24:0] Memory [0:3];
61+
reg [1:0] raddr;
62+
always @(posedge RW0_clk) begin
63+
if (RW0_en && !RW0_wmode) raddr <= RW0_addr;
64+
if (RW0_en && RW0_wmode && RW0_wmask[0]) Memory[RW0_addr] <= RW0_wdata;
65+
end
66+
assign RW0_rdata = Memory[raddr];
67+
endmodule

‎flow/designs/asap7/tinyRocket/tag_array.memories‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

‎flow/scripts/memories/schema_test.py‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
import json
3-
import re
43
import sys
54
import tempfile
65
import unittest
@@ -117,46 +116,5 @@ def test_validate_emittable(self):
117116
schema.validate_emittable(dataless)
118117

119118

120-
FLOW_DIR = Path(__file__).resolve().parents[2]
121-
122-
123-
def module_ports(verilog: Path, module: str) -> dict[str, tuple[str, int]]:
124-
"""{name: (direction, width)} from an ANSI-style module header."""
125-
ports = {}
126-
in_header = False
127-
for line in verilog.read_text().splitlines():
128-
if line.startswith(f"module {module}("):
129-
in_header = True
130-
continue
131-
if in_header:
132-
if line.startswith(");"):
133-
return ports
134-
m = re.match(r"\s*(input|output)\s+(?:\[(\d+):0\])?\s*(\w+)", line)
135-
if m:
136-
direction, msb, name = m.groups()
137-
ports[name] = (direction, int(msb) + 1 if msb else 1)
138-
raise AssertionError(f"module {module} not found in {verilog}")
139-
140-
141-
class TinyRocketTagArrayTest(unittest.TestCase):
142-
"""tinyRocket's tag_array wrapper has no inferred memory for detection
143-
to find, so its override is taken whole and must be emittable on its
144-
own, with the pins of the module it replaces."""
145-
146-
def setUp(self):
147-
path = FLOW_DIR / "designs/asap7/tinyRocket/tag_array.memories"
148-
(self.mem,) = schema.merge([], schema.load(path))
149-
150-
def test_override_is_emittable(self):
151-
schema.validate_emittable(self.mem)
152-
153-
def test_pins_match_the_rtl(self):
154-
rtl = (
155-
FLOW_DIR / "designs/src/tinyRocket/freechips.rocketchip.system.TinyConfig.v"
156-
)
157-
pins = {p.name: (p.direction, p.width) for p in self.mem.pins}
158-
self.assertEqual(pins, module_ports(rtl, "tag_array"))
159-
160-
161119
if __name__ == "__main__":
162120
unittest.main()

0 commit comments

Comments
 (0)