Repository navigation
relinker: run Rosetta-mistranslated scalar compares out of line - #480
Conversation
Under Rosetta 2, a CMPSS/VCMPSS (and VCMPSD) whose predicate is not EQ_OQ, LT_OS or LE_OS, followed in the same block by a full 128-bit VEX load (VMOVAPS/VMOVUPS/VMOVDQA) into the compare's destination, makes a later scalar read of that register (VUCOMISS, VADDSS) see the compare's mask instead of the loaded value. clang's fmaxf idiom (VCMPUNORDSS, VMAXSS, VBLENDVPS) followed by a reload and VUCOMISS hits it: equal operands compared as "below", so a title's flex layout never grew or shrank its items. Found by replaying one layout call from a snapshot under Rosetta and under qemu-user (TCG) and bisecting to the first diverging instruction. --to-rosetta now moves every such compare (legacy and VEX, ss and sd, register, memory and RIP-relative sources) into a stub that runs the unchanged instruction, so it lands in its own block. The semantics are exactly the instruction's; the cost is two jumps per site. Tests: - amd64_only_converter_tests: decoding, which predicates split, the stub body and RIP-relative relocation, the Intel target untouched. - rosetta_cpuid_tests: every predicate of every form under Rosetta, as written and split. The load is lost in 68 of the 80 sequences as written and in none once split; the compare results are bit exact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9aa2704cfa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| std::size_t pos = 0; | ||
| while (pos < length && _segmentPrefix(data[pos])) | ||
| ++pos; |
There was a problem hiding this comment.
Handle address-size prefixes before scalar compares
When a valid scalar compare carries an address-size override, such as 67 C5 FA C2 05 ... or 67 F3 0F C2 05 ..., the instruction scanner consumes 0x67 as a prefix but this decoder skips only segment prefixes, so it returns no match. Such memory-source compares remain in the original Rosetta block and can still trigger the load-loss bug this change is intended to prevent; parse all applicable legacy prefixes before locating the VEX or mandatory F2/F3 prefix.
Useful? React with 👍 / 👎.
…es, Metal depth retirement, null degamma images) (#498) * fix(relinker): decode scalar compares behind address-size and segment prefixes A scalar compare carrying an address-size override (67 C5 FA C2 ..., 67 F3 0F C2 ...) or with F2/F3 on either side of another legacy prefix was not decoded, so it stayed in its Rosetta block and could still lose the later load of its destination. Legacy prefixes are now read in any order, the last F2/F3 being the mandatory one; F2/F3 before a VEX escape is still not a compare. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(agc): retire depth surfaces over every MSAA fragment and every layered slice on Metal A multisampled color target now retires the depth surfaces over all of its fragments (bytes * samples), as MetalColorSurface::OverlapsMappings already measures it. Each extra slice of a layered depth draw retires the surfaces over its depth and stencil planes, not only one at exactly its depth address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(recompiler): skip null images before FORCE_DEGAMMA validation A null T# (TYPE=0 or zero base) reads zero whatever its other words say, so a null image left with an RGBA8_UINT format under a FORCE_DEGAMMA sampler no longer fails the one-slice-volume check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(agc): pin a swizzled T# sampled through the FORCE_DEGAMMA sRGB view An R/B-swapped UNORM and sRGB texture sampled under FORCE_DEGAMMA keeps its mapping once. Measured: a Metal view of a view takes its swizzle relative to the root texture, so passing the parent's swizzle is right and an identity swizzle drops the mapping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(agc): keep a stencil-only target's absent depth plane absent in its layered slices The extra slices of a layered draw offset the depth address even when it is zero (a stencil-only target), and the range retirement then treated that fabricated address as a depth plane. DepthArraySlice leaves an absent plane at zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Under Rosetta 2, a scalar compare (CMPSS / VCMPSS / VCMPSD) whose predicate is not EQ_OQ, LT_OS or LE_OS breaks the next load in the same translated block. If a full 128-bit VEX load (VMOVAPS / VMOVUPS / VMOVDQA) then overwrites the compare's destination, a later scalar FP read of that register (VUCOMISS, VADDSS) gets the compare's mask instead of the loaded value.
clang's
fmaxfidiom (VCMPUNORDSS, VMAXSS, VBLENDVPS), followed by a reload and a VUCOMISS, hits this. Equal operands (309.0 vs 309.0) compared as "below", so the UI flex layout never grew or shrank items, andmargin:autoand leader select broke.How it was found
vucomiss xmm1, xmm0that followsvcmpunordss xmm1, xmm2, xmm2; …; vmovaps xmm1, [rbp-0x110]. QEMU gives ZF=1 and Rosetta gives CF=1.Fix
--to-rosettamoves each such compare into a stub that runs the unchanged instruction, so it lands in its own block.Tests
amd64_only_converter_testscovers:rosetta_cpuid_testsruns every predicate of every form under Rosetta, as written and split:min-heightandmargin-top:autocases differ from browser CSS, but an offline replay shows Rosetta now matches exact x86 bit for bit there. That is the title's own layout behaviour, not emulation.🤖 Generated with Claude Code
https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj