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

Manually merged
github merged 3 commits from gh-pr/1013/head into gh-pr/1013/base 2026-11-26 22:35:07 +00:00
Owner

@⁠Leyukaka on GitHub · 2026-11-23 21:15 UTC · original
Leyukaka:pack-inline-f16 → main · +48 −5 · 3 files · 3 commits · merged 2026-11-23 21:57 UTC

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.

**@⁠Leyukaka** on GitHub · 2026-11-23 21:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1013) `Leyukaka:pack-inline-f16` → `main` · +48 −5 · 3 files · 3 commits · merged 2026-11-23 21:57 UTC ## 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.
An inline float constant on v_pack_b32_f16 went through the 32-bit scalar path, so 1.0 supplied the low half of 0x3f800000 (0) instead of 0x3c00.

AI-assisted.
AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:35:05 +00:00
github manually merged commit 23ab53d29e into gh-pr/1013/base 2026-11-26 22:35:07 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 21:27 UTC · original

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** on GitHub · 2026-11-23 21:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1013#issuecomment-7114490633) 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 21:41 UTC · original

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).

**@⁠R0Y00** on GitHub · 2026-11-23 21:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1013#issuecomment-7114790980) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.