feat(relinker): lower F16C VCVTPH2PS and VCVTPS2PH under --to-avx #23842
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23842"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by swifttdma on 2026-11-19T18:51:12Z.
What
Lower 128- and 256-bit F16C instructions (
VCVTPH2PSandVCVTPS2PH, register and memory operands, immediate and MXCSR rounding modes) under--to-avxvia out-of-line integer conversion stubs below the red zone, preserving RFLAGS, GPRs, other YMM registers, and upper-lane zeroing. Updates--to-avxdocumentation indocs/user/USAGE.mdand adds the corresponding technical debt fragment.Tested
CachyOS Linux x86_64 (GCC 16.2.1, Clang 23.1.4
-Wall -Wextra -Wpedantic, Release relinker-only build). Ranf16c_lowering(all 65,536 half-precision inputs forVCVTPH2PSand normal, subnormal, overflow, underflow, NaN, DAZ/FTZ, immediate and MXCSR rounding cases forVCVTPS2PHverified bit-for-bit against both the Intel SDM model and hardware F16C, plus GPR/RFLAGS/YMM/red-zone, RIP-relative, SIB, RSP and page-end guard checks),amd64_only_converter,avx2_twin_lowering,lane_split_lowering,permute_lowering,widen_broadcast_lowering,relinker_conversion,cli_args,to_rosetta,tools/debt_fold.py --check,tools/check_test_registration.py, andtools/check_conventions.py --base origin/main— all passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
--to-avxoption now supports F16C half-precision and single-precision conversions, including 128-bit and 256-bit forms.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T19:09:52Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
8c264f070a:tools/check_conventions.pypassed.f16c_lowering_testsbuilt cleanly.f16c_lowering):core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/F16cLowering.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:35:35Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the immediate rounding-mode selection so VCVTPS2PH uses the requested rounding mode.
What I ran
Reviewed head
8c264f070a2af1af465c2ccdd423bc8c6e0795defrom the prepared diff and repository reader. No build or tests were run; the environment exposed reader tools only.Results
Findings
Blocking
core/relinker/codegen/src/x86/F16cLowering.cpp:128: The rounding helper tests the unsigned immediate as a signedint32_tto choose the83 /r ibencoding. ForVCVTPS2PHimmediates with high bits set (for example0xF3), the signed value is negative and fits the signed-byte range, so only its low byte (0xF3, sign-extended to-13) reaches the CPU. The emitted operation therefore adds/subtracts the wrong value instead of the intended mask or comparison value. This breaks upper immediate values and may cause incorrect conversions or loop/control decisions. Choose the short form based on whether the intended immediate is a valid sign-extended byte, or always emit the full-width form for these constants.Non-blocking
None.
Sources
core/relinker/codegen/src/x86/F16cLowering.cpp:126-143shows the signed narrowing test used by the immediate encoder.core/relinker/codegen/src/x86/F16cLowering.cpp:303-325shows the immediate-derived rounding mode and the conversion constants passed through this helper.core/relinker/codegen/tests/F16cLoweringTests.cpp:1003-1034includes an upper-bit immediate (0xF3) in the test inputs, but the test result was not run independently.Not verified
The author-reported CachyOS builds and test suite were not run in this review. The prepared diff excludes files by rule;
files.jsonwas not available through the reader, so excluded-file details are not verified. All changed files listed in the review manifest were read:core/relinker/CMakeLists.txt,core/relinker/codegen/include/codegen/x86/F16cLowering.hpp,core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/F16cLowering.cpp,core/relinker/codegen/tests/F16cLoweringTests.cpp,docs/dev/debt/changes/feat-relinker-f16c-lowering.md, anddocs/user/USAGE.md.To get this to a good state
Fix the immediate encoding and rerun the F16C lowering test suite on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:56:25Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: fix the 32-bit subnormal conversion path so its shift counts preserve the discarded bits and produce correctly rounded half subnormals.
What I ran
Reviewed head
71bed90de4755a0a0a307accb5832c217386bd8cusing the prepared diff and repository reader. I did not run tests; the test results in the PR description are author-reported.Results
Findings
Blocking
core/relinker/codegen/src/x86/F16cLowering.cpp:362-370: The subnormal path computes the right-shift count inECXas126 - exponent, then usesDEC ECXand later converts it to a left-shift count with32 - ECX. For exponent 112, for example, this produces a right shift of 13 and then a left shift of 20; the intermediate value only retains the low 19 fraction bits, so the discarded rounding information is lost. This makesVCVTPS2PHsubnormal results incorrect for inputs in this exponent range (including rounding-boundary cases). Derive the remainder/guard bits from the original significand with counts that keep all discarded bits available, and add focused checks around subnormal rounding ties.Non-blocking
None.
Not verified
No tests or build checks were run. The author-reported test suite and the PR's hardware measurements were not independently verified. No changed files were excluded by the manifest.
To get this to a good state
Correct the subnormal conversion and add boundary-focused rounding coverage, then rerun the F16C lowering tests and affected relinker checks.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:13:43Z.
Review: COMMENTED
Reviewed — comments
The F16C lowering is registered for AVX matching and includes focused execution tests, but the technical debt fragment has a malformed heading and describes a CPU capability restriction inconsistently with this PR’s
--to-avxchange.What I ran
84090ad60d19474416fac8008e596281b8065cac; basemain. No merged-preview check was run.description.md,commits.md,manifest.json,diff.patch,README.md, and all seven changed files. No changed files were excluded.Results
Findings
Blocking
None.
Non-blocking
docs/dev/debt/changes/feat-relinker-f16c-lowering.md:3has an unmatched)in the matcher link and ends with the incomplete phrase “applies the BMI1”. The next bullet provides a full description, but this heading reads as malformed markdown/content. Please replace it with an accurate, complete change heading.docs/dev/debt/changes/feat-relinker-f16c-lowering.md:5says--to-avxrequires--macosbecause Linux and Windows stop at startup when the host lacks AVX2, while the PR description says the lowering targets hosts with AVX but without AVX2 and is dispatched under--to-avx. Please reconcile the stated host/runtime restriction with the actual supported use case so users are not told the new lowering applies where runtime startup precludes it.Not verified
To get this to a good state
Nothing is required. Optional: correct the malformed debt heading and clarify the runtime/host restriction in the debt note.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:53:56Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand ranf16c_loweringandamd64_only_converteron Linux x86-64. Both passed, including the half-to-single and single-to-half conversion checks.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T11:12:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make the F16C lowering preserve conversion exception status and unmasked exception behavior, or avoid lowering instructions when those semantics cannot be preserved.
What I ran
Reviewed head
2c45755785a9278a9efa2c0c5d1dd63fd32a6db4. I inspected the prepared diff and changed sections, and usedrepo_read.pyto inspect matcher and supporting code at the pinned head. I did not run tests or a build; the test results in the PR description are author-reported.Results
Negative control
Not run; no tests were executed during this review.
Findings
Blocking
core/relinker/codegen/src/x86/F16cLowering.cpp:317saves MXCSR for rounding-mode and DAZ decisions, but the integer conversion path does not update MXCSR exception status or raise#XMfor unmasked exceptions. For example, an inexact or overflowingVCVTPS2PHcan leave status flags unchanged, so guest code that checks MXCSR observes different behavior from the instruction being lowered. Implement equivalent status and exception handling, or restrict lowering where that behavior cannot be preserved. The PR’s debt note acknowledges this limitation.Non-blocking
None.
Sources
Not verified
No tests or builds were run, and physical-console behavior was not checked. Inspected changed files:
core/relinker/CMakeLists.txt,core/relinker/codegen/include/codegen/x86/F16cLowering.hpp,core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/F16cLowering.cpp,core/relinker/codegen/tests/F16cLoweringTests.cpp,docs/dev/debt/changes/feat-relinker-f16c-lowering.md, and the changed section ofdocs/user/USAGE.md.files.jsonlists no excluded files.To get this to a good state
Implement the required MXCSR status and unmasked exception behavior, or prevent lowering when it cannot be preserved. Then rerun the F16C lowering checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T11:27:41Z.
Review: COMMENTED
Actionable comments
core/relinker/codegen/src/x86/F16cLowering.cpp, lines44· 🎯 Functional Correctness · ⚖️ Poor tradeoffUnindexedStackcheck. It always uses the 304-byte default frame. Its address can then resolve below the red zone, into the scratch YMM spill at original RSP-160 through RSP-129.VCVTPH2PSreads the saved scratch register instead of its input.VCVTPS2PHwrites its output over the saved scratch register, and the restore then loads the output bytes back into the scratch register. The enlarged-frame rule for unindexed displacements below -128 does not cover indexed operands, because the index is a runtime value.963f7935-1c63-445b-ab98-597d8eda4f08Reviewing files that changed from the base of the PR and between
63b98e5bf8and2c45755785.core/relinker/CMakeLists.txtcore/relinker/codegen/include/codegen/x86/F16cLowering.hppcore/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cppcore/relinker/codegen/src/x86/F16cLowering.cppcore/relinker/codegen/tests/F16cLoweringTests.cppdocs/dev/debt/changes/feat-relinker-f16c-lowering.mddocs/user/USAGE.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.