Make simd_shuffle act closer to swizzle

This commit is contained in:
gingerBill
2022-05-26 00:36:24 +01:00
parent c2f5cbdeb4
commit cde6a2f7a5
5 changed files with 59 additions and 58 deletions
+11 -3
View File
@@ -1282,15 +1282,23 @@ lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const
case BuiltinProc_simd_shuffle:
{
arg1 = lb_build_expr(p, ce->args[1]);
arg2 = lb_build_expr(p, ce->args[2]);
Type *vt = arg0.type;
GB_ASSERT(vt->kind == Type_SimdVector);
LLVMValueRef mask = arg2.value;
i64 mask_count = ce->args.count-2;
i64 max_count = vt->SimdVector.count*2;
LLVMValueRef max_mask = llvm_splat_int(max_count, lb_type(m, arg2.type->SimdVector.elem), max_count-1);
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, mask_count);
for (isize i = 0; i < max_count; i++) {
lbValue idx = lb_build_expr(p, ce->args[i+2]);
GB_ASSERT(LLVMIsConstant(idx.value));
values[i] = idx.value;
}
LLVMValueRef mask = LLVMConstVector(values, cast(unsigned)mask_count);
LLVMValueRef max_mask = llvm_splat_int(mask_count, lb_type(m, t_u32), max_count-1);
mask = LLVMBuildAnd(p->builder, mask, max_mask, "");
res.value = LLVMBuildShuffleVector(p->builder, arg0.value, arg1.value, mask, "");