mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Add column major matrix support
This commit is contained in:
+19
-1
@@ -2739,9 +2739,27 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
char const *str = alloc_cstring(temporary_allocator(), mangled_name);
|
char const *str = alloc_cstring(temporary_allocator(), mangled_name);
|
||||||
add_string3("entry_point: \"", str, "\"");
|
add_string3("entry_point: \"", str, "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
add_string1("type_view: {type: \"[]?\", expr: \"array(data, len)\"}");
|
add_string1("type_view: {type: \"[]?\", expr: \"array(data, len)\"}");
|
||||||
add_string1("type_view: {type: \"string\", expr: \"array(data, len)\"}");
|
add_string1("type_view: {type: \"string\", expr: \"array(data, len)\"}");
|
||||||
// add_string1("type_view: {type: \"[dynamic]?\", expr: \"array(data, len)\"}");
|
|
||||||
|
// column major matrices
|
||||||
|
add_string1("type_view: {type: \"matrix[1, ?]?\", expr: \"table($.data, $[0])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[2, ?]?\", expr: \"table($.data, $[0], $[1])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[3, ?]?\", expr: \"table($.data, $[0], $[1], $[2])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[4, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[5, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[6, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[7, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[8, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[9, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[10, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[11, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9], $[10])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[12, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9], $[10], $[11])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[13, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9], $[10], $[11], $[12])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[14, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9], $[10], $[11], $[12], $[13])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[15, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9], $[10], $[11], $[12], $[13], $[14])\"}");
|
||||||
|
add_string1("type_view: {type: \"matrix[16, ?]?\", expr: \"table($.data, $[0], $[1], $[2], $[3], $[4], $[5], $[6], $[7], $[8], $[9], $[10], $[11], $[12], $[13], $[14], $[15])\"}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+75
-15
@@ -564,22 +564,21 @@ gb_internal LLVMMetadataRef lb_debug_bitfield(lbModule *m, Type *type, String na
|
|||||||
u64 size_in_bits = 8*type_size_of(bt);
|
u64 size_in_bits = 8*type_size_of(bt);
|
||||||
u32 align_in_bits = 8*cast(u32)type_align_of(bt);
|
u32 align_in_bits = 8*cast(u32)type_align_of(bt);
|
||||||
|
|
||||||
unsigned element_count = cast(unsigned)bt->BitField.fields.count;
|
unsigned element_count = cast(unsigned)bt->BitField.fields.count;
|
||||||
LLVMMetadataRef *elements = gb_alloc_array(permanent_allocator(), LLVMMetadataRef, element_count);
|
LLVMMetadataRef *elements = gb_alloc_array(permanent_allocator(), LLVMMetadataRef, element_count);
|
||||||
|
|
||||||
u64 offset_in_bits = 0;
|
u64 offset_in_bits = 0;
|
||||||
for (unsigned i = 0; i < element_count; i++) {
|
for (unsigned i = 0; i < element_count; i++) {
|
||||||
Entity *f = bt->BitField.fields[i];
|
Entity *f = bt->BitField.fields[i];
|
||||||
u8 bit_size = bt->BitField.bit_sizes[i];
|
u8 bit_size = bt->BitField.bit_sizes[i];
|
||||||
GB_ASSERT(f->kind == Entity_Variable);
|
GB_ASSERT(f->kind == Entity_Variable);
|
||||||
String name = f->token.string;
|
String name = f->token.string;
|
||||||
elements[i] = LLVMDIBuilderCreateBitFieldMemberType(m->debug_builder, scope, cast(char const *)name.text, name.len, file, line,
|
elements[i] = LLVMDIBuilderCreateBitFieldMemberType(m->debug_builder, scope, cast(char const *)name.text, name.len, file, line,
|
||||||
bit_size, offset_in_bits, 0,
|
bit_size, offset_in_bits, 0,
|
||||||
LLVMDIFlagZero, lb_debug_type(m, f->type)
|
LLVMDIFlagZero, lb_debug_type(m, f->type)
|
||||||
);
|
);
|
||||||
|
offset_in_bits += bit_size;
|
||||||
offset_in_bits += bit_size;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LLVMMetadataRef final_decl = LLVMDIBuilderCreateStructType(
|
LLVMMetadataRef final_decl = LLVMDIBuilderCreateStructType(
|
||||||
m->debug_builder, scope,
|
m->debug_builder, scope,
|
||||||
@@ -924,6 +923,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Type_Matrix: {
|
case Type_Matrix: {
|
||||||
|
#if 0
|
||||||
LLVMMetadataRef subscripts[1] = {};
|
LLVMMetadataRef subscripts[1] = {};
|
||||||
subscripts[0] = LLVMDIBuilderGetOrCreateSubrange(m->debug_builder,
|
subscripts[0] = LLVMDIBuilderGetOrCreateSubrange(m->debug_builder,
|
||||||
0ll,
|
0ll,
|
||||||
@@ -935,6 +935,66 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
|
|||||||
8*cast(unsigned)type_align_of(type),
|
8*cast(unsigned)type_align_of(type),
|
||||||
lb_debug_type(m, type->Matrix.elem),
|
lb_debug_type(m, type->Matrix.elem),
|
||||||
subscripts, gb_count_of(subscripts));
|
subscripts, gb_count_of(subscripts));
|
||||||
|
#else
|
||||||
|
LLVMMetadataRef subscripts[2] = {};
|
||||||
|
subscripts[0] = LLVMDIBuilderGetOrCreateSubrange(m->debug_builder, 0ll, type->Matrix.row_count);
|
||||||
|
subscripts[1] = LLVMDIBuilderGetOrCreateSubrange(m->debug_builder, 0ll, type->Matrix.column_count);
|
||||||
|
|
||||||
|
LLVMMetadataRef scope = nullptr;
|
||||||
|
LLVMMetadataRef array_type = nullptr;
|
||||||
|
|
||||||
|
uint64_t size_in_bits = 8*cast(uint64_t)(type_size_of(type));
|
||||||
|
unsigned align_in_bits = 8*cast(unsigned)(type_align_of(type));
|
||||||
|
|
||||||
|
if (type->Matrix.is_row_major) {
|
||||||
|
LLVMMetadataRef base = LLVMDIBuilderCreateArrayType(m->debug_builder,
|
||||||
|
8*cast(uint64_t)(type_size_of(type->Matrix.elem) * type->Matrix.column_count),
|
||||||
|
8*cast(unsigned)type_align_of(type->Matrix.elem),
|
||||||
|
lb_debug_type(m, type->Matrix.elem),
|
||||||
|
subscripts+1, 1);
|
||||||
|
array_type = LLVMDIBuilderCreateArrayType(m->debug_builder,
|
||||||
|
size_in_bits,
|
||||||
|
align_in_bits,
|
||||||
|
base,
|
||||||
|
subscripts+0, 1);
|
||||||
|
} else {
|
||||||
|
LLVMMetadataRef base = LLVMDIBuilderCreateArrayType(m->debug_builder,
|
||||||
|
8*cast(uint64_t)(type_size_of(type->Matrix.elem) * type->Matrix.row_count),
|
||||||
|
8*cast(unsigned)type_align_of(type->Matrix.elem),
|
||||||
|
lb_debug_type(m, type->Matrix.elem),
|
||||||
|
subscripts+0, 1);
|
||||||
|
array_type = LLVMDIBuilderCreateArrayType(m->debug_builder,
|
||||||
|
size_in_bits,
|
||||||
|
align_in_bits,
|
||||||
|
base,
|
||||||
|
subscripts+1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMMetadataRef elements[1] = {};
|
||||||
|
elements[0] = LLVMDIBuilderCreateMemberType(m->debug_builder, scope,
|
||||||
|
"data", 4,
|
||||||
|
nullptr, 0,
|
||||||
|
size_in_bits, align_in_bits, 0, LLVMDIFlagZero,
|
||||||
|
array_type
|
||||||
|
);
|
||||||
|
|
||||||
|
gbString name = temp_canonical_string(type);
|
||||||
|
|
||||||
|
LLVMMetadataRef final_decl = LLVMDIBuilderCreateStructType(
|
||||||
|
m->debug_builder, scope,
|
||||||
|
name, gb_string_length(name),
|
||||||
|
nullptr, 0,
|
||||||
|
size_in_bits, align_in_bits,
|
||||||
|
LLVMDIFlagZero,
|
||||||
|
nullptr,
|
||||||
|
elements, 1,
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
"", 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return final_decl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user