pixel_aot: non-packed binary16 VOP1/VOP2 ALU under the low-16-only contract (scope question) #839
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#839
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@JB2WIN on GitHub · 2026-11-23 11:00 UTC · original
On current
main, a form-coverage run lists the non-packed binary16 ALU forms as uncovered:v_add_f16,v_sub_f16,v_subrev_f16,v_mul_f16,v_min_f16,v_max_f16,v_ldexp_f16,v_fmac_f16,v_fmaak_f16andv_fmamk_f16.v_rcp_f16,v_sqrt_f16,v_rsq_f16,v_log_f16,v_exp_f16,v_sin_f16,v_cos_f16,v_floor_f16,v_ceil_f16,v_trunc_f16,v_rndne_f16andv_fract_f16._e64spellings of the above.#732 now gives the 16-bit integer ops a low-16-only contract. A first slice of these forms could use the same contract:
v_cvt_f32_f16, the f16 compares and SDWAWORD_0.Before proposing a design I'd like to settle three points:
v_cvt_f32_f16plus SDWAWORD_0?v_fma_f16. @KomaGuy and @Holastor, would a plain VOP1/VOP2 slice get in your way, or should it wait for those PRs?HALF_ROUNDING?I'd start with the arithmetic VOP2 set (
add/sub/subrev/mul/min/max). Transcendental andldexpwould come later, if at all. AI-assisted (Claude Code).@Holastor on GitHub · 2026-11-23 11:05 UTC · original
Thanks for checking in @JB2WIN!
A plain VOP1/VOP2 slice for binary16 arithmetic will not get in the way of #704:
Regarding your 3rd point (rounding modes): in #704, R0Y00 specifically requested rejecting non-default rounding modes (HALF_ROUNDING["0"] / RNE only, rejecting HALF_RTZ), so sticking to the default RNE mode for the first slice is definitely consistent with established practice in pixel_aot.
Feel free to proceed with the VOP2 arithmetic slice (dd/sub/subrev/mul/min/max)!
@R0Y00 on GitHub · 2026-11-23 11:16 UTC · original
A small plain, non-fused VOP2 slice can proceed independently of #419 and #704. Start with add/sub/subrev/mul under a validated binary16 mode: nearest-even with half denormals preserved. A numeric half-mode assumption needs the same entry provenance or tracked MODE write as the rest of the profile; refuse unsupported or unknown modes. Track the low half as defined, with the high half unknown. Start with audited
v_cvt_f32_f16and SDWAWORD_0consumers. Any added compare/chained consumer needs its own low-half validation; keep whole-word and high-half readers rejected. Keep min/max separate until the signed-zero and NaN rules are pinned. Use LLVM 15 round-trip and a lossless integer readback with halfway rounding, positive and negative subnormals, signed zero, and a wrong-rounding/high-half control. For any input class whose observable result is not established, require a proven supported value or independent native reference before extending the profile.@JB2WIN on GitHub · 2026-11-23 12:08 UTC · original
Thanks, both. The design for the
add/sub/subrev/mulslice is drafted. Before I build it, two choices are yours.The arithmetic is
widen16of both low halves, oneprecisebinary32 operation, thennarrow16. That is exact for these ops: binary32mulof two halves is exact, and double rounding through binary32 is harmless foraddbecause 24 ≥ 2·11+2. I checked it exhaustively offline over all finite operand pairs foraddandmul, with 0 differences.require_proven_i32_f32_range: refuse any source not statically proven finite. That makes the slice much narrower.HALF_DENORM_ENTRY= preserve), with every MODE-changing instruction refused. Is that the provenance you mean, or do you want a trackedhwreg(HW_REG_MODE, 6, 2)write?Smaller choices, unless you object:
("half16", …)tag, separate from integerlow16, so the integer 16-bit readers can't consume it.v_cvt_f32_f16without modifiers, plus SDWAWORD_0(cvt and mov).clamp, omod and integer inline constants other than 0 are refused.v_add_f16_e64refusal neighbour becomesv_min_f16_e64.@R0Y00 on GitHub · 2026-11-23 12:15 UTC · original
Choose (b) for the first slice. Require both operands to be proven finite, including register copies with established provenance. Leave arbitrary runtime operands for the extension that establishes NaN and infinity behavior. Finite overflow is a separate case. If the slice accepts it, pin the signed result at both overflow boundaries with an independent reference and integer readback. Otherwise require a result within the supported range.
An explicit entry profile is sufficient for binary16 denormal preservation when the caller gets it from validated guest state. Keep the new forms unavailable when that entry state is unknown, and refuse MODE writes that might invalidate it. Tracking the denormal field can follow separately. The distinct half16 tag and the proposed audited readers fit the low-half rule. Please include a refusal for an unknown mode and for a dynamic operand lacking the finite proof. Keep the signed-zero and subnormal cases in the draw.
@R0Y00 on GitHub · 2026-11-23 14:09 UTC · original
#854 landed the first slice: plain add, sub, subrev and mul on proven-finite low halves under the validated binary16 mode. WARP and RTX reads matched, including signed overflow, and the high-half consumption controls still refuse unsupported uses. This issue stays open for the remaining forms and arbitrary runtime operands.
@JB2WIN on GitHub · 2026-11-23 14:53 UTC · original
Thanks for landing #854. I'd like to take the next small slice under the same rules:
v_floor_f16,v_ceil_f16,v_trunc_f16andv_rndne_f16(VOP1 and_e64). LLVM 15.0.7VOP1Instructions.tdL449-452 maps them toffloor,fceil,ftruncandfrint.The plan:
widen16, then the binary32floor/ceil/trunc/round, thennarrow16. The rounded value of a finite half is itself a representable half, so the narrowing is exact.half16result read only by the audited readers.clamp, omod and modifiers.trunc(-0.5)), halfway cases forrndne(0.5, 1.5, 2.5 and -2.5), the largest finite values, subnormals and integers at 1024 and above. Mutations swap each op for another and drop the sign of a -0 result.v_fract_f16stays out because of its clamp near 1, and so domin/maxand the transcendentals. AI-assisted (Claude Code).@R0Y00 on GitHub · 2026-11-23 14:54 UTC · original
Please go ahead with the four rounding operations under the same finite-input, explicit binary16 mode and low-half-only rules as #854. Keep the existing _e32 and _e64 modifier refusals. For RNDNE, verify ties-to-even with the emitted code. For signed zero, read back the raw half bits and preserve the input sign when a result rounds to zero. Include negative subnormals: FLOOR should give -1, while CEIL and TRUNC should give -0. The positive counterpart distinguishes CEIL from TRUNC. The existing consumer and half-width rejection controls still apply.
@R0Y00 on GitHub · 2026-11-23 15:44 UTC · original
#881 merged at
b8646f5. The finite, low-half FLOOR, CEIL, TRUNC and RNDNE forms now have integer pixel readbacks and passed on WARP and RTX. All five mutations, including ties-away and lost negative zero, differed on both. The out-of-scope forms and arbitrary runtime inputs still need separate evidence, so this stays open.@JB2WIN on GitHub · 2026-11-23 15:53 UTC · original
Thanks for landing #881. Here is a proposal for the next slice; I won't start it without your go-ahead.
The candidates are
v_cvt_f16_i16andv_cvt_f16_u16(VOP1 and_e64). LLVM 15.0.7VOP1Instructions.tdL432-433 maps them tosint_to_fpanduint_to_fp. The integer input class differs from the float slices:v_cvt_f16_i16: every i16 input (−32768…32767) converts to a finite binary16 under nearest-even. No NaN or inf can arise, and the largest magnitude, 32768, is representable. So a runtime source could be accepted, as long as it is a value the existing 16-bit integer contract already reads correctly: alow16result, or a register whose low 16 bits are read.v_cvt_f16_u16: inputs ≥ 65520 round to +inf. The source would therefore need a proof that its value is below 65520, and runtime values would be refused. The alternative is to pin the overflow at the boundary, but you set that up as a separate case.Either way the result would be a
half16low half for the audited readers.clampand omod are refused, under the explicit denormal entry profile. Integers above 2048 still round, so the draw would include halfway integers such as 2049 and 4099, ±32768, -0 versus +0 (the integer 0 gives +0), and the boundary 65519/65520 for u16.Would you accept runtime i16 sources for
v_cvt_f16_i16, or keep both conversions on proven-constant sources for now? AI-assisted (Claude Code).@R0Y00 on GitHub · 2026-11-23 16:04 UTC · original
Please go ahead with runtime signed i16 through the existing audited low-16 integer reader. It must sign-extend bits 15:0, and the result stays a low-half-only binary16 value. All signed i16 inputs round to finite binary16 under the stated mode, so a constant proof is unnecessary. For u16, keep the current scope to statically proven values below 65520; reject an unproven runtime source and the overflow boundary. Keep modifiers refused.
For signed runtime cases, send distinct values through the same compiled shader and vary the high half independently. Include -32768, 32767, 2049 and its negative, and integer zero (expected +0). For unsigned constants, 65519 should round to 65504 and 65520 should be refused. Use raw-bit readback and a mutation that would catch a zero-extension or ties-away implementation.
@KomaGuy on GitHub · 2026-11-23 19:52 UTC · original
Thanks for checking @JB2WIN! Neither #419 (DPP binary16 ops) nor #421 (DPP conversions) overlaps with plain VOP1/VOP2 binary16 forms — glad #881 landed and feel free to proceed with the next plain slice.
@JB2WIN on GitHub · 2026-11-23 19:52 UTC · original
Thanks for landing #921. Here is a proposal for the reverse direction. I'll wait for your go-ahead before starting it.
The forms are
v_cvt_i16_f16andv_cvt_u16_f16, plain and_e64. LLVM 15.0.7VOP1Instructions.tdL436-437 maps them tofp_to_sintandfp_to_uint(VOP_I16_F16_SPECIAL_OMOD), which truncate toward zero. Under the existing rules, the slice would be:low16integer value, readable through the audited 16-bit integer readers from #732. The bits are the low 16 bits of the truncated integer.clampand omod.Should this slice stay on proven in-range constants, or do you want a different first step for half→int? AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 20:01 UTC · original
Please proceed with the finite, statically proven in-range slice. RDNA 2 §12.8, VOP1 entries 82 and 83, explicitly specifies truncation for both. Apply the range check to the truncated integer, then produce a low16 result and retain the existing high-half refusal. For boundary tests use exactly representable halves: 32752 and 32768 straddle the positive signed limit, and -32768 and its next lower half straddle the negative limit. 32767.5 is not representable as a half. Include -0.5 to unsigned zero, -1 refused for unsigned, 65504 for unsigned, nonfinite/unknown-source refusals, and an independent rounding mutation. Keep modifiers and output modifiers outside this slice. Use LLVM 15 assembly and exact integer readback for plain and e64.
AMD RDNA 2 ISA reference
@R0Y00 on GitHub · 2026-11-24 00:35 UTC · original
#1077 and #1084 cover the same finite, statically proven binary16-to-i16/u16 low-half conversion slice. @tedin7 and @romn4rch, please use #1077 as the integration point and bring any distinct boundary or mutation controls from #1084 over with attribution. One independent LLVM 15/WARP review of the combined candidate would help. Keep the whole-word/high-half rejection, exact signed and unsigned endpoints, and the controls for nonfinite and out-of-range inputs. The issue remains open while this slice is reviewed.
@romn4rch on GitHub · 2026-11-24 00:53 UTC · original
I compared #1084 with #1077 at
e7ab28bto find controls to bring over. Every boundary, refusal and mutation in #1084 already has a counterpart in #1077:0x77ff) and -32768 (0xf800) accepted; 32768 (0x7800) and -32800 (0xf801) refused0xb800) gives 0, 65504 (0x7bff) accepted, -1 (0xbc00) refused0x0001and0x8001Nothing needs to move. One behavioural difference: #1084 accepts both forms under round toward zero, treating the truncation as defined by the instruction, while #1077 refuses them like the other binary16 forms. I would keep #1077's refusal for this slice, because nothing here measures whether the MODE rounding field affects these conversions.
I'm closing #1084 in favour of #1077 and will run an independent LLVM 15 and WARP review of #1077.
AI-assisted.
@tedin7 on GitHub · 2026-11-24 01:04 UTC · original
Claiming v_fmac_f16_e32 and v_ldexp_f16_e32 in tools/pixel_aot.py (their disassembly is already in main). The v_cvt_i16/u16_f16 slice is #1077. Environment: Linux with LLVM 19 locally; I rely on the Ubuntu LLVM 15 job and the Windows WARP jobs for the rest. AI-assisted.
@R0Y00 on GitHub · 2026-11-24 03:17 UTC · original
Please go ahead with the two literal-K forms. Keep the low-half definedness rules and the previously tested FMA profile. An LLVM 15 assemble/disassemble check should distinguish which operand receives K. For execution, use different values for both source operands and K, a rounding case that distinguishes a fused result from two operations, and a control that puts the literal in the wrong slot. Keep whole-word and high-half consumers refused where the upper half is unknown.
github-bot referenced this issue2026-11-30 05:15:13 +00:00