mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 08:58:02 +02:00
ac/llvm: implement byte/word extract/insert instructions
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com> Reviewed-by: Timur Kristóf <timur.kristof@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
This commit is contained in:
parent
daa329f664
commit
7d76b07d6b
1 changed files with 25 additions and 0 deletions
|
|
@ -1211,6 +1211,31 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
|
|||
break;
|
||||
}
|
||||
|
||||
case nir_op_extract_u8:
|
||||
case nir_op_extract_i8:
|
||||
case nir_op_extract_u16:
|
||||
case nir_op_extract_i16: {
|
||||
bool is_signed = instr->op == nir_op_extract_i16 || instr->op == nir_op_extract_i8;
|
||||
unsigned size = instr->op == nir_op_extract_u8 || instr->op == nir_op_extract_i8 ? 8 : 16;
|
||||
LLVMValueRef offset = LLVMConstInt(LLVMTypeOf(src[0]), nir_src_as_uint(instr->src[1].src) * size, false);
|
||||
result = LLVMBuildLShr(ctx->ac.builder, src[0], offset, "");
|
||||
result = LLVMBuildTrunc(ctx->ac.builder, result, LLVMIntTypeInContext(ctx->ac.context, size), "");
|
||||
if (is_signed)
|
||||
result = LLVMBuildSExt(ctx->ac.builder, result, LLVMTypeOf(src[0]), "");
|
||||
else
|
||||
result = LLVMBuildZExt(ctx->ac.builder, result, LLVMTypeOf(src[0]), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case nir_op_insert_u8:
|
||||
case nir_op_insert_u16: {
|
||||
unsigned size = instr->op == nir_op_insert_u8 ? 8 : 16;
|
||||
LLVMValueRef offset = LLVMConstInt(LLVMTypeOf(src[0]), nir_src_as_uint(instr->src[1].src) * size, false);
|
||||
LLVMValueRef mask = LLVMConstInt(LLVMTypeOf(src[0]), u_bit_consecutive(0, size), false);
|
||||
result = LLVMBuildShl(ctx->ac.builder, LLVMBuildAnd(ctx->ac.builder, src[0], mask, ""), offset, "");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unknown NIR alu instr: ");
|
||||
nir_print_instr(&instr->instr, stderr);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue