[PR #3200] [MERGED] Fix V_ADDC_U32 carry-out edge cases #3301

Closed
opened 2026-02-27 22:03:11 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/3200
Author: @OFFTKP
Created: 7/6/2025
Status: Merged
Merged: 7/7/2025
Merged by: @georgemoralis

Base: mainHead: cf


📝 Commits (2)

  • 0845fe2 Fix V_ADDC_U32 carry-out edge cases
  • f90ff77 Use IAddCarry instead

📊 Changes

1 file changed (+9 additions, -6 deletions)

View changed files

📝 src/shader_recompiler/frontend/translate/vector_alu.cpp (+9 -6)

📄 Description

Carry calculations in unsigned numbers work like this:

carry = result < src

It doesn't matter which of the two sources you check, because in unsigned addition when there's an overflow the result will be smaller than both sources, never just one.


In the case of add with carry, you need to check whether src1 + src2 overflows and whether (src1+src) + cf overflows separately.

The current implementation does result < src1 || result < src2. This doesn't check separately for the intermediate result of src1+src2 and only checks if the final result overflowed. This fails in cases where the intermediate result overflows but the final result doesn't.


Example where old implementation can fail:

src0 = 0xFFFF'FFFF
src1 = 0xFFFF'FFFF
carry_in = 1

result = 0xFFFF'FFFF + 0xFFFF'FFFF + 1 = 0xFFFF'FFFF

This previous implementation would check result < src0 (false) || result < src1 (false) and carry_out would be false


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/3200 **Author:** [@OFFTKP](https://github.com/OFFTKP) **Created:** 7/6/2025 **Status:** ✅ Merged **Merged:** 7/7/2025 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `cf` --- ### 📝 Commits (2) - [`0845fe2`](https://github.com/shadps4-emu/shadPS4/commit/0845fe2b2b7c6c7bc47ee0bcb44165e144a8b32a) Fix V_ADDC_U32 carry-out edge cases - [`f90ff77`](https://github.com/shadps4-emu/shadPS4/commit/f90ff7769f485c8bc4e86a3cd851a696ce485ced) Use IAddCarry instead ### 📊 Changes **1 file changed** (+9 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/shader_recompiler/frontend/translate/vector_alu.cpp` (+9 -6) </details> ### 📄 Description Carry calculations in unsigned numbers work like this: ``` carry = result < src ``` It doesn't matter which of the two sources you check, because in unsigned addition when there's an overflow the result will be smaller than both sources, never just one. --- In the case of add with carry, you need to check whether src1 + src2 overflows and whether (src1+src) + cf overflows separately. The current implementation does `result < src1 || result < src2`. This doesn't check separately for the intermediate result of src1+src2 and only checks if the final result overflowed. This fails in cases where the intermediate result overflows but the final result doesn't. --- Example where old implementation can fail: src0 = 0xFFFF'FFFF src1 = 0xFFFF'FFFF carry_in = 1 result = 0xFFFF'FFFF + 0xFFFF'FFFF + 1 = 0xFFFF'FFFF This previous implementation would check `result < src0 (false)` || `result < src1 (false)` and carry_out would be false --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:03:11 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#3301
No description provided.