summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2020-06-19 16:59:11 +1000
committerDave Airlie <airlied@redhat.com>2020-07-27 13:48:11 +1000
commita0d8d49f4dcb8e0809a3f880042302df1bcfeef1 (patch)
tree461b4b5fee0b71633fd5624d23e60e6ff9ef47c1
parentb509e4ef3f9d8e42c35d206f72b2d274a151c907 (diff)
gallivm/nir: add quantize to f16 support
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_nir.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c
index 26bfb4bb014..e1a101eaca0 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c
@@ -443,6 +443,18 @@ do_int_mod(struct lp_build_nir_context *bld_base,
return LLVMBuildOr(builder, div_mask, result, "");
}
+static LLVMValueRef
+do_quantize_to_f16(struct lp_build_nir_context *bld_base,
+ LLVMValueRef src)
+{
+ struct gallivm_state *gallivm = bld_base->base.gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef result;
+ result = LLVMBuildFPTrunc(builder, src, LLVMVectorType(LLVMHalfTypeInContext(gallivm->context), bld_base->base.type.length), "");
+ result = LLVMBuildFPExt(builder, result, bld_base->base.vec_type, "");
+ return result;
+}
+
static LLVMValueRef do_alu_action(struct lp_build_nir_context *bld_base,
nir_op op, unsigned src_bit_size[NIR_MAX_VEC_COMPONENTS], LLVMValueRef src[NIR_MAX_VEC_COMPONENTS])
{
@@ -587,6 +599,9 @@ static LLVMValueRef do_alu_action(struct lp_build_nir_context *bld_base,
case nir_op_fpow:
result = lp_build_pow(&bld_base->base, src[0], src[1]);
break;
+ case nir_op_fquantize2f16:
+ result = do_quantize_to_f16(bld_base, src[0]);
+ break;
case nir_op_frcp:
result = lp_build_rcp(get_flt_bld(bld_base, src_bit_size[0]), src[0]);
break;