aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-03-12 12:11:48 +0000
committergingerBill <bill@gingerbill.org>2024-03-12 12:11:48 +0000
commitc7c68520577133d6332bd6df98c44e751b571c03 (patch)
tree86c148c954f63da90da166548a63abc3b91351fe /src/check_expr.cpp
parent9a41a450e7b234e72591ab141e05a1dd7fd0cb30 (diff)
Support swizzle selector syntax `.xyzw` for `#simd` vectors
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 3a8cdf0b1..0911e48cf 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -4920,7 +4920,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
}
}
- if (entity == nullptr && selector->kind == Ast_Ident && is_type_array(type_deref(operand->type))) {
+ if (entity == nullptr && selector->kind == Ast_Ident && (is_type_array(type_deref(operand->type)) || is_type_simd_vector(type_deref(operand->type)))) {
String field_name = selector->Ident.token.string;
if (1 < field_name.len && field_name.len <= 4) {
u8 swizzles_xyzw[4] = {'x', 'y', 'z', 'w'};
@@ -4975,8 +4975,10 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
Type *original_type = operand->type;
Type *array_type = base_type(type_deref(original_type));
- GB_ASSERT(array_type->kind == Type_Array);
- i64 array_count = array_type->Array.count;
+ GB_ASSERT(array_type->kind == Type_Array || array_type->kind == Type_SimdVector);
+
+ i64 array_count = get_array_type_count(array_type);
+
for (u8 i = 0; i < index_count; i++) {
u8 idx = indices>>(i*2) & 3;
if (idx >= array_count) {
@@ -4996,7 +4998,6 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
se->swizzle_count = index_count;
se->swizzle_indices = indices;
-
AddressingMode prev_mode = operand->mode;
operand->mode = Addressing_SwizzleValue;
operand->type = determine_swizzle_array_type(original_type, type_hint, index_count);
@@ -5010,6 +5011,10 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
break;
}
+ if (array_type->kind == Type_SimdVector) {
+ operand->mode = Addressing_Value;
+ }
+
Entity *swizzle_entity = alloc_entity_variable(nullptr, make_token_ident(field_name), operand->type, EntityState_Resolved);
add_type_and_value(c, operand->expr, operand->mode, operand->type, operand->value);
return swizzle_entity;