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-06-23 09:52:09-07:00
logfc185a6f71b9bd611a6d808082999a9da0f107e8
treea86c3bfe1fd35cdbeb0674c425bfb34def86b154
parent0134cb0214131d1a7edb18a48f54f9d25277cf84

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
......@@ -634,3 +634,16 @@ test "vector reduce operation" {
634634 try S.doTheTest();
635635 comptime try S.doTheTest();
636636}
637
638test "mask parameter of @shuffle is comptime scope" {
639 const __v4hi = std.meta.Vector(4, i16);
640 var v4_a = __v4hi{ 0, 0, 0, 0 };
641 var v4_b = __v4hi{ 0, 0, 0, 0 };
642 var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, std.meta.Vector(4, i32){
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 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
646 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
647 });
648 _ = shuffled;
649}