pixel_aot: use binary16 encodings for inline float constants in v_pack_b32_f16 #1006

Merged
Leyukaka merged 3 commits from upstream-pr/1013 into main 2026-11-23 21:57:27 +00:00
Leyukaka commented 2026-11-23 21:15:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T21:15:58Z.


Change

v_pack_b32_f16 lowers through the integer table, so an inline float constant went through scalar_u32, which packs a decimal token as binary32. On main, v_pack_b32_f16 v12, 1.0, v18 emits

precise float alu21 = asfloat((1065353216u & 0xffffu) | ((asuint(alu20) & 0xffffu) << 16));

so the low half is 0x3f800000 & 0xffff = 0. LLVM types the sources of v_pack_b32_f16 as binary16 and prints an inline float constant on them as a decimal float, so its binary16 encoding is the operand (1.0 is 0x3c00), as tools/pixel_aot.py already assumes for the packed VOP3P forms; this is not measured on the console. This change maps the tokens of the existing INLINE_F16 table (0.5, 1.0, 2.0, 4.0, their negations and 0.15915494) to those encodings for this opcode only, and refuses any other decimal float (llvm-mc prints those as hex on a binary16 operand). Registers, hex literals and integer inline constants are unchanged. With it the same line is

precise float alu21 = asfloat((15360u & 0xffffu) | ((asuint(alu20) & 0xffffu) << 16));

docs/experiments.md says so in the v_pack_b32_f16 paragraph. Refs #1001.

Verification

On 87c69f68 (based on main at 1f34ba1), Windows 11, Python 3.14:

python -B tests/pixel_aot_check.py
ctest --preset dev --no-tests=error -R '^pixel_aot_pack_b32_' -V
python -B tests/docs_links_check.py

check_pack_b32_lowering() now translates 1.0, -0.5 and 0.15915494 sources and requires 15360u, 47104u and 12568u, and refuses 3.0 and 0.25. The controls pass with this change. With the new check and the main version of tools/pixel_aot.py, they fail on the first of those lines (AssertionError: precise float alu21 = asfloat((15360u & 0xffffu) | ...). The pixel_aot_pack_b32 draws, which use no inline float constant, still pass on WARP and on an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101, not skipped), and the docs check passes.

Evidence and follow-up

The binary16 inline-constant encodings come from the INLINE_F16 table that tools/pixel_aot.py already uses for the packed VOP3P forms. No new fixture is added; the draws do not use inline float constants, so the check is static.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6568992780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1013). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-23T21:15:58Z. --- ## Change `v_pack_b32_f16` lowers through the integer table, so an inline float constant went through `scalar_u32`, which packs a decimal token as binary32. On `main`, `v_pack_b32_f16 v12, 1.0, v18` emits ```text precise float alu21 = asfloat((1065353216u & 0xffffu) | ((asuint(alu20) & 0xffffu) << 16)); ``` so the low half is `0x3f800000 & 0xffff = 0`. LLVM types the sources of `v_pack_b32_f16` as binary16 and prints an inline float constant on them as a decimal float, so its binary16 encoding is the operand (`1.0` is `0x3c00`), as `tools/pixel_aot.py` already assumes for the packed `VOP3P` forms; this is not measured on the console. This change maps the tokens of the existing `INLINE_F16` table (`0.5`, `1.0`, `2.0`, `4.0`, their negations and `0.15915494`) to those encodings for this opcode only, and refuses any other decimal float (`llvm-mc` prints those as hex on a binary16 operand). Registers, hex literals and integer inline constants are unchanged. With it the same line is ```text precise float alu21 = asfloat((15360u & 0xffffu) | ((asuint(alu20) & 0xffffu) << 16)); ``` `docs/experiments.md` says so in the `v_pack_b32_f16` paragraph. Refs #1001. ## Verification On `87c69f68` (based on `main` at `1f34ba1`), Windows 11, Python 3.14: ```text python -B tests/pixel_aot_check.py ctest --preset dev --no-tests=error -R '^pixel_aot_pack_b32_' -V python -B tests/docs_links_check.py ``` `check_pack_b32_lowering()` now translates `1.0`, `-0.5` and `0.15915494` sources and requires `15360u`, `47104u` and `12568u`, and refuses `3.0` and `0.25`. The controls pass with this change. With the new check and the `main` version of `tools/pixel_aot.py`, they fail on the first of those lines (`AssertionError: precise float alu21 = asfloat((15360u & 0xffffu) | ...`). The `pixel_aot_pack_b32` draws, which use no inline float constant, still pass on WARP and on an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101, not skipped), and the docs check passes. ## Evidence and follow-up The binary16 inline-constant encodings come from the `INLINE_F16` table that `tools/pixel_aot.py` already uses for the packed `VOP3P` forms. No new fixture is added; the draws do not use inline float constants, so the check is static. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:45:51 +00:00
R0Y00 commented 2026-11-24 06:49:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:27:40Z.


I independently assembled all three forms with LLVM 15 for gfx1013. They are inline selectors (242 for 1.0, 241 for -0.5, 248 for 0.15915494), without a literal word, and the new Python lowering assertions pass. Please put one of those actual encodings into the existing pack draw/binary round-trip. Use a nonzero neighboring half so the raw readback catches 0x0000 from the old f32-low-half behavior. The desktop readback would verify the lowering path; keep the current qualification about console evidence.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7114490633 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1013#issuecomment-7114490633). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T21:27:40Z. --- I independently assembled all three forms with LLVM 15 for gfx1013. They are inline selectors (242 for `1.0`, 241 for `-0.5`, 248 for `0.15915494`), without a literal word, and the new Python lowering assertions pass. Please put one of those actual encodings into the existing pack draw/binary round-trip. Use a nonzero neighboring half so the raw readback catches `0x0000` from the old f32-low-half behavior. The desktop readback would verify the lowering path; keep the current qualification about console evidence.
R0Y00 commented 2026-11-24 06:49:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:41:25Z.


I added the inline 1.0 variant in 23ab53d2 and kept all existing pack cases. LLVM 15 assembles and round-trips it with the other binary fixtures. The draw compares 0xc0003c00 and catches 0xc0000000, the old f32 low-half result, on both the local hardware and WARP runs (ctest --preset release --no-tests=error -R '^pixel_aot_pack_b32_(hardware|warp)$' -V, 2/2).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7114790980 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1013#issuecomment-7114790980). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T21:41:25Z. --- I added the inline `1.0` variant in `23ab53d2` and kept all existing pack cases. LLVM 15 assembles and round-trips it with the other binary fixtures. The draw compares `0xc0003c00` and catches `0xc0000000`, the old f32 low-half result, on both the local hardware and WARP runs (`ctest --preset release --no-tests=error -R '^pixel_aot_pack_b32_(hardware|warp)$' -V`, 2/2).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1006
No description provided.