Skip to content

Commit fc185a6

Browse files
committed
stage1: @shuffle type and mask params in comptime scope
1 parent 0134cb0 commit fc185a6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/stage1/astgen.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,16 @@ test "vector reduce operation" {
634634
try S.doTheTest();
635635
comptime try S.doTheTest();
636636
}
637+
638+
test "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+
}

0 commit comments

Comments
 (0)