Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions docs/user/AutoMemories.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ To overrule the gate, list a `.memories` file in `ADDITIONAL_MEMORIES`:
"version": 1,
"memories": [
{
"name": "tag_array",
"name": "small_array",
"idiomatic": true,
"reason": "forced: the RTL provides no behavioral fallback"
"reason": "forced: a macro despite the floors"
}
]
}
Expand All @@ -92,11 +92,7 @@ To overrule the gate, list a `.memories` file in `ADDITIONAL_MEMORIES`:
Entries merge by name onto the detected set: fields the override
carries win, everything else (geometry, pins) is kept from detection. A
`.memories` entry naming a module the scanner never found is taken
whole — it must then describe its pins itself. The
`designs/asap7/tinyRocket` design demonstrates the forced-conversion
case: its `tag_array` wrapper is 4 entries deep (rejected by the gate)
but instantiates a module the sources never define, so flops are not an
option and the design forces conversion.
whole — it must then describe its pins itself.

## Generated views

Expand Down
43 changes: 43 additions & 0 deletions flow/designs/asap7/tinyRocket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
tinyRocket on asap7
-------------------

Rocket Chip's `TinyConfig` tile (`RocketTile`): a 32-bit Rocket core
with its instruction and data caches. It is the one ORFS design that
takes `AUTO_MEMORIES` end to end, and the quickest way to see what it
does with a real core: synthesis to global route in minutes.

What makes it unique among the designs:

- **Its memories are found, not hand-mapped.** The Rocket Chip generator
leaves the cache arrays as black boxes (`*_ext`); `memories.v` gives
them behavioral models in firtool's read-write port convention, and
`AUTO_MEMORIES` infers them, checks them against its macro floors and
generates FakeRAM `.lib`/`.lef` views for those that pass. Nothing is
mapped by hand, unlike nangate45's tinyRocket (a platform file mapping
each `*_ext` onto a fakeram macro) or the designs that instantiate
their macros explicitly.
- **SRAMs and a register file in one design, both identified by yosys.**
`results/.../memories.json`, the inventory, lists every memory yosys
infers and what became of it:

