feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transShufflevectorExpr
fn transShufflevectorExpr(
t: *Translator,
scope: *Scope,
shufflevector: Node.Shufflevector,
) TransError!ZigNode
File
Code
fn transShufflevectorExpr(
t: *Translator,
scope: *Scope,
shufflevector: Node.Shufflevector,
) TransError!ZigNode {
if (shufflevector.indexes.len == 0) {
return t.fail(error.UnsupportedTranslation, shufflevector.builtin_tok, "@shuffle needs at least 1 index", .{});
}
const a = try t.transExpr(scope, shufflevector.lhs, .used);
const b = try t.transExpr(scope, shufflevector.rhs, .used);
const vector_child_type = try t.vectorTypeInfo(a, "child");
const vector_len = try t.vectorTypeInfo(a, "len");
const shuffle_mask = blk: {
const mask_len = shufflevector.indexes.len;
const mask_type = try ZigTag.vector.create(t.arena, .{
.lhs = try t.createNumberNode(mask_len),
.rhs = try ZigTag.type.create(t.arena, "i32"),
});
const init_list = try t.arena.alloc(ZigNode, mask_len);
for (init_list, shufflevector.indexes) |*init, index| {
const index_expr = try t.transExprCoercing(scope, index, .used);
const converted_index = try t.createHelperCallNode(.shuffleVectorIndex, &.{ index_expr, vector_len });
init.* = converted_index;
}
break :blk try ZigTag.array_init.create(t.arena, .{
.cond = mask_type,
.cases = init_list,
});
};
return ZigTag.shuffle.create(t.arena, .{
.element_type = vector_child_type,
.a = a,
.b = b,
.mask_vector = shuffle_mask,
});
}