Skip to content

relinker: run Rosetta-mistranslated scalar compares out of line - #480

Merged
RINNECODER merged 1 commit into
mainfrom
ui-flexbox-r5
Oct 14, 2026
Merged

RINNECODER merged 1 commit into
mainfrom
ui-flexbox-r5

Conversation

@RINNECODER

Copy link
Copy Markdown
Owner

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 fmaxf idiom (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, and margin:auto and leader select broke.

How it was found

  • I captured one snapshot at the layout function's flex decision during a game run.
  • I replayed it offline at its original addresses under Rosetta and under qemu-user (TCG, an exact x86 emulator).
    • Rosetta reproduced the bad size (child height 0).
    • QEMU gave the correct 309.
  • I bisected with int3 checkpoints. The first state that differs is after the vucomiss xmm1, xmm0 that follows vcmpunordss xmm1, xmm2, xmm2; …; vmovaps xmm1, [rbp-0x110]. QEMU gives ZF=1 and Rosetta gives CF=1.
  • Standalone repros narrowed it to compare + VEX full-width load into the same register + a scalar consumer, all in one block. A block boundary (jmp, call, branch) between them avoids it.

Fix

--to-rosetta moves each such compare into a stub that runs the unchanged instruction, so it lands in its own block.

  • Covers legacy and VEX, ss and sd, and register, memory and RIP-relative sources.
  • The semantics are exactly the instruction's. Each site costs two jumps (240 sites in the affected title).

Tests

  • amd64_only_converter_tests covers:
    • decoding
    • which predicates are split
    • the stub body
    • RIP-relative relocation
    • the Intel target staying untouched
  • rosetta_cpuid_tests runs 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.
  • Game run with the UI probe mod:
    • grow, shrink and stretch layouts now fill their containers.
    • Leader select lays out correctly.
    • The probe's min-height and margin-top:auto cases 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

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T01:33:07.311644Z 9aa2704 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 52dd2ab7-b78e-4d84-b679-9080ec0a93db
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RINNECODER
RINNECODER merged commit eedae84 into main Oct 14, 2026
6 checks passed
@RINNECODER
RINNECODER deleted the ui-flexbox-r5 branch October 14, 2026 01:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +29 to +31
std::size_t pos = 0;
while (pos < length && _segmentPrefix(data[pos]))
++pos;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

RINNECODER added a commit that referenced this pull request Oct 14, 2026
…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>
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.

1 participant