Repository navigation
Conversation
Two things about the s -> f16 step had no test: the VOP1 forms that convert an integer (Marvisak#866), and the step itself (`legacyF32ToF16`), which every f16 result in the translator goes through. `v_cvt_f16_u16` (0x050) and `v_cvt_f16_i16` (0x051) read the low 16 bits of the source; the i16 form shifts left then arithmetically right by 16 first, a path shared with no other tested instruction. The table holds 27 sources: everywhere below 0x8000, where the two forms must agree, and 0x8000, 0x8001, 0xC000, 0xFFEF, 0xFFF0, 0xFFF1, 0xFFFE and 0xFFFF, where they part ways. Each conversion runs twice, once into a destination whose high half is zero and once into one seeded with 0xDEAD0000, so the half a 16-bit write leaves alone is checked as well. The expected bits are the truncating ones, not the nearest-even ones Marvisak#866 lists. The step rounds toward zero: 2051 gives 2050, 32767 gives 32752, and 65520, 65536 and 1e30 all give 65504, so no conversion produces an f16 infinity. Measured on an AMD RX 7600M XT (RDNA3, driver 32.0.31007.5012) and on WARP, which agree on every row, and consistent with the NVIDIA figures quoted in Marvisak#866 and with the "0x6801 on main" in Marvisak#422's note. Marvisak#422 moves the ties to nearest even, so its merge has to update these rows. Test-only: the lowering is unchanged. Flipping the i16 extension from an arithmetic to a logical shift fails the test at 0x8000, and so does adding an extension to the u16 form. 122 victory-shader tests pass, the one benchmark ignored; clippy with warnings denied, rustfmt and `cargo xtask policy` (154 files) are clean. AI-assisted; synthetic tests only, no game data.
P2xe1
force-pushed
the
shader/v-cvt-f16-from-u16-i16-test
branch
from
November 24, 2026 13:46
da4dd99 to
b81ac80
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both opcodes now have a hardware test, plus the f32 → f16 step they share, and one correction to the table the issue proposes: on
mainthe conversion truncates — and, truncating, it saturates instead of overflowing.Branch:
P2xe1/VIctory@shader/v-cvt-f16-from-u16-i16-test, commitb81ac80onmainffe310e. Review PR against the fork's ownmain, since upstreamCreatePullRequeststill answers 404: #1Tests (
crates/victory-shader/src/emit/valu_tests.rs, +139 lines, no production code touched):emit::valu_tests::v_cvt_f16_u16_and_i16_convert_the_low_half— 27 sources: everywhere below0x8000, where the two forms must agree, and0x8000,0x8001,0xC000,0xFFEF,0xFFF0,0xFFF1,0xFFFE,0xFFFF, where they part ways. Each conversion runs twice, into a destination whose high half is zero and into one seeded with0xDEAD0000, so the half a 16-bit write leaves alone is covered too.emit::valu_tests::v_cvt_f16_f32_truncates_rather_than_rounding— the step every f16 result goes through, on the ties around 1.0 and at the top of the range.The expected bits
maingives0x0803(2051)0x6802(2052)0x6801(2050)0x7FFF(32767)0x7800(32768)0x77FF(32752)0xFFF0(65520)0x7C00(+inf)0x7BFF(65504)And the step is not only truncating, it never overflows: 65520, 65536 and 1e30 (
0x7149F2CA) all give0x7BFF(65504).v_cvt_f16_f32(VOP10x00A) of1 + 3·2⁻¹¹(0x3F803000) gives0x3C01, where nearest even would carry to0x3C02.So
legacyF32ToF16rounds toward zero and saturates, on both host backends, and every f16 result in the translator inherits that. This matches @fuzeofficlal's "the tie at 2,051 also goes from 2,050 (0x6801) on main to 2,052 (0x6802) with Marvisak#422": the tests recordmain, and Marvisak#422's merge has to update those rows. Whether RDNA2 truncates or rounds to nearest even is the open question — if it rounds, this is a defect of its own, wider than Marvisak#422 (which would leave the saturation as it is), and worth reporting separately.@MichaelSmithAI's corrections to the encodings in the issue hold — 1 →
0x3C00, 15 →0x4B80, 1,024 →0x6400, −16 →0xCC00, 2,049 → 2,048 — except the 2,051 one, whichmainrounds down rather than up, and the two unsigned rows at 65,520 and 65,535, which stay finite here.Evidence
32.0.31007.5012), Windows 1110.0.28020, Rust 1.98.1 MSVC. The reports above were NVIDIA plus WARP; this is an AMD data point.Bin::AShr→Bin::LShrin the i16 extension fails at0x8000(0x7800, want0xF800); adding that extension to the u16 form fails at0x8000too (0xF800, want0x7800). Reverting both passes.AI-assisted; synthetic tests only, no game data.
Opened here against this fork's main (fe310e) for review and cherry-pick; upstream PR creation is restricted to collaborators.