Skip to content

Fix/divider correctness#299

Open
guosran wants to merge 2 commits into
tancheng:masterfrom
guosran:fix/divider-correctness
Open

Fix/divider correctness#299
guosran wants to merge 2 commits into
tancheng:masterfrom
guosran:fix/divider-correctness

Conversation

@guosran

@guosran guosran commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses #292 with a minimized divider operation fix. This PR updates DivRTL.py, its focused test, and lib/opt_type.py for the required REM opcodes.

Changes

  • Handle DIV/REM zero divisors deterministically in simulation.
  • Add REM and REM_CONST support.
  • Add concrete examples as inline test comments.

No ExclusiveDiv backpressure rewrite, new ports, or new interfaces are included.

@tancheng tancheng requested review from HobbitQia and yyan7223 June 21, 2026 06:34
Comment thread fu/single/ExclusiveDivRTL.py
@guosran guosran force-pushed the fix/divider-correctness branch from d5cc795 to ebf7843 Compare June 23, 2026 20:41
Comment thread fu/single/DivRTL.py Outdated
Comment thread fu/single/DivRTL.py Outdated
Comment thread fu/single/DivRTL.py Outdated
Comment thread fu/single/DivRTL.py Outdated
Comment thread fu/single/DivRTL.py Outdated
Comment thread fu/single/DivRTL.py Outdated
@guosran guosran force-pushed the fix/divider-correctness branch from 64516aa to 3f35760 Compare June 25, 2026 14:43
@guosran guosran changed the base branch from kernel-submit to master June 25, 2026 14:52
@guosran guosran marked this pull request as draft June 25, 2026 14:53
@tancheng

Copy link
Copy Markdown
Owner

Hi @guosran, "draft" means this is not yet ready for review, right?

@guosran

guosran commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @guosran, "draft" means this is not yet ready for review, right?

Not yet, just a few more things to be done.

@guosran guosran force-pushed the fix/divider-correctness branch 2 times, most recently from b862c12 to 160f768 Compare June 25, 2026 19:28
@guosran guosran force-pushed the fix/divider-correctness branch from 160f768 to 8c0df00 Compare June 25, 2026 19:46
@guosran guosran force-pushed the fix/divider-correctness branch from 8c0df00 to cf6ee08 Compare June 26, 2026 00:22
@guosran guosran marked this pull request as ready for review June 26, 2026 00:33
@guosran

guosran commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

Concrete example:
For REM, PyMTL translates % into generated Verilog successfully:

  if ( divisor != 32'd0 ) begin
    div_remainder = dividend % divisor;
  end
  else
    div_remainder = 32'd0;

I restored the exact quotient path and use guarded % for the remainder path.

Comment thread fu/single/DivRTL.py

s.div_quotient @= quotient
if s.divisor != 0:
s.div_remainder @= s.dividend % s.divisor

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

well, we already performed above calculation, then the s.div_remainder can just be:

s.div_remainder @= remainder

no?

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.

3 participants