-
Notifications
You must be signed in to change notification settings - Fork 230
feat: Add Parity Generator component #920
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughThis pull request adds a new ParityGenerator module to the simulator. It introduces a ParityGenerator class (extending CircuitElement) that creates configurable input nodes and a single output, computes parity (output is 1 when an odd number of inputs are 1), implements customSave, resolve, customDraw, and generateVerilog, and sets prototype metadata. The module is exported and registered in moduleSetup and added to simulator metadata. A Vitest spec (src/simulator/spec/parityGenerator.spec.js) tests initialization and 3-/4-input parity behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/simulator/src/metadata.ts`:
- Around line 63-64: The ParityGenerator currently implements odd parity but
issue `#586` requires even parity; update the ParityGenerator implementation so
its output bit makes the total count of 1s even (i.e., invert the existing
XOR-chain result or use XNOR logic), or alternatively add a configurable
parityMode property on ParityGenerator (e.g., "even" | "odd") and ensure
downstream code that constructs/uses ParityGenerator honors that flag; update
any tests or metadata entries referencing ParityGenerator to reflect the chosen
convention.
- Added ParityGenerator.js with XOR-based even parity logic - Added ParityGenerator.svg icon matching project style - Registered component in metadata.ts under Misc category - Added unit tests for parity calculations Closes CircuitVerse#586
0018b1a to
390b47d
Compare
|
Hi @Nihal4777 @tachyons parity generator feature is added, pls review this PR. |
|
@Nakshatra480 please fill in the PR description as per the template. Thanks! |
|
@naman79820 now is it ok? |

Fixes #586
Describe the changes you have made in this PR -
I've added a new
ParityGeneratorcomponent to the simulator. This module implements standard odd parity logic, where the output is high (1) if the number of high inputs is odd.Key changes include:
src/simulator/src/modules/ParityGenerator.jswhich extendsCircuitElement.moduleSetup.jsso it appears in the simulator's module list.src/simulator/spec/parityGenerator.spec.jswith unit tests covering initialization, bit width verification, and logic correctness for both odd and even input counts.Screenshots of the UI changes (If any) -
(The component renders as a standard rectangular circuit element with the label "Parity")
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
The simulator was missing a dedicated Parity Generator, which is a fundamental digital logic component.
My implementation approach was to extend the base
CircuitElementclass to ensure full compatibility with the existing rendering and simulation engine.resolve()method by iterating through the input nodes and applying an XOR operation (result ^= input). This is the standard definition of odd parity and scales efficiently with any number of inputs.changeInputSizemethod.generateVerilog()to map this component to the^(XOR) operator in Verilog export, ensuring designs using this component can be exported correctly.Checklist before requesting a review