From ad3849259a88de04367857765f4b8d56d62dacbc Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 23 Oct 2020 16:04:04 +1000 Subject: [PATCH] gallivm: fix f16 quantize. Add the correct flush to 0 behaviour. Fixes: dEQP-VK.spirv_assembly.instruction.compute.opquantize.flush_to_zero Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 23e57809385..c8d864a2803 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -504,9 +504,18 @@ do_quantize_to_f16(struct lp_build_nir_context *bld_base, { struct gallivm_state *gallivm = bld_base->base.gallivm; LLVMBuilderRef builder = gallivm->builder; - LLVMValueRef result; + LLVMValueRef result, cond, cond2, temp; + result = LLVMBuildFPTrunc(builder, src, LLVMVectorType(LLVMHalfTypeInContext(gallivm->context), bld_base->base.type.length), ""); result = LLVMBuildFPExt(builder, result, bld_base->base.vec_type, ""); + + temp = lp_build_abs(get_flt_bld(bld_base, 32), result); + cond = LLVMBuildFCmp(builder, LLVMRealOGT, + LLVMBuildBitCast(builder, lp_build_const_int_vec(gallivm, bld_base->uint_bld.type, 0x38800000), bld_base->base.vec_type, ""), + temp, ""); + cond2 = LLVMBuildFCmp(builder, LLVMRealONE, temp, bld_base->base.zero, ""); + cond = LLVMBuildAnd(builder, cond, cond2, ""); + result = LLVMBuildSelect(builder, cond, bld_base->base.zero, result, ""); return result; }