diff --git a/crates/xcl/src/gpu/dxil/lower.rs b/crates/xcl/src/gpu/dxil/lower.rs index 3d4c760f4..517e52798 100644 --- a/crates/xcl/src/gpu/dxil/lower.rs +++ b/crates/xcl/src/gpu/dxil/lower.rs @@ -1978,7 +1978,7 @@ pub fn is_f16_rounded_op(name: &str) -> bool { name, "v_interp_p2_f16" | "v_cvt_f16_f32" | "v_fma_mixlo_f16" | "v_fma_mixhi_f16" | "v_pk_add_f16" | "v_pk_mul_f16" | "v_pk_fma_f16" | "v_pk_fmac_f16" | "v_pk_min_f16" | "v_pk_max_f16" | "v_add_f16" | "v_sub_f16" | "v_subrev_f16" | "v_mul_f16" | "v_min_f16" - | "v_max_f16" | "v_fma_f16" | "v_med3_f16" | "v_min3_f16" | "v_max3_f16" | "v_frexp_mant_f16" | "v_mad_f16" | "v_fmac_f16" + | "v_max_f16" | "v_fma_f16" | "v_med3_f16" | "v_min3_f16" | "v_max3_f16" | "v_frexp_mant_f16" | "v_mad_f16" | "v_div_fixup_f16" | "v_fmac_f16" | "v_fmamk_f16" | "v_fmaak_f16" | "v_ldexp_f16" | "v_rcp_f16" | "v_rsq_f16" | "v_sqrt_f16" | "v_log_f16" | "v_exp_f16" | "v_sin_f16" | "v_cos_f16" | "v_fract_f16" | "v_floor_f16" | "v_ceil_f16" | "v_trunc_f16" | "v_rndne_f16" | "v_cvt_f16_u16" | "v_cvt_f16_i16" diff --git a/crates/xcl/src/gpu/dxil/lower_wide.rs b/crates/xcl/src/gpu/dxil/lower_wide.rs index 6c4003035..7aa0819ea 100644 --- a/crates/xcl/src/gpu/dxil/lower_wide.rs +++ b/crates/xcl/src/gpu/dxil/lower_wide.rs @@ -450,6 +450,7 @@ impl Lw { "v_max_f16" => f2!(|s: &mut Self, x, y| s.fmax(x, y)), "v_fma_f16" => f3!(|s: &mut Self, x, y, w| s.fmad(x, y, w)), "v_med3_f16" => f3!(|s: &mut Self, x, y, w| s.med3f(x, y, w)), + "v_div_fixup_f16" => f3!(|s: &mut Self, x, y, w| s.div_fixup(x, y, w)), "v_min3_f16" => f3!(|s: &mut Self, x, y, w| { let t = s.fmin(x, y); s.fmin(t, w) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 96966005b..c56f74fdc 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -417,6 +417,7 @@ fn is_f16_rounded_op(name: &str) -> bool { | "v_max3_f16" | "v_frexp_mant_f16" | "v_mad_f16" + | "v_div_fixup_f16" | "v_fmac_f16" | "v_fmamk_f16" | "v_fmaak_f16" @@ -2988,6 +2989,7 @@ impl Em { "v_max_f16" => fr(format!("max({}, {})", fh(0), fh(1))), "v_fma_f16" => fr(format!("mad({}, {}, {})", fh(0), fh(1), fh(2))), "v_med3_f16" => fr(format!("med3f({}, {}, {})", fh(0), fh(1), fh(2))), + "v_div_fixup_f16" => fr(format!("div_fixup({}, {}, {})", fh(0), fh(1), fh(2))), "v_min3_f16" => fr(format!("min(min({}, {}), {})", fh(0), fh(1), fh(2))), "v_max3_f16" => fr(format!("max(max({}, {}), {})", fh(0), fh(1), fh(2))), "v_med3_u16" => format!("med3u({a}, {b}, {c})"), diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index e1f73ef48..34a7418d9 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -594,6 +594,16 @@ fn cvt_norm_f16_instructions() { assert!(t.hlsl.contains("cvt_norm_u16_f16((0x00003C00u & 0xFFFFu))") && t.hlsl.contains("cvt_norm_u16_f16((0x0000BC00u & 0xFFFFu))"), "{}", t.hlsl); } +/// `v_div_fixup_f16` (VOP3, three f16 sources: quotient, denominator, numerator) is translated +/// like `v_div_fixup_f32`, on half-precision operands, instead of being left as unsupported. +#[test] +fn div_fixup_f16_instruction() { + let code = prog(&[("V_DIV_FIXUP_F16", "ENC_VOP3", &[("VDST", 1), ("SRC0", V + 9), ("SRC1", V + 10), ("SRC2", V + 11)], None)]); + let t = translate(&code, &Options::default()).unwrap(); + assert!(t.complete(), "{:?}", t.unsupported); + assert!(t.hlsl.contains("div_fixup(f16tof32(((v9) & 0xFFFFu)), f16tof32(((v10) & 0xFFFFu)), f16tof32(((v11) & 0xFFFFu)))"), "{}", t.hlsl); +} + /// GPU verification of exact RNE rounding and edge cases for `V_CVT_NORM_*_F16` and /// `V_CVT_PKNORM_*_F16`: catches binary32 double-rounding (`0x3801`/`0xB801`), DXIL /// `clamp(NaN, -1, 1)` returning ±32767 instead of 0, ±Inf, ±0, subnormals, and VOP3 abs/neg.