amd/common: lower bitfield_extract to ubfe/ibfe.
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:

committed by
Daniel Schürmann

parent
48a75e7af0
commit
0daeb1d127
@@ -2798,11 +2798,22 @@ LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
|
||||
width,
|
||||
};
|
||||
|
||||
return ac_build_intrinsic(ctx,
|
||||
is_signed ? "llvm.amdgcn.sbfe.i32" :
|
||||
"llvm.amdgcn.ubfe.i32",
|
||||
ctx->i32, args, 3,
|
||||
AC_FUNC_ATTR_READNONE);
|
||||
LLVMValueRef result = ac_build_intrinsic(ctx,
|
||||
is_signed ? "llvm.amdgcn.sbfe.i32" :
|
||||
"llvm.amdgcn.ubfe.i32",
|
||||
ctx->i32, args, 3,
|
||||
AC_FUNC_ATTR_READNONE);
|
||||
|
||||
if (HAVE_LLVM < 0x0800) {
|
||||
/* FIXME: LLVM 7+ returns incorrect result when count is 0.
|
||||
* https://bugs.freedesktop.org/show_bug.cgi?id=107276
|
||||
*/
|
||||
LLVMValueRef zero = ctx->i32_0;
|
||||
LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, width, zero, "");
|
||||
result = LLVMBuildSelect(ctx->builder, icond, zero, result, "");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0,
|
||||
|
@@ -429,32 +429,6 @@ static LLVMValueRef emit_imul_high(struct ac_llvm_context *ctx,
|
||||
return result;
|
||||
}
|
||||
|
||||
static LLVMValueRef emit_bitfield_extract(struct ac_llvm_context *ctx,
|
||||
bool is_signed,
|
||||
const LLVMValueRef srcs[3])
|
||||
{
|
||||
LLVMValueRef result;
|
||||
|
||||
if (HAVE_LLVM >= 0x0800) {
|
||||
LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], LLVMConstInt(ctx->i32, 32, false), "");
|
||||
result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], is_signed);
|
||||
result = LLVMBuildSelect(ctx->builder, icond, srcs[0], result, "");
|
||||
} else {
|
||||
/* FIXME: LLVM 7+ returns incorrect result when count is 0.
|
||||
* https://bugs.freedesktop.org/show_bug.cgi?id=107276
|
||||
*/
|
||||
LLVMValueRef zero = ctx->i32_0;
|
||||
LLVMValueRef icond1 = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], LLVMConstInt(ctx->i32, 32, false), "");
|
||||
LLVMValueRef icond2 = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], zero, "");
|
||||
|
||||
result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], is_signed);
|
||||
result = LLVMBuildSelect(ctx->builder, icond1, srcs[0], result, "");
|
||||
result = LLVMBuildSelect(ctx->builder, icond2, zero, result, "");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static LLVMValueRef emit_bfm(struct ac_llvm_context *ctx,
|
||||
LLVMValueRef bits, LLVMValueRef offset)
|
||||
{
|
||||
@@ -837,11 +811,11 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
|
||||
case nir_op_bitfield_select:
|
||||
result = emit_bitfield_select(&ctx->ac, src[0], src[1], src[2]);
|
||||
break;
|
||||
case nir_op_ibitfield_extract:
|
||||
result = emit_bitfield_extract(&ctx->ac, true, src);
|
||||
case nir_op_ubfe:
|
||||
result = ac_build_bfe(&ctx->ac, src[0], src[1], src[2], false);
|
||||
break;
|
||||
case nir_op_ubitfield_extract:
|
||||
result = emit_bitfield_extract(&ctx->ac, false, src);
|
||||
case nir_op_ibfe:
|
||||
result = ac_build_bfe(&ctx->ac, src[0], src[1], src[2], true);
|
||||
break;
|
||||
case nir_op_bitfield_reverse:
|
||||
result = ac_build_bitfield_reverse(&ctx->ac, src[0]);
|
||||
|
@@ -59,6 +59,7 @@ static const struct nir_shader_compiler_options nir_options = {
|
||||
.lower_fsat = true,
|
||||
.lower_fdiv = true,
|
||||
.lower_bitfield_insert_to_bitfield_select = true,
|
||||
.lower_bitfield_extract = true,
|
||||
.lower_sub = true,
|
||||
.lower_pack_snorm_2x16 = true,
|
||||
.lower_pack_snorm_4x8 = true,
|
||||
|
@@ -488,6 +488,7 @@ static const struct nir_shader_compiler_options nir_options = {
|
||||
.lower_fsat = true,
|
||||
.lower_fdiv = true,
|
||||
.lower_bitfield_insert_to_bitfield_select = true,
|
||||
.lower_bitfield_extract = true,
|
||||
.lower_sub = true,
|
||||
.lower_ffma = true,
|
||||
.lower_fmod = true,
|
||||
|
Reference in New Issue
Block a user