From 6decb1b8969fed72c03db84fd622b671367a87a3 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 19 Jul 2021 12:49:00 +1000 Subject: [PATCH] gallivm: add 16-bit sin/cos via llvm intrinsic Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_arit.c | 22 +++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_nir.c | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c index 14fda8db0f3..b6e9ebd4546 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -3012,6 +3012,17 @@ LLVMValueRef lp_build_sin(struct lp_build_context *bld, LLVMValueRef a) { + const struct lp_type type = bld->type; + + if (type.width == 16) { + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + char intrinsic[32]; + lp_format_intrinsic(intrinsic, sizeof intrinsic, "llvm.sin", vec_type); + LLVMValueRef args[] = { a }; + return lp_build_intrinsic(builder, intrinsic, vec_type, args, 1, 0); + } + return lp_build_sin_or_cos(bld, a, FALSE); } @@ -3023,6 +3034,17 @@ LLVMValueRef lp_build_cos(struct lp_build_context *bld, LLVMValueRef a) { + const struct lp_type type = bld->type; + + if (type.width == 16) { + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + char intrinsic[32]; + lp_format_intrinsic(intrinsic, sizeof intrinsic, "llvm.cos", vec_type); + LLVMValueRef args[] = { a }; + return lp_build_intrinsic(builder, intrinsic, vec_type, args, 1, 0); + } + return lp_build_sin_or_cos(bld, a, TRUE); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 78e644db009..28c7eafe54a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -684,7 +684,7 @@ static LLVMValueRef do_alu_action(struct lp_build_nir_context *bld_base, result = lp_build_ceil(get_flt_bld(bld_base, src_bit_size[0]), src[0]); break; case nir_op_fcos: - result = lp_build_cos(&bld_base->base, src[0]); + result = lp_build_cos(get_flt_bld(bld_base, src_bit_size[0]), src[0]); break; case nir_op_fddx: case nir_op_fddx_coarse: @@ -810,7 +810,7 @@ static LLVMValueRef do_alu_action(struct lp_build_nir_context *bld_base, result = lp_build_sgn(get_flt_bld(bld_base, src_bit_size[0]), src[0]); break; case nir_op_fsin: - result = lp_build_sin(&bld_base->base, src[0]); + result = lp_build_sin(get_flt_bld(bld_base, src_bit_size[0]), src[0]); break; case nir_op_fsqrt: result = lp_build_sqrt(get_flt_bld(bld_base, src_bit_size[0]), src[0]);