aco: always use rtne for fquantize2f16
authorGeorg Lehmann <dadschoorse@gmail.com>
Thu, 10 Aug 2023 18:55:04 +0000 (20:55 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 11 Aug 2023 12:37:23 +0000 (12:37 +0000)
The SPIR-V spec says:

If Value is positive with a magnitude too large to represent as a
16-bit floating-point value, the result is positive infinity.
If Value is negative with a magnitude too large to represent as a
16-bit floating-point value, the result is negative infinity.

This is only the case for rtne v_cvt_f16_f32

Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24617>

src/amd/compiler/aco_instruction_selection.cpp

index 12c9588..f4bcadd 100644 (file)
@@ -3375,7 +3375,11 @@ visit_alu_instr(isel_context* ctx, nir_alu_instr* instr)
    }
    case nir_op_fquantize2f16: {
       Temp src = get_alu_src(ctx, instr->src[0]);
-      Temp f16 = bld.vop1(aco_opcode::v_cvt_f16_f32, bld.def(v2b), src);
+      Temp f16;
+      if (ctx->block->fp_mode.round16_64 != fp_round_ne)
+         f16 = bld.vop1(aco_opcode::p_cvt_f16_f32_rtne, bld.def(v2b), src);
+      else
+         f16 = bld.vop1(aco_opcode::v_cvt_f16_f32, bld.def(v2b), src);
       Temp f32, cmp_res;
 
       if (ctx->program->gfx_level >= GFX8) {