mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52:22 -07:00
Correct index to offset calculation for matrix compound literals
This commit is contained in:
@@ -1013,7 +1013,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
||||
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++) {
|
||||
i64 offset = matrix_index_to_offset(type, k);
|
||||
i64 offset = matrix_row_major_index_to_offset(type, k);
|
||||
GB_ASSERT(values[offset] == nullptr);
|
||||
values[offset] = val;
|
||||
}
|
||||
@@ -1023,7 +1023,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
||||
i64 index = exact_value_to_i64(index_tav.value);
|
||||
TypeAndValue tav = fv->value->tav;
|
||||
LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value;
|
||||
i64 offset = matrix_index_to_offset(type, index);
|
||||
i64 offset = matrix_row_major_index_to_offset(type, index);
|
||||
GB_ASSERT(values[offset] == nullptr);
|
||||
values[offset] = val;
|
||||
}
|
||||
@@ -1045,7 +1045,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
||||
for_array(i, cl->elems) {
|
||||
TypeAndValue tav = cl->elems[i]->tav;
|
||||
GB_ASSERT(tav.mode != Addressing_Invalid);
|
||||
i64 offset = matrix_index_to_offset(type, i);
|
||||
i64 offset = matrix_row_major_index_to_offset(type, i);
|
||||
values[offset] = lb_const_value(m, elem_type, tav.value, allow_local).value;
|
||||
}
|
||||
for (isize i = 0; i < total_count; i++) {
|
||||
|
||||
@@ -4465,7 +4465,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
lbCompoundLitElemTempData data = {};
|
||||
data.value = value;
|
||||
|
||||
data.elem_index = cast(i32)matrix_index_to_offset(bt, k);
|
||||
data.elem_index = cast(i32)matrix_row_major_index_to_offset(bt, k);
|
||||
array_add(&temp_data, data);
|
||||
}
|
||||
|
||||
@@ -4479,7 +4479,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
data.value = lb_emit_conv(p, value, et);
|
||||
data.expr = fv->value;
|
||||
|
||||
data.elem_index = cast(i32)matrix_index_to_offset(bt, index);
|
||||
data.elem_index = cast(i32)matrix_row_major_index_to_offset(bt, index);
|
||||
array_add(&temp_data, data);
|
||||
}
|
||||
|
||||
@@ -4489,7 +4489,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
}
|
||||
lbCompoundLitElemTempData data = {};
|
||||
data.expr = elem;
|
||||
data.elem_index = cast(i32)matrix_index_to_offset(bt, i);
|
||||
data.elem_index = cast(i32)matrix_row_major_index_to_offset(bt, i);
|
||||
array_add(&temp_data, data);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1408,12 +1408,13 @@ i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) {
|
||||
i64 stride_elems = matrix_type_stride_in_elems(t);
|
||||
return stride_elems*column_index + row_index;
|
||||
}
|
||||
i64 matrix_index_to_offset(Type *t, i64 index) {
|
||||
|
||||
i64 matrix_row_major_index_to_offset(Type *t, i64 index) {
|
||||
t = base_type(t);
|
||||
GB_ASSERT(t->kind == Type_Matrix);
|
||||
|
||||
i64 row_index = index%t->Matrix.row_count;
|
||||
i64 column_index = index/t->Matrix.row_count;
|
||||
i64 column_index = index%t->Matrix.column_count;
|
||||
i64 row_index = index/t->Matrix.column_count;
|
||||
return matrix_indices_to_offset(t, row_index, column_index);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user