gallivm: add 16-bit sin/cos via llvm intrinsic

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11816>
This commit is contained in:
Dave Airlie 2021-07-19 12:49:00 +10:00 committed by Marge Bot
parent af49f9697a
commit 6decb1b896
2 changed files with 24 additions and 2 deletions

View file

@ -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);
}

View file

@ -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]);