Skip to content

Why? through memories: follow a value read from a memory - #24

Merged
dtt-github merged 1 commit into
mainfrom
feature/why-memory
Nov 6, 2026
Merged

dtt-github merged 1 commit into
mainfrom
feature/why-memory

Conversation

@dtt-github

Copy link
Copy Markdown
Owner

What

In Why is it this value?, a value read from a memory (assign dout = mem[rptr]) used to end the chain with mem = ?. Now it names the word that was read and lets you follow it back:

dout = 17 from cycle 1: line 35 of fifo4.v wrote it: assign dout = mem[rptr]
It used mem[0] = 17, rptr = 0.
mem[0] = 17 from cycle 1: line 27 of fifo4.v wrote it: mem[wptr] <= din
It ran because !rst_n was false (rst_n = 1), and do_wr was true (do_wr = 1). It used din = 17.

"Why wasn't it N?" lists the words read in the same way.

How

  • Simulator (wafer-sim):
    • Each memory word's changes are recorded like a signal's (SimResult::words, named tb.dut.mem[2], with what wrote each value).
    • Each time an assignment that reads memory words runs, it records which words it read (SimResult::word_reads, in Origin::words order). That log is capped at MAX_WORD_READS.
    • Only memories that are actually used get recorded.
  • WASM: new getters wordNames, wordWidths, wordTimes, wordValues, wordBy, wordReadTimes, wordReadOrigins and wordReadWords; words is added to the origins JSON.
  • Web: why.ts looks words up like signals and expands a memory read into the words read by the run that made the value.

Checks

  • New simulator test, memory_words_are_recorded_like_signals: a memory with a non-zero base index, an index expression, two word reads in one assignment, and a bit-select of a word.
  • Checked in the browser on the FIFO starter: dout → mem[0] → mem[wptr] <= din → din, as shown above.
  • fmt, clippy, workspace tests, typecheck and web build all pass.
  • Docs: user guide (design view), architecture and CHANGELOG.

🤖 Generated with Claude Code

…and its writer

"Why is it this value?" used to stop at a memory read with "mem = ?". The
simulator now records each memory word's changes like a signal's
(SimResult::words, named like tb.dut.mem[2]) and, each time an assignment
that reads memory words runs, which words it read (SimResult::word_reads,
Origin::words). The web app shows the word read ("It used mem[0] = 17,
rptr = 0") and follows it back to the line that stored it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dtt-github
dtt-github merged commit 78ebf32 into main Nov 6, 2026
2 checks passed
@dtt-github
dtt-github deleted the feature/why-memory branch November 6, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant