aboutsummaryrefslogtreecommitdiff
path: root/src/types.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/types.cpp
parent9a41a450e7b234e72591ab141e05a1dd7fd0cb30 (diff)
Support swizzle selector syntax `.xyzw` for `#simd` vectors
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp71
1 files changed, 46 insertions, 25 deletions
diff --git a/src/types.cpp b/src/types.cpp
index e9e91dcd4..5a3ad5d6b 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -3430,31 +3430,6 @@ gb_internal Selection lookup_field_with_selection(Type *type_, String field_name
}
return sel;
- } else if (type->kind == Type_Array) {
- if (type->Array.count <= 4) {
- // HACK(bill): Memory leak
- switch (type->Array.count) {
- #define _ARRAY_FIELD_CASE_IF(_length, _name) \
- if (field_name == (_name)) { \
- selection_add_index(&sel, (_length)-1); \
- sel.entity = alloc_entity_array_elem(nullptr, make_token_ident(str_lit(_name)), type->Array.elem, (_length)-1); \
- return sel; \
- }
- #define _ARRAY_FIELD_CASE(_length, _name0, _name1) \
- case (_length): \
- _ARRAY_FIELD_CASE_IF(_length, _name0); \
- _ARRAY_FIELD_CASE_IF(_length, _name1); \
- /*fallthrough*/
-
- _ARRAY_FIELD_CASE(4, "w", "a");
- _ARRAY_FIELD_CASE(3, "z", "b");
- _ARRAY_FIELD_CASE(2, "y", "g");
- _ARRAY_FIELD_CASE(1, "x", "r");
- default: break;
-
- #undef _ARRAY_FIELD_CASE
- }
- }
} else if (type->kind == Type_DynamicArray) {
GB_ASSERT(t_allocator != nullptr);
String allocator_str = str_lit("allocator");
@@ -3475,7 +3450,53 @@ gb_internal Selection lookup_field_with_selection(Type *type_, String field_name
sel.entity = entity__allocator;
return sel;
}
+
+
+#define _ARRAY_FIELD_CASE_IF(_length, _name) \
+ if (field_name == (_name)) { \
+ selection_add_index(&sel, (_length)-1); \
+ sel.entity = alloc_entity_array_elem(nullptr, make_token_ident(str_lit(_name)), elem, (_length)-1); \
+ return sel; \
}
+#define _ARRAY_FIELD_CASE(_length, _name0, _name1) \
+case (_length): \
+ _ARRAY_FIELD_CASE_IF(_length, _name0); \
+ _ARRAY_FIELD_CASE_IF(_length, _name1); \
+ /*fallthrough*/
+
+
+ } else if (type->kind == Type_Array) {
+
+ Type *elem = type->Array.elem;
+
+ if (type->Array.count <= 4) {
+ // HACK(bill): Memory leak
+ switch (type->Array.count) {
+
+ _ARRAY_FIELD_CASE(4, "w", "a");
+ _ARRAY_FIELD_CASE(3, "z", "b");
+ _ARRAY_FIELD_CASE(2, "y", "g");
+ _ARRAY_FIELD_CASE(1, "x", "r");
+ default: break;
+ }
+ }
+ } else if (type->kind == Type_SimdVector) {
+
+ Type *elem = type->SimdVector.elem;
+ if (type->SimdVector.count <= 4) {
+ // HACK(bill): Memory leak
+ switch (type->SimdVector.count) {
+ _ARRAY_FIELD_CASE(4, "w", "a");
+ _ARRAY_FIELD_CASE(3, "z", "b");
+ _ARRAY_FIELD_CASE(2, "y", "g");
+ _ARRAY_FIELD_CASE(1, "x", "r");
+ default: break;
+ }
+ }
+ }
+
+#undef _ARRAY_FIELD_CASE
+#undef _ARRAY_FIELD_CASE
return sel;
}