| memory | shape | becomes |
|---|---|---|
| `data_arrays_0_ext` (dcache data) | 64 x 32, one read-write port, 4 byte lanes | FakeRAM macro |
| `data_arrays_0_0_ext` (icache data) | 64 x 32, one read-write port | FakeRAM macro |
| `tag_array_ext` (icache tags) | 4 x 25 | flip-flops: below the macro floors |
| `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 |
| TileLink queue entries | 2 words each | flip-flops |

So the design exercises the SRAM path and shows the register file a
CPU core really has, side by side, which no other design does.
- **Fast turnaround.** A real core with macros, yet small enough to
iterate on: synthesis is about half a minute, floorplan to global route
a few minutes.

To see the inventory and the generated views after synthesis:

make DESIGN_CONFIG=designs/asap7/tinyRocket/config.mk synth
cat results/asap7/tinyRocket/base/memories.json
ls results/asap7/tinyRocket/base/memories/

`docs/user/AutoMemories.md` describes `AUTO_MEMORIES`.
18 changes: 7 additions & 11 deletions flow/designs/asap7/tinyRocket/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@ export DESIGN_NICKNAME = tinyRocket
export DESIGN_NAME = RocketTile
export PLATFORM = asap7

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

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

export AUTO_MEMORIES = 1
# tag_array (4x25) falls below the idiomatic-macro floors, but this RTL
# provides no behavioral fallback (the wrapper instantiates a
# tag_array_ext module the sources never define), so its conversion is
# forced via a .memories override.
export ADDITIONAL_MEMORIES = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/tag_array.memories

export CORE_UTILIZATION = 40
export CORE_MARGIN = 2

Expand Down
2 changes: 1 addition & 1 deletion flow/designs/asap7/tinyRocket/constraint.sdc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
current_design RocketTile

create_clock -name core_clock -period 1600 [get_ports {clock}]
create_clock -name core_clock -period 600 [get_ports {clock}]
67 changes: 67 additions & 0 deletions flow/designs/asap7/tinyRocket/memories.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Behavioral models of the memories the Rocket Chip generator leaves as
// black boxes (`*_ext`, firtool's read-write port convention), so the
// generic sources elaborate and AUTO_MEMORIES detects each memory and
// replaces it with a generated macro. nangate45 maps the same modules
// onto hand-made fakeram macros instead.
//
// One read-write port, written as firtool writes one: a write on the
// clock when enabled and in write mode, under the write mask; a read
// registers its address on the clock and reads from it, which yosys
// infers as a clocked read port, the SRAM shape AUTO_MEMORIES converts.

module data_arrays_0_ext(
input RW0_clk,
input [5:0] RW0_addr,
input RW0_en,
input RW0_wmode,
input [3:0] RW0_wmask,
input [31:0] RW0_wdata,
output [31:0] RW0_rdata
);
reg [31:0] Memory [0:63];
reg [5:0] raddr;
always @(posedge RW0_clk) begin : port
integer i;
if (RW0_en && !RW0_wmode) raddr <= RW0_addr;
if (RW0_en && RW0_wmode)
for (i = 0; i < 4; i = i + 1)
if (RW0_wmask[i]) Memory[RW0_addr][i*8 +: 8] <= RW0_wdata[i*8 +: 8];
end
assign RW0_rdata = Memory[raddr];
endmodule

module data_arrays_0_0_ext(
input RW0_clk,
input [5:0] RW0_addr,
input RW0_en,
input RW0_wmode,
input [0:0] RW0_wmask,
input [31:0] RW0_wdata,
output [31:0] RW0_rdata
);
reg [31:0] Memory [0:63];
reg [5:0] raddr;
always @(posedge RW0_clk) begin
if (RW0_en && !RW0_wmode) raddr <= RW0_addr;
if (RW0_en && RW0_wmode && RW0_wmask[0]) Memory[RW0_addr] <= RW0_wdata;
end
assign RW0_rdata = Memory[raddr];
endmodule

module tag_array_ext(
input RW0_clk,
input [1:0] RW0_addr,
input RW0_en,
input RW0_wmode,
input [0:0] RW0_wmask,
input [24:0] RW0_wdata,
output [24:0] RW0_rdata
);
reg [24:0] Memory [0:3];
reg [1:0] raddr;
always @(posedge RW0_clk) begin
if (RW0_en && !RW0_wmode) raddr <= RW0_addr;
if (RW0_en && RW0_wmode && RW0_wmask[0]) Memory[RW0_addr] <= RW0_wdata;
end
assign RW0_rdata = Memory[raddr];
endmodule
61 changes: 0 additions & 61 deletions flow/designs/asap7/tinyRocket/tag_array.memories

This file was deleted.

42 changes: 0 additions & 42 deletions flow/scripts/memories/schema_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
import json
import re
import sys
import tempfile
import unittest
Expand Down Expand Up @@ -117,46 +116,5 @@ def test_validate_emittable(self):
schema.validate_emittable(dataless)


FLOW_DIR = Path(__file__).resolve().parents[2]


def module_ports(verilog: Path, module: str) -> dict[str, tuple[str, int]]:
"""{name: (direction, width)} from an ANSI-style module header."""
ports = {}
in_header = False
for line in verilog.read_text().splitlines():
if line.startswith(f"module {module}("):
in_header = True
continue
if in_header:
if line.startswith(");"):
return ports
m = re.match(r"\s*(input|output)\s+(?:\[(\d+):0\])?\s*(\w+)", line)
if m:
direction, msb, name = m.groups()
ports[name] = (direction, int(msb) + 1 if msb else 1)
raise AssertionError(f"module {module} not found in {verilog}")


class TinyRocketTagArrayTest(unittest.TestCase):
"""tinyRocket's tag_array wrapper has no inferred memory for detection
to find, so its override is taken whole and must be emittable on its
own, with the pins of the module it replaces."""

def setUp(self):
path = FLOW_DIR / "designs/asap7/tinyRocket/tag_array.memories"
(self.mem,) = schema.merge([], schema.load(path))

def test_override_is_emittable(self):
schema.validate_emittable(self.mem)

def test_pins_match_the_rtl(self):
rtl = (
FLOW_DIR / "designs/src/tinyRocket/freechips.rocketchip.system.TinyConfig.v"
)
pins = {p.name: (p.direction, p.width) for p in self.mem.pins}
self.assertEqual(pins, module_ports(rtl, "tag_array"))


if __name__ == "__main__":
unittest.main()
Loading