fix: refuse a FLAT offset with bit 11 set instead of reading it as negative #242

Manually merged
github merged 1 commit from gh-pr/242/head into gh-pr/242/base 2026-11-26 05:39:45 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:55 UTC · original
lcg007xd-c:fix/flat-offset-bit11 → main · +53 −4 · 3 files · 1 commits · merged 2026-11-25 21:46 UTC

Change

The reference interpreter (rdna2_exec_memory._flat) and the HLSL recompiler (rdna2_hlsl_memory._flat) sign-extend the 12-bit offset of every FLAT/GLOBAL/SCRATCH instruction. For the FLAT segment (SEG = 0) that gives a negative offset when bit 11 is set, and the disassembler of this repository disagrees with it:

encoding 0xDC300800 0x007D0001
  rdna2_operands.text  → flat_load_dword v0, v[1:2] offset:2048
  llvm-mc 20 gfx1030   → flat_load_dword v0, v[1:2] offset:2048
  interpreter / HLSL   → address = v[1:2] - 2048

Sources:

  • AMD, "RDNA 2" ISA, November 2020, §9.1 "Flat Memory Instruction" (printed p. 83), OFFSET field: "Scratch, Global: 12-bit signed byte offset. Flat: must be positive."
  • LLVM 20 (cross-check): llvm-mc -triple=amdgcn -mcpu=gfx1030 rejects flat_load_dword v0, v[1:2] offset:2048 and offset:-1 with "expected a 11-bit unsigned offset", and accepts global_load_dword … offset:-1.

Neither source says what the hardware does with bit 11 set on FLAT, so following rule 3 both paths now refuse it by name (Untranslated / Untranslatable: "FLAT offset with bit 11 set (the ISA requires a positive offset)") instead of guessing. FLAT offsets 0-2047 are unchanged. GLOBAL and SCRATCH keep the 12-bit signed offset. The new rdna2_exec_memory.flat_offset(family, word) is shared by the interpreter and HLSL.

Linked issue: none. VIctory reads the same field as 11-bit unsigned (Marvisak/VIctory#1636, "GFX10 FLAT offsets ignore bit 11"). That PR gives no measurement, so this PR refuses the case rather than copying the mask; it is a one-line change if you prefer masking.

Verification

Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased on main 400e590:

python -m pytest                → 1039 passed, 319 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

The suite is green on this machine since #237 and #238 merged.

Not run: the Windows CI job and GPU/WARP. The HLSL change is only a refusal: the text generated for valid offsets is unchanged, and the existing GPU tests use GLOBAL.

Oracle and test data

  • New test_flat_offset_is_unsigned_and_bit_11_is_refused (tests/test_rdna2_exec_memory.py):
    • flat_load_dword with offset 0x7FC loads from base + 2044;
    • bit 11 is refused by the interpreter (Untranslated) and by rdna2_hlsl.translate (Untranslatable);
    • global_load_dword with offset −4 still loads from base − 4.
  • Failure case: on main the test fails with "DID NOT RAISE Untranslated": the interpreter loaded from base − 2048.
  • Test data is built in the test.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (The undocumented case is now refused instead of guessed.)
  • README: the same change in all 9 languages (test_readme_sync.py checks it). (No README change.)
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

Made with AI assistance (Claude Code).

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:55 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/242) `lcg007xd-c:fix/flat-offset-bit11` → `main` · +53 −4 · 3 files · 1 commits · merged 2026-11-25 21:46 UTC ## Change The reference interpreter (`rdna2_exec_memory._flat`) and the HLSL recompiler (`rdna2_hlsl_memory._flat`) sign-extend the 12-bit offset of every FLAT/GLOBAL/SCRATCH instruction. For the FLAT segment (SEG = 0) that gives a **negative** offset when bit 11 is set, and the disassembler of this repository disagrees with it: ``` encoding 0xDC300800 0x007D0001 rdna2_operands.text → flat_load_dword v0, v[1:2] offset:2048 llvm-mc 20 gfx1030 → flat_load_dword v0, v[1:2] offset:2048 interpreter / HLSL → address = v[1:2] - 2048 ``` Sources: - AMD, "RDNA 2" ISA, November 2020, §9.1 "Flat Memory Instruction" (printed p. 83), OFFSET field: "Scratch, Global: 12-bit signed byte offset. **Flat: must be positive.**" - LLVM 20 (cross-check): `llvm-mc -triple=amdgcn -mcpu=gfx1030` rejects `flat_load_dword v0, v[1:2] offset:2048` and `offset:-1` with "expected a 11-bit unsigned offset", and accepts `global_load_dword … offset:-1`. Neither source says what the hardware does with bit 11 set on FLAT, so following rule 3 both paths now refuse it by name (`Untranslated` / `Untranslatable`: "FLAT offset with bit 11 set (the ISA requires a positive offset)") instead of guessing. FLAT offsets 0-2047 are unchanged. GLOBAL and SCRATCH keep the 12-bit signed offset. The new `rdna2_exec_memory.flat_offset(family, word)` is shared by the interpreter and HLSL. Linked issue: none. VIctory reads the same field as 11-bit unsigned (Marvisak/VIctory#1636, "GFX10 FLAT offsets ignore bit 11"). That PR gives no measurement, so this PR refuses the case rather than copying the mask; it is a one-line change if you prefer masking. ## Verification Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased on `main` `400e590`: ``` python -m pytest → 1039 passed, 319 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` The suite is green on this machine since #237 and #238 merged. Not run: the Windows CI job and GPU/WARP. The HLSL change is only a refusal: the text generated for valid offsets is unchanged, and the existing GPU tests use GLOBAL. ## Oracle and test data - New `test_flat_offset_is_unsigned_and_bit_11_is_refused` (`tests/test_rdna2_exec_memory.py`): - `flat_load_dword` with offset `0x7FC` loads from base + 2044; - bit 11 is refused by the interpreter (`Untranslated`) and by `rdna2_hlsl.translate` (`Untranslatable`); - `global_load_dword` with offset −4 still loads from base − 4. - Failure case: on `main` the test fails with "DID NOT RAISE `Untranslated`": the interpreter loaded from base − 2048. - Test data is built in the test. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (The undocumented case is now refused instead of guessed.) - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). (No README change.) - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. Made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The interpreter and the HLSL recompiler sign-extended the 12-bit offset
of every FLAT/GLOBAL/SCRATCH instruction, so a FLAT (SEG = 0) offset of
0x800 became -2048 while the disassembler prints offset:2048. The RDNA 2
ISA (section 9.1, p. 83) says "Scratch, Global: 12-bit signed byte
offset. Flat: must be positive", and llvm-mc 20 (gfx1030) only accepts
an 11-bit unsigned FLAT offset. What the hardware does with bit 11 set
is not documented, so both now refuse it by name (rule 3); GLOBAL and
SCRATCH keep the signed offset. flat_offset() is shared by the two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:39:42 +00:00
github manually merged commit 33fb631eef into gh-pr/242/base 2026-11-26 05:39:45 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.