fix(relinker): lower legacy packed reciprocal register instructions #2377

Closed
Scramblrrrr wants to merge 1 commit from upstream-pr/2377 into main
Scramblrrrr commented 2026-10-09 16:50:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-09T16:50:48Z.


What

--to-intel leaves legacy SSE register forms of RSQRTPS and RCPPS native, although it already replaces their VEX.128 equivalents to avoid reciprocal approximation differences. This PR extends the existing lowering to those legacy register forms, including REX-extended registers and equal source/destination operands.

The gap is recorded in TechnicalDebt: legacy forms retain the host approximation. The same entry documents why the existing VEX lowering uses division and square root: an approximate reciprocal square root of 1.0 can remain below 1.0 after refinement. This change applies the existing policy to SSE code; it does not reproduce AMD's approximation tables.

Instruction form Before After
Legacy register RSQRTPS Native approximation Existing SQRTPS then DIVPS lowering; upper YMM bits preserved
Legacy register RCPPS Native approximation Existing DIVPS lowering; upper YMM bits preserved
VEX.128 register equivalents Existing lowering; upper YMM bits cleared Same behavior

For example, a supported legacy RSQRTPS with all input lanes equal to 1.0 now produces exactly 1.0 in every lane, through the same arithmetic used for its VEX equivalent.

Implementation:

  • Rename the internal decoder to DecodeReciprocal, accept legacy register encodings with an optional REX prefix, and record whether the instruction uses VEX.
  • Reuse ReciprocalLowering and the existing scratch-register spill/restore path. Emit a legacy result move for RCPPS, and avoid the final VEX move for legacy RSQRTPS, so upper YMM bits remain intact.
  • Report RSQRTPS/RCPPS separately from their VEX equivalents in conversion diagnostics. Support mixed legacy/VEX sequences through the existing out-of-line sequence builder.
  • Update the corresponding TechnicalDebt entry to describe the additional supported forms and register behavior.

The substitution remains optional. Sites shorter than the five-byte jump absorb movable following instructions, or stay native when a jump cannot fit safely. Scalar, memory and 256-bit forms retain their existing behavior. No new dependencies or system-library exports are added.

Tested

Rebased onto upstream a29ef592190d0450eacbde15ec8e228e379ed753; branch head aeb97f5b1282c5ff4821aa59c2c7d800da2a393e. Windows 11, Ryzen 7 7800X3D, RTX 5070 Ti, Release MinGW GCC 15.2, SPIRV-Tools OFF.

The relevant checks (amd64_only_converter and amd64_only_windows) pass in a combined validation checkout containing the independently rebased reciprocal, shared-loop-exit, vertex-fetch-aliasing, table-store, SRT-depth, constant-phi and deferred-specialization topics. All 10 selected CTest cases passed in 2.31 seconds, with Vulkan required for the table-store execution regression. Each public branch contains its own topic only; these are combined-checkout results, not seven separate full builds. Conventions and diff checks pass for each branch.

No fresh game run, visible frame or playable gameplay is claimed for these rebased heads. Earlier reduced-regression and local-title observations motivated the original change; title code and captures remain local. Linux and macOS were not rerun locally for this rebase.

Checklist

  • Based on upstream main a29ef592; one topic per branch
  • No new comments in code
  • Unimplemented paths retain explicit errors
  • No investigation files, title data or images in the repository
  • No new third-party code
  • Generic behavior
  • Depends on: none for this correction
  • AI-assisted: yes, prepared with Codex; author is responsible for review

GitHub refuses reopening this existing PR with state cannot be changed. The branch was force-pushed or recreated. The public topic branch above contains the rebased/tested head; this closed PR retains its historical head. No replacement upstream PR was opened because current intake still applies automatically to newly opened PRs.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4803352964 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2377). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-09T16:50:48Z. --- ### What `--to-intel` leaves legacy SSE register forms of `RSQRTPS` and `RCPPS` native, although it already replaces their VEX.128 equivalents to avoid reciprocal approximation differences. This PR extends the existing lowering to those legacy register forms, including REX-extended registers and equal source/destination operands. The gap is recorded in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/d70b89989473ba1f6ae13e44e079e67f1f8a44b0/docs/dev/TechnicalDebt.md#functional): legacy forms retain the host approximation. The same entry documents why the existing VEX lowering uses division and square root: an approximate reciprocal square root of `1.0` can remain below `1.0` after refinement. This change applies the existing policy to SSE code; it does not reproduce AMD's approximation tables. | Instruction form | Before | After | |---|---|---| | Legacy register `RSQRTPS` | Native approximation | Existing `SQRTPS` then `DIVPS` lowering; upper YMM bits preserved | | Legacy register `RCPPS` | Native approximation | Existing `DIVPS` lowering; upper YMM bits preserved | | VEX.128 register equivalents | Existing lowering; upper YMM bits cleared | Same behavior | For example, a supported legacy `RSQRTPS` with all input lanes equal to `1.0` now produces exactly `1.0` in every lane, through the same arithmetic used for its VEX equivalent. Implementation: - Rename the internal decoder to `DecodeReciprocal`, accept legacy register encodings with an optional REX prefix, and record whether the instruction uses VEX. - Reuse `ReciprocalLowering` and the existing scratch-register spill/restore path. Emit a legacy result move for `RCPPS`, and avoid the final VEX move for legacy `RSQRTPS`, so upper YMM bits remain intact. - Report `RSQRTPS`/`RCPPS` separately from their VEX equivalents in conversion diagnostics. Support mixed legacy/VEX sequences through the existing out-of-line sequence builder. - Update the corresponding TechnicalDebt entry to describe the additional supported forms and register behavior. The substitution remains optional. Sites shorter than the five-byte jump absorb movable following instructions, or stay native when a jump cannot fit safely. Scalar, memory and 256-bit forms retain their existing behavior. No new dependencies or system-library exports are added. ### Tested Rebased onto upstream `a29ef592190d0450eacbde15ec8e228e379ed753`; branch head `aeb97f5b1282c5ff4821aa59c2c7d800da2a393e`. Windows 11, Ryzen 7 7800X3D, RTX 5070 Ti, Release MinGW GCC 15.2, SPIRV-Tools OFF. The relevant checks (amd64_only_converter and amd64_only_windows) pass in a combined validation checkout containing the independently rebased reciprocal, shared-loop-exit, vertex-fetch-aliasing, table-store, SRT-depth, constant-phi and deferred-specialization topics. All 10 selected CTest cases passed in 2.31 seconds, with Vulkan required for the table-store execution regression. Each public branch contains its own topic only; these are combined-checkout results, not seven separate full builds. Conventions and diff checks pass for each branch. No fresh game run, visible frame or playable gameplay is claimed for these rebased heads. Earlier reduced-regression and local-title observations motivated the original change; title code and captures remain local. Linux and macOS were not rerun locally for this rebase. ### Checklist - [x] Based on upstream main `a29ef592`; one topic per branch - [x] No new comments in code - [x] Unimplemented paths retain explicit errors - [x] No investigation files, title data or images in the repository - [x] No new third-party code - [x] Generic behavior - [x] Depends on: none for this correction - [x] AI-assisted: yes, prepared with Codex; author is responsible for review GitHub refuses reopening this existing PR with `state cannot be changed. The branch was force-pushed or recreated`. The public topic branch above contains the rebased/tested head; this closed PR retains its historical head. No replacement upstream PR was opened because current intake still applies automatically to newly opened PRs.
github-actions[bot] commented 2026-10-09 16:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T16:50:59Z.


