mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-22 13:44:59 -07:00
Make simd_shuffle act closer to swizzle
This commit is contained in:
@@ -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, "");
|
||||
|
||||
Reference in New Issue
Block a user