Repository navigation
feat(cache): enable instruction-only L1 builds through Nix #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
murdoa
wants to merge
6
commits into
LilithSemi:master
Choose a base branch
from
murdoa:feat/nix-instruction-only-l1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca33063
chore(deps): pin Harbor physical-cache scaling prerequisite
murdoa da5f4d1
feat(cache): opt physical L1 into larger data-cache capacities
murdoa 3bbe44c
test(cache): exercise physical cache capacities and index banks
murdoa 039d89c
feat(cache): support instruction-only L1 consumers
murdoa 3f6ee55
test(cache): cover instruction-only cache behavior
murdoa c05b911
feat(nix): expose instruction-only CPU cache builds
murdoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Instruction-only L1 builds | ||
|
|
||
| Select instruction-only caching through the existing SoC derivation: | ||
|
|
||
| ```nix | ||
| river-hdl.mkSoC { | ||
| socName = "instruction_only_soc"; | ||
| cores = [ "rc1-s" ]; | ||
| memories = [ "0x80000000:4K:sram" ]; | ||
| instructionOnlyCache = true; | ||
| } | ||
| ``` | ||
|
|
||
| The option passes `--instruction-only-cache` to `river-genip`. Direct CLI use: | ||
|
|
||
| ```sh | ||
| river-genip --core rc1-s --device sram:0x80000000:4K \ | ||
| --instruction-only-cache --output output | ||
| ``` | ||
|
|
||
| It selects a 64-byte, direct-mapped I-cache with 8-byte lines and **no D-cache**. | ||
| All data accesses bypass the cache. Omitting the option (or setting it to false | ||
| in Nix) preserves the selected tier's existing defaults; it does not select an | ||
| uncached CPU. | ||
|
|
||
| The switch applies to all harts. Supported profiles are `rc1-n`, `rc1-mi`, | ||
| `rc1-s`, and `rc1-f`, with the same XLEN throughout the SoC. The out-of-order | ||
| `rc1-m` profile is rejected for this option. | ||
|
|
||
| For the RV64 physical-cache path, only explicitly declared `sram` and `dram` | ||
| windows are eligible for instruction caching. The existing physical stage | ||
| requires the complete refill line to fit in a RAM PMA after translation and | ||
| permission checks. MMIO, flash, PSRAM, generated boot ROM and other unlisted | ||
| addresses bypass this path. RAM overlapping another declared bus device is | ||
| rejected. These PMAs do not advertise atomics or misaligned access support. | ||
| The legacy bare instruction-cache path retains its existing behavior. | ||
|
|
||
| This option does not change cache sizes on existing builds, enable cached | ||
| misaligned loads, change core ISA/pipeline profiles, or change board defaults. | ||
| It is not a timing or FPGA-boot guarantee. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/river_emulator/test/instruction_only_cache_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import 'package:river/river.dart'; | ||
| import 'package:river_emulator/river_emulator.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| class _Memory extends DeviceAccessor { | ||
| final bytes = <int, int>{}; | ||
| int reads = 0, writes = 0; | ||
|
|
||
| void putWord(int address, int value) { | ||
| for (var i = 0; i < 4; i++) { | ||
| bytes[address + i] = (value >> (8 * i)) & 255; | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Future<int> read(int addr, int width) async { | ||
| reads++; | ||
| var value = 0; | ||
| for (var i = 0; i < width; i++) { | ||
| value |= (bytes[addr + i] ?? 0) << (8 * i); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| @override | ||
| Future<void> write(int addr, int value, int width) async { | ||
| writes++; | ||
| for (var i = 0; i < width; i++) { | ||
| bytes[addr + i] = (value >> (8 * i)) & 255; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void main() { | ||
| test( | ||
| 'emulator instruction-only cache retains fetches but not RAM data', | ||
| () async { | ||
| final memory = _Memory() | ||
| ..putWord(0, 0x13) | ||
| ..putWord(0x100, 0x1111); | ||
| final core = RiverCore( | ||
| RiverCoreConfigV1.micro( | ||
| mmu: HarborMmuConfig( | ||
| mxlen: RiscVMxlen.rv32, | ||
| pagingModes: const [RiscVPagingMode.bare], | ||
| tlbLevels: const [], | ||
| pmp: HarborPmpConfig.none, | ||
| ), | ||
| interrupts: [], | ||
| clock: const HarborClockConfig( | ||
| name: 'test', | ||
| rate: HarborFixedClockRate(100000000), | ||
| ), | ||
| l1cache: const HarborL1CacheConfig.instructionOnly( | ||
| HarborL1iCacheConfig(size: 64, ways: 1, lineSize: 16), | ||
| ), | ||
| ), | ||
| memDevices: {const BusAddressRange(0, 4096): memory}, | ||
| ); | ||
| core.reset(); | ||
| expect(core.l1i, isNotNull); | ||
| expect(core.l1d, isNull); | ||
| expect(await core.fetch(0), 0x13); | ||
| final coldReads = memory.reads; | ||
| memory.putWord(0, 0x00100093); | ||
| expect(await core.fetch(0), 0x13); | ||
| expect(memory.reads, coldReads); | ||
| expect(await core.read(0x100, 4), 0x1111); | ||
| memory.putWord(0x100, 0x2222); | ||
| expect(await core.read(0x100, 4), 0x2222); | ||
| expect(memory.reads, coldReads + 2); | ||
| await core.write(0x104, 0x3333, 4); | ||
| expect(memory.writes, 1); | ||
| expect(await core.read(0x104, 4), 0x3333); | ||
| core.reset(); | ||
| expect(await core.fetch(0), 0x00100093); | ||
| }, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a properly of the River Core config, not a genip flag.