Skip to content

[hardware] 🐛 Fix vaadd/vasub results on overflow - #513

Open
davidharrishmc wants to merge 1 commit into
pulp-platform:mainfrom
davidharrishmc:fix/vaadd-overflow
Open

davidharrishmc wants to merge 1 commit into
pulp-platform:mainfrom
davidharrishmc:fix/vaadd-overflow

Conversation

@davidharrishmc

Copy link
Copy Markdown

Caution

This pull request was generated by an AI assistant (Claude Code) and has not been reviewed by a human. Please review it with that in mind.

Fixes #228. vaadd/vasub computed the SEW-bit sum or difference without the extra bit, so signed overflow flipped the sign of the result, and vasubu dropped the borrow. Both operands are now extended by one bit (sign for vaadd/vasub, zero for vaaddu/vasubu) and the result is bits SEW:1 plus the rounding increment.

Verification (Verilator, NrLanes=4, VLEN=512): vaadd.vv 0x8c+0xe4 gives 0xb8 (main: 0x38), vasub.vv 0x80-0x7f gives 0x81 (main: 0x01), vasubu.vv 0x00-0x02 gives 0xff (main: 0x7f).

Changelog

Fixed

Checklist

  • Automated tests pass (Ara's own test suite was not run; see Verification)
  • Changelog updated
  • Code style guideline is observed

The averaging add/subtract computed the SEW-bit sum or difference without the extra bit, so
signed overflow flipped the sign of the result (vaadd 0x8c+0xe4 gave 0x38, not 0xb8) and vasub and
vasubu were wrong whenever the difference overflowed. Extend both operands by one bit (sign for
vaadd/vasub, zero for vaaddu/vasubu) and take bits SEW:1 plus the rounding increment.

Fixes pulp-platform#228

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: David Harris <David_Harris@hmc.edu>

This branch has not been deployed

No deployments
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.

Issue in vector single-width averaging add and subtract instructions: wrong results

1 participant