Repository navigation
Conversation
…igned and packed adds and dots
The f64 VALU path, v_cvt_f32_f64 and v_cvt_f16_f32 dropped omod (and the two
conversions dropped clamp too). Integer clamp (saturation) was handled only
on v_add_nc_i32 / v_sub_nc_i32; v_add_nc_u32, v_sub_nc_u32, v_subrev_nc_u32,
v_add3_u32, v_pk_{add,sub}_{u16,i16}, v_pk_mad_{u16,i16} and the integer
dot products wrapped instead.
f64 clamp already kept double precision (DXIL has a double saturate), so it
stays. v_cvt_f16_f32 applies the modifiers in f32 before rounding: the same
f16 except where it is denormal.
Test gpu_clamp_and_omod_per_instruction: every changed instruction, with
the non-clamp forms of an add, a packed add and a dot as a control.
34efd81 to
28caa63
Compare
|
Merged. It conflicted with fdeacf0, which made the plain |
|
Closing by hand: your rebase (28caa63) landed while I merged the earlier head (34efd81, merge 73c7bbe on |
Follow-up to xcl-dev#119 (issue xcl-dev#105 item 4), covering the remaining RDNA2 VALU integer instructions that support CLAMP=1 saturation and previously ignored it: - 16-bit integer (valu16 / valu_pk): v_add_nc_u16, v_sub_nc_u16, v_add_nc_i16, v_sub_nc_i16, v_mul_lo_u16, v_mad_u16, v_mad_i16, and v_pk_mul_lo_u16 (plus the legacy u16 aliases already matched in valu16) - 32-bit 24x24 / 16x16 mul/mad: v_mul_u32_u24, v_mul_i32_i24, v_mad_u32_u24, v_mad_i32_i24, v_mad_u32_u16, v_mad_i32_i16 (including SDWA CLAMP=1 forms via Self::mods) - 32-bit SAD/MSAD: v_sad_u32, v_sad_u8, v_sad_hi_u8, v_sad_u16, v_msad_u8 - 32-bit carry-out / carry-in: v_add_co_u32, v_sub_co_u32, v_subrev_co_u32, v_add_co_ci_u32, v_sub_co_ci_u32, v_subrev_co_ci_u32 (VOP3 + SDWA; saturates VDST while preserving unclamped carry/borrow in SDST/VCC) - 64-bit integer MAD (valu64): v_mad_u64_u32 and v_mad_i64_i32 (saturates 64-bit VDST while preserving the unclamped 65-bit SDST bit: unsigned carry-out for u64, bit 64 sign bit of the true 65-bit signed sum for v_mad_i64_i32) Compiler / backend fixes in the HLSL prelude: - sat_u32(uint64_t) uses branchless (uint)r | (0u - min((uint)(r >> 32), 1u)) instead of select(r > 0xFFFFFFFFu, ...): Windows SDK DXC 1.7-1.9.2602 lowers the select form on 64-bit products (v_mul_u32_u24 CLAMP=1) into forbidden llvm.umul.with.overflow.i32, failing DXIL validation. - Adds sat_i16(int) using select instead of ((uint)clamp(r, -32768, 32767) & 0xFFFFu) across 16-bit signed saturation sites: NVIDIA 610.57.4 (Vulkan / vkd3d-proton) drops the & 0xFFFF mask after SMin(SMax(r, -32768), 32767), leaking sign bits into the upper half of the destination VGPR. Adds GPU tests (wave64 + wave32) and a CPU-only HLSL codegen test covering CLAMP=1 saturation, CLAMP=0 wrapping, boundary pairs, SDST/VCC masks, SDWA CLAMP=1, and confirming v_cvt_pkrtz_f16_f32 ignores VOP3 OMOD/CLAMP.
#105 item 4.
Dropped before this change:
v_cvt_f32_f64andv_cvt_f16_f32;v_add_nc_u32,v_sub_nc_u32,v_subrev_nc_u32,v_add3_u32,v_pk_add/sub_u16,v_pk_add/sub_i16,v_pk_mad_u16/i16,v_dot2_{i32_i16,u32_u16},v_dot4_{i32_i8,u32_u8}andv_dot8_{i32_i4,u32_u4}. These wrapped instead.One point of the audit was wrong: f64 clamp did not narrow to float. DXIL has a double
Saturate, and the test confirms clamp keeps double precision on main. So that part is not changed.Notes:
v_cvt_f16_f32applies the modifiers in f32 before the rounding. The f16 is the same except where it is denormal.sat_u32, next tosat_i32. No-Gis(per Floating-point modes: the non-fused MAD/MAC family needsprecise, and thes_round_modeNOOPs are not free #73).Test
gpu_clamp_and_omod_per_instruction: every changed instruction once, with values that saturate. The non-clamp forms of an add, a packed add and a dot are controls that must still wrap. Without the emit change it fails (first atv_add_f64omod). With it, it passes on a GTX 1650 under Wine (vkd3d-proton), and so do the other lib tests that run there. Not run on AMD.