mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-31 02:12:04 +00:00
Support swizzle selector syntax .xyzw for #simd vectors
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user