Skip to content

fix(recompiler): widen constants of 64-bit operands instead of repeating them - #39

Merged
boykopovar merged 1 commit into
boykopovar:mainfrom
Pacuka:fix/recompiler-64bit-constants
Sep 28, 2026
Merged

boykopovar merged 1 commit into
boykopovar:mainfrom
Pacuka:fix/recompiler-64bit-constants

Conversation

@Pacuka

@Pacuka Pacuka commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Problem

TranslationContext::readU32Pair builds a 64-bit source from two 32-bit reads, taking the high half from offsetOperand(operand, 1). For registers that is the next register. For a literal or an inline constant, offsetOperand returns the same operand, so the constant ended up in both halves: the literal L was read as L:L instead of 0:L.

Found in The Smurfs Dreams (UE). A compute shader writes the args of an indirect draw and rounds a count up to a multiple of 21:

v_add_nc_u32   v4, 20, v3
v_mad_u64_u32  v[2:3], vcc_lo, 0xc30c30c3, v4, 0xc30c30c3
v_lshrrev_b32  v2, 4, v3          ; instances = (n + 20) / 21

With the addend read as 0xc30c30c3c30c30c3, the draw got 0x0c30c30d instances instead of 0. On RDNA2 that kept the gfx ring busy past the amdgpu lockup timeout, and a MODE1 GPU reset followed.

Fix

The fix only applies when the operand is a constant:

  • a literal is zero-extended (the high half is 0), which matches LLVM's AMDGPU disassembler. Only f64 operands put the literal in the high half, and the translator has no f64 ALU path.
  • an integer inline constant is sign-extended, so -1 becomes all ones
  • a float inline constant becomes the double of the same value

Register operands behave as before.

The same function backs readMask, so a 64-bit mask constant also changes. For example, s_and_saveexec_b64 s[14:15], 1 in a wave64 shader enabled lanes 0 and 32. Now it enables only lane 0.

Testing

  • Full build plus libs on Linux; ctest passes 36/36.
  • The Smurfs Dreams on a local branch: before this change it always hit a GPU reset at frame 34. With the change, the args record reads {63, 0, 0, 0}, the draw is skipped as intended, and there has been no reset or GPU fault in a 240 s run.
  • Not covered: the float inline constant branch. I haven't seen a shader that uses one in a 64-bit integer operation, so it follows the ISA rule and is untested. There is no unit test either: the recompiler has no translation-level test harness yet.

🤖 Generated with Claude Code

…ing them

readU32Pair read a literal or inline constant into both halves of a 64-bit
source. A literal is now zero-extended, an integer inline constant
sign-extended and a float inline constant becomes the matching double.

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.

2 participants