authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-23 09:52:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-03 15:22:53-07:00
logd59fc1ac0418d452dc2c1a7701a08af862dc210a
tree075ceb2807aa49f1e2e55f8ca1f3883d29cbb80a
parent9349c9c4b1b964d00241bcc310951bfcd22ee86e

stage1: `@shuffle` type and mask params in comptime scope


2 files changed, 18 insertions(+), 2 deletions(-)

src/stage1/astgen.cpp+5-2
......@@ -4599,8 +4599,11 @@ static IrInstSrc *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
45994599 }
46004600 case BuiltinFnIdShuffle:
46014601 {
4602 // Used for the type expr and the mask expr
4603 Scope *comptime_scope = create_comptime_scope(ag->codegen, node, scope);
4604
46024605 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4603 IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope);
4606 IrInstSrc *arg0_value = astgen_node(ag, arg0_node, comptime_scope);
46044607 if (arg0_value == ag->codegen->invalid_inst_src)
46054608 return arg0_value;
46064609
......@@ -4615,7 +4618,7 @@ static IrInstSrc *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode
46154618 return arg2_value;
46164619
46174620 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
4618 IrInstSrc *arg3_value = astgen_node(ag, arg3_node, scope);
4621 IrInstSrc *arg3_value = astgen_node(ag, arg3_node, comptime_scope);
46194622 if (arg3_value == ag->codegen->invalid_inst_src)
46204623 return arg3_value;
46214624
test/behavior/vector.zig+13
......@@ -632,3 +632,16 @@ test "vector reduce operation" {
632632 try S.doTheTest();
633633 comptime try S.doTheTest();
634634}
635
636test "mask parameter of @shuffle is comptime scope" {
637 const __v4hi = std.meta.Vector(4, i16);
638 var v4_a = __v4hi{ 0, 0, 0, 0 };
639 var v4_b = __v4hi{ 0, 0, 0, 0 };
640 var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, std.meta.Vector(4, i32){
641 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
642 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
643 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
644 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
645 });
646 _ = shuffled;
647}