mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Add ranges for simd compounds literals
This commit is contained in:
@@ -7741,10 +7741,6 @@ ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cl->elems.count > 0 && cl->elems[0]->kind == Ast_FieldValue) {
|
if (cl->elems.count > 0 && cl->elems[0]->kind == Ast_FieldValue) {
|
||||||
// TODO(bill): Why was this decision made for simd?
|
|
||||||
if (is_type_simd_vector(t)) {
|
|
||||||
error(cl->elems[0], "'field = value' is not allowed for SIMD vector literals");
|
|
||||||
} else {
|
|
||||||
RangeCache rc = range_cache_make(heap_allocator());
|
RangeCache rc = range_cache_make(heap_allocator());
|
||||||
defer (range_cache_destroy(&rc));
|
defer (range_cache_destroy(&rc));
|
||||||
|
|
||||||
@@ -7845,8 +7841,6 @@ ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *
|
|||||||
}
|
}
|
||||||
|
|
||||||
cl->max_count = max;
|
cl->max_count = max;
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
isize index = 0;
|
isize index = 0;
|
||||||
for (; index < cl->elems.count; index++) {
|
for (; index < cl->elems.count; index++) {
|
||||||
|
|||||||
@@ -819,10 +819,64 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
|||||||
return lb_const_nil(m, original_type);
|
return lb_const_nil(m, original_type);
|
||||||
}
|
}
|
||||||
GB_ASSERT(elem_type_can_be_constant(elem_type));
|
GB_ASSERT(elem_type_can_be_constant(elem_type));
|
||||||
|
|
||||||
isize total_elem_count = cast(isize)type->SimdVector.count;
|
isize total_elem_count = cast(isize)type->SimdVector.count;
|
||||||
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, total_elem_count);
|
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, total_elem_count);
|
||||||
|
|
||||||
|
if (cl->elems[0]->kind == Ast_FieldValue) {
|
||||||
|
// TODO(bill): This is O(N*M) and will be quite slow; it should probably be sorted before hand
|
||||||
|
isize value_index = 0;
|
||||||
|
for (i64 i = 0; i < total_elem_count; i++) {
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (isize j = 0; j < elem_count; j++) {
|
||||||
|
Ast *elem = cl->elems[j];
|
||||||
|
ast_node(fv, FieldValue, elem);
|
||||||
|
if (is_ast_range(fv->field)) {
|
||||||
|
ast_node(ie, BinaryExpr, fv->field);
|
||||||
|
TypeAndValue lo_tav = ie->left->tav;
|
||||||
|
TypeAndValue hi_tav = ie->right->tav;
|
||||||
|
GB_ASSERT(lo_tav.mode == Addressing_Constant);
|
||||||
|
GB_ASSERT(hi_tav.mode == Addressing_Constant);
|
||||||
|
|
||||||
|
TokenKind op = ie->op.kind;
|
||||||
|
i64 lo = exact_value_to_i64(lo_tav.value);
|
||||||
|
i64 hi = exact_value_to_i64(hi_tav.value);
|
||||||
|
if (op != Token_RangeHalf) {
|
||||||
|
hi += 1;
|
||||||
|
}
|
||||||
|
if (lo == i) {
|
||||||
|
TypeAndValue tav = fv->value->tav;
|
||||||
|
LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value;
|
||||||
|
for (i64 k = lo; k < hi; k++) {
|
||||||
|
values[value_index++] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
i += (hi-lo-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TypeAndValue index_tav = fv->field->tav;
|
||||||
|
GB_ASSERT(index_tav.mode == Addressing_Constant);
|
||||||
|
i64 index = exact_value_to_i64(index_tav.value);
|
||||||
|
if (index == i) {
|
||||||
|
TypeAndValue tav = fv->value->tav;
|
||||||
|
LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value;
|
||||||
|
values[value_index++] = val;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
values[value_index++] = LLVMConstNull(lb_type(m, elem_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.value = LLVMConstVector(values, cast(unsigned)total_elem_count);
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
for (isize i = 0; i < elem_count; i++) {
|
for (isize i = 0; i < elem_count; i++) {
|
||||||
TypeAndValue tav = cl->elems[i]->tav;
|
TypeAndValue tav = cl->elems[i]->tav;
|
||||||
GB_ASSERT(tav.mode != Addressing_Invalid);
|
GB_ASSERT(tav.mode != Addressing_Invalid);
|
||||||
@@ -830,7 +884,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
|||||||
}
|
}
|
||||||
LLVMTypeRef et = lb_type(m, elem_type);
|
LLVMTypeRef et = lb_type(m, elem_type);
|
||||||
|
|
||||||
for (isize i = elem_count; i < type->SimdVector.count; i++) {
|
for (isize i = elem_count; i < total_elem_count; i++) {
|
||||||
values[i] = LLVMConstNull(et);
|
values[i] = LLVMConstNull(et);
|
||||||
}
|
}
|
||||||
for (isize i = 0; i < total_elem_count; i++) {
|
for (isize i = 0; i < total_elem_count; i++) {
|
||||||
@@ -839,6 +893,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
|||||||
|
|
||||||
res.value = LLVMConstVector(values, cast(unsigned)total_elem_count);
|
res.value = LLVMConstVector(values, cast(unsigned)total_elem_count);
|
||||||
return res;
|
return res;
|
||||||
|
}
|
||||||
} else if (is_type_struct(type)) {
|
} else if (is_type_struct(type)) {
|
||||||
ast_node(cl, CompoundLit, value.value_compound);
|
ast_node(cl, CompoundLit, value.value_compound);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user