Спасибо за ваш интерес к проекту! Извините, сейчас накопилось слишком много открытых PR. Пока мы разбираемся с ними, приём PR от новых участников - авторов, чьих коммитов ещё нет в main, - временно приостановлен. Поэтому этот PR автоматически закрыт. Это не оценка качества ваших изменений.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085324966 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2377#issuecomment-6085324966). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T16:50:59Z. --- Спасибо за ваш интерес к проекту! Извините, сейчас накопилось слишком много открытых PR. Пока мы разбираемся с ними, приём PR от новых участников - авторов, чьих коммитов ещё нет в `main`, - временно приостановлен. Поэтому этот PR автоматически закрыт. Это не оценка качества ваших изменений.
boykopovar commented 2026-10-09 17:17:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-09T17:17:31Z.


Thank you for your interest in the project! Sorry, there are currently too many open PRs. While we sort them out, accepting PRs from new contributors—authors whose commits haven't yet made it into main—is temporarily suspended. Therefore, this PR is automatically closed. This is not a quality review of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085741443 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2377#issuecomment-6085741443). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-10-09T17:17:31Z. --- Thank you for your interest in the project! Sorry, there are currently too many open PRs. While we sort them out, accepting PRs from new contributors—authors whose commits haven't yet made it into main—is temporarily suspended. Therefore, this PR is automatically closed. This is not a quality review of your changes.
Scramblrrrr commented 2026-10-11 13:58:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-11T13:58:51Z.


Refreshed the public topic branch onto current main a11c8f7f70: new head 363d17985e, codex/legacy-sse-reciprocals. Resolved the matcher conflict by retaining main's Rosetta RDPID optional handling alongside the extended reciprocal decoder; retained the Rosetta technical-debt entry.

Fresh standalone Windows Release build: amd64_only_converter + amd64_only_windows, 2/2 pass, 0.61 seconds. Conventions and diff checks pass. No game run or Linux/macOS validation claimed for this topic. This closed PR retains its historical head; the refreshed fork branch is the current cross-test reference. AI-assisted (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109791581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2377#issuecomment-6109791581). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-11T13:58:51Z. --- Refreshed the public topic branch onto current main **a11c8f7f70a0ed4e71504a89de69e8cdae687817**: new head **363d17985e2551dfbe3d3ec81ca3f4bb893b4fc7**, [codex/legacy-sse-reciprocals](https://github.com/Scramblrrrr/AnyPS5/tree/codex/legacy-sse-reciprocals). Resolved the matcher conflict by retaining main's Rosetta RDPID optional handling alongside the extended reciprocal decoder; retained the Rosetta technical-debt entry. Fresh standalone Windows Release build: **amd64_only_converter + amd64_only_windows, 2/2 pass, 0.61 seconds**. Conventions and diff checks pass. No game run or Linux/macOS validation claimed for this topic. This closed PR retains its historical head; the refreshed fork branch is the current cross-test reference. AI-assisted (Codex).
Scramblrrrr commented 2026-10-11 14:08:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-11T14:08:30Z.


The current tested branch is now submitted as #3601, replacing this historical intake-closed PR. Author commits are now on main; this is the same topic rebased and independently Windows-tested, with main Rosetta behavior retained.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109877163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2377#issuecomment-6109877163). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-11T14:08:30Z. --- The current tested branch is now submitted as #3601, replacing this historical intake-closed PR. Author commits are now on main; this is the same topic rebased and independently Windows-tested, with main Rosetta behavior retained.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!2377
No description provided.