Skip to content

fix(ram): make verilog write behavior match simulator#817

Merged
092vk merged 3 commits intoCircuitVerse:mainfrom
aindree-2005:ram
Feb 24, 2026
Merged

fix(ram): make verilog write behavior match simulator#817
092vk merged 3 commits intoCircuitVerse:mainfrom
aindree-2005:ram

Conversation

@aindree-2005
Copy link
Contributor

@aindree-2005 aindree-2005 commented Jan 17, 2026

Fixes #816

Describe the changes you have made in this PR -

This PR fixes a WRITE-enable polarity mismatch between the RAM simulator and exported Verilog.

Screenshots of the UI changes (If any) -


Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected RAM write-enable behavior in the simulator: memory now writes when the write-enable signal is asserted (high) rather than when it was deasserted. This fixes incorrect write timing and ensures simulated memory operates as expected.

@netlify
Copy link

netlify bot commented Jan 17, 2026

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 7c565b3
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/699d28fa724fb30008cb69ec
😎 Deploy Preview https://deploy-preview-817--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 47
Accessibility: 66
Best Practices: 92
SEO: 82
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

Walkthrough

The embedded Verilog in src/simulator/src/sequential/RAM.js had its write condition inverted: the memory write statement mem[addr] = din now executes under if (we) instead of the previous if (!we). This single-line change flips write-enable semantics so writes occur when we is high. The change is a one-line edit in the RAM.js Verilog string.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses issue #816 by fixing the write-enable polarity, but does not fully implement the RESET behavior clarification or read behavior documentation required. Verify RESET behavior aligns with simulator and document read-during-write semantics, or update issue scope to reflect only the write polarity fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing RAM Verilog write behavior to match the simulator's expectations.
Out of Scope Changes check ✅ Passed The code change is narrowly scoped to the write-enable logic in RAM.js, directly addressing the polarity mismatch identified in issue #816.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Nihal4777 Nihal4777 requested a review from 092vk January 18, 2026 10:46
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> [!CAUTION]

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/simulator/src/sequential/RAM.js (1)

316-337: ⚠️ Potential issue | 🟠 Major

rst port is declared but has no implementation — a remaining gap from issue #816.

The linked issue explicitly requires that RESET behavior in the exported Verilog match the simulator. The simulator's resolve() (Lines 171–173) clears all memory when reset.value == 1, but the Verilog module declares rst as an input and never uses it. The same applies to dmp.

The always @(*) block should handle the reset case. A minimal fix would look like:

🛠️ Proposed fix to add rst support
     always @ (*) begin
+        if (rst) begin
+            integer i;
+            for (i = 0; i < 2**ADDR; i = i + 1)
+                mem[i] = 0;
+        end else
         if (we)
             mem[addr] = din;
     end

Note: resetting the entire array inside a combinational block is still non-idiomatic (synthesis tools may warn), but it would keep the simulation semantics consistent. The pre-existing comment at Lines 314–315 already acknowledges the clock-less design is unusual.

Would you like me to open a new issue or draft a more complete Verilog implementation (including reset and a note on dmp) to fully close #816?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/simulator/src/sequential/RAM.js` around lines 316 - 337, The Verilog
emitted by RAM.moduleVerilog() declares rst and dmp but never uses them, so
update moduleVerilog() to implement the simulator's reset semantics (matching
resolve() which clears mem when reset.value == 1): in the always @(*) block add
a branch that when rst is asserted it clears the entire mem (set mem[...] = 0
for all addresses) and otherwise performs the existing write-on-we behavior;
also decide how to handle dmp (either mirror rst or implement intended dump
behavior) and reference rst and dmp in the always block so both ports are used.
Ensure changes are made inside the module string returned by moduleVerilog() so
emitted Verilog matches the simulator's reset behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/simulator/src/sequential/RAM.js`:
- Around line 316-337: The Verilog emitted by RAM.moduleVerilog() declares rst
and dmp but never uses them, so update moduleVerilog() to implement the
simulator's reset semantics (matching resolve() which clears mem when
reset.value == 1): in the always @(*) block add a branch that when rst is
asserted it clears the entire mem (set mem[...] = 0 for all addresses) and
otherwise performs the existing write-on-we behavior; also decide how to handle
dmp (either mirror rst or implement intended dump behavior) and reference rst
and dmp in the always block so both ports are used. Ensure changes are made
inside the module string returned by moduleVerilog() so emitted Verilog matches
the simulator's reset behavior.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8a687 and 230d187.

📒 Files selected for processing (2)
  • src/simulator/src/sequential/RAM.js
  • v1/src/simulator/src/sequential/RAM.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • v1/src/simulator/src/sequential/RAM.js

@092vk 092vk merged commit bf71cde into CircuitVerse:main Feb 24, 2026
12 of 13 checks passed
@092vk
Copy link
Member

092vk commented Feb 24, 2026

@aindree-2005 Thanks for the PR, its merged now

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.

🐞 Bug: RAM Verilog export does not match simulator behavior

2 participants