Rename word_size to ptr_size internally to make it clearer

This commit is contained in:
gingerBill
2023-04-20 12:18:13 +01:00
parent f5d9ca64f9
commit 685f7d0fea
10 changed files with 67 additions and 67 deletions
+9 -9
View File
@@ -116,7 +116,7 @@ gb_global String const ODIN_VERSION = str_lit(ODIN_VERSION_RAW);
struct TargetMetrics { struct TargetMetrics {
TargetOsKind os; TargetOsKind os;
TargetArchKind arch; TargetArchKind arch;
isize word_size; isize ptr_size;
isize int_size; isize int_size;
isize max_align; isize max_align;
isize max_simd_align; isize max_simd_align;
@@ -238,10 +238,10 @@ struct BuildContext {
TargetEndianKind endian_kind; TargetEndianKind endian_kind;
// In bytes // In bytes
i64 word_size; // Size of a pointer, must be >= 4 i64 ptr_size; // Size of a pointer, must be >= 4
i64 int_size; // Size of a int/uint, must be >= 4 i64 int_size; // Size of a int/uint, must be >= 4
i64 max_align; // max alignment, must be >= 1 (and typically >= word_size) i64 max_align; // max alignment, must be >= 1 (and typically >= ptr_size)
i64 max_simd_align; // max alignment, must be >= 1 (and typically >= word_size) i64 max_simd_align; // max alignment, must be >= 1 (and typically >= ptr_size)
CommandKind command_kind; CommandKind command_kind;
String command; String command;
@@ -1192,14 +1192,14 @@ gb_internal void init_build_context(TargetMetrics *cross_target) {
GB_ASSERT(metrics->os != TargetOs_Invalid); GB_ASSERT(metrics->os != TargetOs_Invalid);
GB_ASSERT(metrics->arch != TargetArch_Invalid); GB_ASSERT(metrics->arch != TargetArch_Invalid);
GB_ASSERT(metrics->word_size > 1); GB_ASSERT(metrics->ptr_size > 1);
GB_ASSERT(metrics->int_size > 1); GB_ASSERT(metrics->int_size > 1);
GB_ASSERT(metrics->max_align > 1); GB_ASSERT(metrics->max_align > 1);
GB_ASSERT(metrics->max_simd_align > 1); GB_ASSERT(metrics->max_simd_align > 1);
GB_ASSERT(metrics->int_size >= metrics->word_size); GB_ASSERT(metrics->int_size >= metrics->ptr_size);
if (metrics->int_size > metrics->word_size) { if (metrics->int_size > metrics->ptr_size) {
GB_ASSERT(metrics->int_size == 2*metrics->word_size); GB_ASSERT(metrics->int_size == 2*metrics->ptr_size);
} }
@@ -1208,7 +1208,7 @@ gb_internal void init_build_context(TargetMetrics *cross_target) {
bc->ODIN_OS = target_os_names[metrics->os]; bc->ODIN_OS = target_os_names[metrics->os];
bc->ODIN_ARCH = target_arch_names[metrics->arch]; bc->ODIN_ARCH = target_arch_names[metrics->arch];
bc->endian_kind = target_endians[metrics->arch]; bc->endian_kind = target_endians[metrics->arch];
bc->word_size = metrics->word_size; bc->ptr_size = metrics->ptr_size;
bc->int_size = metrics->int_size; bc->int_size = metrics->int_size;
bc->max_align = metrics->max_align; bc->max_align = metrics->max_align;
bc->max_simd_align = metrics->max_simd_align; bc->max_simd_align = metrics->max_simd_align;
+4 -4
View File
@@ -218,7 +218,7 @@ gb_internal i64 lb_sizeof(LLVMTypeRef type) {
case LLVMDoubleTypeKind: case LLVMDoubleTypeKind:
return 8; return 8;
case LLVMPointerTypeKind: case LLVMPointerTypeKind:
return build_context.word_size; return build_context.ptr_size;
case LLVMStructTypeKind: case LLVMStructTypeKind:
{ {
unsigned field_count = LLVMCountStructElementTypes(type); unsigned field_count = LLVMCountStructElementTypes(type);
@@ -275,7 +275,7 @@ gb_internal i64 lb_alignof(LLVMTypeRef type) {
case LLVMIntegerTypeKind: case LLVMIntegerTypeKind:
{ {
unsigned w = LLVMGetIntTypeWidth(type); unsigned w = LLVMGetIntTypeWidth(type);
return gb_clamp((w + 7)/8, 1, build_context.word_size); return gb_clamp((w + 7)/8, 1, build_context.ptr_size);
} }
case LLVMHalfTypeKind: case LLVMHalfTypeKind:
return 2; return 2;
@@ -284,7 +284,7 @@ gb_internal i64 lb_alignof(LLVMTypeRef type) {
case LLVMDoubleTypeKind: case LLVMDoubleTypeKind:
return 8; return 8;
case LLVMPointerTypeKind: case LLVMPointerTypeKind:
return build_context.word_size; return build_context.ptr_size;
case LLVMStructTypeKind: case LLVMStructTypeKind:
{ {
if (LLVMIsPackedStruct(type)) { if (LLVMIsPackedStruct(type)) {
@@ -388,7 +388,7 @@ namespace lbAbi386 {
} }
if (build_context.metrics.os == TargetOs_windows && if (build_context.metrics.os == TargetOs_windows &&
build_context.word_size == 8 && build_context.ptr_size == 8 &&
lb_is_type_kind(type, LLVMIntegerTypeKind) && lb_is_type_kind(type, LLVMIntegerTypeKind) &&
type == LLVMIntTypeInContext(c, 128)) { type == LLVMIntTypeInContext(c, 128)) {
// NOTE(bill): Because Windows AMD64 is weird // NOTE(bill): Because Windows AMD64 is weird
+1 -1
View File
@@ -539,7 +539,7 @@ gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValu
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile); gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile);
gb_internal gb_inline i64 lb_max_zero_init_size(void) { gb_internal gb_inline i64 lb_max_zero_init_size(void) {
return cast(i64)(4*build_context.word_size); return cast(i64)(4*build_context.int_size);
} }
gb_internal LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type); gb_internal LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type);
+15 -15
View File
@@ -52,8 +52,8 @@ gb_internal LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type)
GB_ASSERT(type != t_invalid); GB_ASSERT(type != t_invalid);
/* unsigned const word_size = cast(unsigned)build_context.word_size; /* unsigned const ptr_size = cast(unsigned)build_context.ptr_size;
unsigned const word_bits = cast(unsigned)(8*build_context.word_size); */ unsigned const ptr_bits = cast(unsigned)(8*build_context.ptr_size); */
GB_ASSERT(type->kind == Type_Proc); GB_ASSERT(type->kind == Type_Proc);
unsigned parameter_count = 1; unsigned parameter_count = 1;
@@ -131,9 +131,9 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
GB_ASSERT(type != t_invalid); GB_ASSERT(type != t_invalid);
/* unsigned const word_size = cast(unsigned)build_context.word_size; */ /* unsigned const ptr_size = cast(unsigned)build_context.ptr_size; */
unsigned const int_bits = cast(unsigned)(8*build_context.int_size); unsigned const int_bits = cast(unsigned)(8*build_context.int_size);
unsigned const word_bits = cast(unsigned)(8*build_context.word_size); unsigned const ptr_bits = cast(unsigned)(8*build_context.ptr_size);
switch (type->kind) { switch (type->kind) {
case Type_Basic: case Type_Basic:
@@ -165,10 +165,10 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Basic_int: return lb_debug_type_basic_type(m, str_lit("int"), int_bits, LLVMDWARFTypeEncoding_Signed); case Basic_int: return lb_debug_type_basic_type(m, str_lit("int"), int_bits, LLVMDWARFTypeEncoding_Signed);
case Basic_uint: return lb_debug_type_basic_type(m, str_lit("uint"), int_bits, LLVMDWARFTypeEncoding_Unsigned); case Basic_uint: return lb_debug_type_basic_type(m, str_lit("uint"), int_bits, LLVMDWARFTypeEncoding_Unsigned);
case Basic_uintptr: return lb_debug_type_basic_type(m, str_lit("uintptr"), word_bits, LLVMDWARFTypeEncoding_Unsigned); case Basic_uintptr: return lb_debug_type_basic_type(m, str_lit("uintptr"), ptr_bits, LLVMDWARFTypeEncoding_Unsigned);
case Basic_typeid: case Basic_typeid:
return lb_debug_type_basic_type(m, str_lit("typeid"), word_bits, LLVMDWARFTypeEncoding_Unsigned); return lb_debug_type_basic_type(m, str_lit("typeid"), ptr_bits, LLVMDWARFTypeEncoding_Unsigned);
// Endian Specific Types // Endian Specific Types
case Basic_i16le: return lb_debug_type_basic_type(m, str_lit("i16le"), 16, LLVMDWARFTypeEncoding_Signed, LLVMDIFlagLittleEndian); case Basic_i16le: return lb_debug_type_basic_type(m, str_lit("i16le"), 16, LLVMDWARFTypeEncoding_Signed, LLVMDIFlagLittleEndian);
@@ -252,7 +252,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Basic_rawptr: case Basic_rawptr:
{ {
LLVMMetadataRef void_type = lb_debug_type_basic_type(m, str_lit("void"), 8, LLVMDWARFTypeEncoding_Unsigned); LLVMMetadataRef void_type = lb_debug_type_basic_type(m, str_lit("void"), 8, LLVMDWARFTypeEncoding_Unsigned);
return LLVMDIBuilderCreatePointerType(m->debug_builder, void_type, word_bits, word_bits, LLVMDWARFTypeEncoding_Address, "rawptr", 6); return LLVMDIBuilderCreatePointerType(m->debug_builder, void_type, ptr_bits, ptr_bits, LLVMDWARFTypeEncoding_Address, "rawptr", 6);
} }
case Basic_string: case Basic_string:
{ {
@@ -264,14 +264,14 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Basic_cstring: case Basic_cstring:
{ {
LLVMMetadataRef char_type = lb_debug_type_basic_type(m, str_lit("char"), 8, LLVMDWARFTypeEncoding_Unsigned); LLVMMetadataRef char_type = lb_debug_type_basic_type(m, str_lit("char"), 8, LLVMDWARFTypeEncoding_Unsigned);
return LLVMDIBuilderCreatePointerType(m->debug_builder, char_type, word_bits, word_bits, 0, "cstring", 7); return LLVMDIBuilderCreatePointerType(m->debug_builder, char_type, ptr_bits, ptr_bits, 0, "cstring", 7);
} }
case Basic_any: case Basic_any:
{ {
LLVMMetadataRef elements[2] = {}; LLVMMetadataRef elements[2] = {};
elements[0] = lb_debug_struct_field(m, str_lit("data"), t_rawptr, 0); elements[0] = lb_debug_struct_field(m, str_lit("data"), t_rawptr, 0);
elements[1] = lb_debug_struct_field(m, str_lit("id"), t_typeid, word_bits); elements[1] = lb_debug_struct_field(m, str_lit("id"), t_typeid, ptr_bits);
return lb_debug_basic_struct(m, str_lit("any"), 2*word_bits, word_bits, elements, gb_count_of(elements)); return lb_debug_basic_struct(m, str_lit("any"), 2*ptr_bits, ptr_bits, elements, gb_count_of(elements));
} }
// Untyped types // Untyped types
@@ -295,9 +295,9 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Type_SoaPointer: case Type_SoaPointer:
return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->SoaPointer.elem), int_bits, int_bits, 0, nullptr, 0); return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->SoaPointer.elem), int_bits, int_bits, 0, nullptr, 0);
case Type_Pointer: case Type_Pointer:
return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->Pointer.elem), word_bits, word_bits, 0, nullptr, 0); return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->Pointer.elem), ptr_bits, ptr_bits, 0, nullptr, 0);
case Type_MultiPointer: case Type_MultiPointer:
return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->MultiPointer.elem), word_bits, word_bits, 0, nullptr, 0); return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->MultiPointer.elem), ptr_bits, ptr_bits, 0, nullptr, 0);
case Type_Array: { case Type_Array: {
LLVMMetadataRef subscripts[1] = {}; LLVMMetadataRef subscripts[1] = {};
@@ -417,7 +417,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Type_Proc: case Type_Proc:
{ {
LLVMMetadataRef proc_underlying_type = lb_debug_type_internal_proc(m, type); LLVMMetadataRef proc_underlying_type = lb_debug_type_internal_proc(m, type);
LLVMMetadataRef pointer_type = LLVMDIBuilderCreatePointerType(m->debug_builder, proc_underlying_type, word_bits, word_bits, 0, nullptr, 0); LLVMMetadataRef pointer_type = LLVMDIBuilderCreatePointerType(m->debug_builder, proc_underlying_type, ptr_bits, ptr_bits, 0, nullptr, 0);
gbString name = type_to_string(type, temporary_allocator()); gbString name = type_to_string(type, temporary_allocator());
return LLVMDIBuilderCreateTypedef(m->debug_builder, pointer_type, name, gb_string_length(name), nullptr, 0, nullptr, cast(u32)(8*type_align_of(type))); return LLVMDIBuilderCreateTypedef(m->debug_builder, pointer_type, name, gb_string_length(name), nullptr, 0, nullptr, cast(u32)(8*type_align_of(type)));
} }
@@ -618,8 +618,8 @@ gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) {
} }
gb_internal void lb_debug_complete_types(lbModule *m) { gb_internal void lb_debug_complete_types(lbModule *m) {
/* unsigned const word_size = cast(unsigned)build_context.word_size; */ /* unsigned const ptr_size = cast(unsigned)build_context.ptr_size; */
unsigned const word_bits = cast(unsigned)(8*build_context.word_size); unsigned const ptr_bits = cast(unsigned)(8*build_context.ptr_size);
unsigned const int_bits = cast(unsigned)(8*build_context.int_size); unsigned const int_bits = cast(unsigned)(8*build_context.int_size);
for_array(debug_incomplete_type_index, m->debug_incomplete_types) { for_array(debug_incomplete_type_index, m->debug_incomplete_types) {
+6 -6
View File
@@ -1626,7 +1626,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
GB_ASSERT(type != t_invalid); GB_ASSERT(type != t_invalid);
bool bigger_int = build_context.word_size != build_context.int_size; bool bigger_int = build_context.ptr_size != build_context.int_size;
switch (type->kind) { switch (type->kind) {
case Type_Basic: case Type_Basic:
@@ -1765,7 +1765,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
case Basic_int: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size); case Basic_int: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
case Basic_uint: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size); case Basic_uint: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
case Basic_uintptr: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.word_size); case Basic_uintptr: return LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.ptr_size);
case Basic_rawptr: return LLVMPointerType(LLVMInt8TypeInContext(ctx), 0); case Basic_rawptr: return LLVMPointerType(LLVMInt8TypeInContext(ctx), 0);
case Basic_string: case Basic_string:
@@ -1800,7 +1800,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
return type; return type;
} }
case Basic_typeid: return LLVMIntTypeInContext(m->ctx, 8*cast(unsigned)build_context.word_size); case Basic_typeid: return LLVMIntTypeInContext(m->ctx, 8*cast(unsigned)build_context.ptr_size);
// Endian Specific Types // Endian Specific Types
case Basic_i16le: return LLVMInt16TypeInContext(ctx); case Basic_i16le: return LLVMInt16TypeInContext(ctx);
@@ -1927,7 +1927,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
if (bigger_int) { if (bigger_int) {
LLVMTypeRef fields[3] = { LLVMTypeRef fields[3] = {
LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data LLVMPointerType(lb_type(m, type->Slice.elem), 0), // data
lb_type_padding_filler(m, build_context.word_size, build_context.word_size), // padding lb_type_padding_filler(m, build_context.ptr_size, build_context.ptr_size), // padding
lb_type(m, t_int), // len lb_type(m, t_int), // len
}; };
return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false); return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false);
@@ -1946,7 +1946,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
if (bigger_int) { if (bigger_int) {
LLVMTypeRef fields[5] = { LLVMTypeRef fields[5] = {
LLVMPointerType(lb_type(m, type->DynamicArray.elem), 0), // data LLVMPointerType(lb_type(m, type->DynamicArray.elem), 0), // data
lb_type_padding_filler(m, build_context.word_size, build_context.word_size), // padding lb_type_padding_filler(m, build_context.ptr_size, build_context.ptr_size), // padding
lb_type(m, t_int), // len lb_type(m, t_int), // len
lb_type(m, t_int), // cap lb_type(m, t_int), // cap
lb_type(m, t_allocator), // allocator lb_type(m, t_allocator), // allocator
@@ -2173,7 +2173,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
LLVMTypeRef *fields = gb_alloc_array(permanent_allocator(), LLVMTypeRef, field_count); LLVMTypeRef *fields = gb_alloc_array(permanent_allocator(), LLVMTypeRef, field_count);
fields[0] = LLVMPointerType(lb_type(m, type->Pointer.elem), 0); fields[0] = LLVMPointerType(lb_type(m, type->Pointer.elem), 0);
if (bigger_int) { if (bigger_int) {
fields[1] = lb_type_padding_filler(m, build_context.word_size, build_context.word_size); fields[1] = lb_type_padding_filler(m, build_context.ptr_size, build_context.ptr_size);
fields[2] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size); fields[2] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
} else { } else {
fields[1] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size); fields[1] = LLVMIntTypeInContext(ctx, 8*cast(unsigned)build_context.int_size);
+2 -2
View File
@@ -14,7 +14,7 @@ gb_internal void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue sr
char const *name = "llvm.memmove"; char const *name = "llvm.memmove";
if (LLVMIsConstant(len.value)) { if (LLVMIsConstant(len.value)) {
i64 const_len = cast(i64)LLVMConstIntGetSExtValue(len.value); i64 const_len = cast(i64)LLVMConstIntGetSExtValue(len.value);
if (const_len <= 4*build_context.word_size) { if (const_len <= 4*build_context.int_size) {
name = "llvm.memmove.inline"; name = "llvm.memmove.inline";
} }
} }
@@ -43,7 +43,7 @@ gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValu
char const *name = "llvm.memcpy"; char const *name = "llvm.memcpy";
if (LLVMIsConstant(len.value)) { if (LLVMIsConstant(len.value)) {
i64 const_len = cast(i64)LLVMConstIntGetSExtValue(len.value); i64 const_len = cast(i64)LLVMConstIntGetSExtValue(len.value);
if (const_len <= 4*build_context.word_size) { if (const_len <= 4*build_context.int_size) {
name = "llvm.memcpy.inline"; name = "llvm.memcpy.inline";
} }
} }
+1 -1
View File
@@ -1652,7 +1652,7 @@ gb_internal void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) {
if (res.value != nullptr) { if (res.value != nullptr) {
LLVMValueRef res_val = res.value; LLVMValueRef res_val = res.value;
i64 sz = type_size_of(res.type); i64 sz = type_size_of(res.type);
if (LLVMIsALoadInst(res_val) && sz > build_context.word_size) { if (LLVMIsALoadInst(res_val) && sz > build_context.int_size) {
lbValue ptr = lb_address_from_load_or_generate_local(p, res); lbValue ptr = lb_address_from_load_or_generate_local(p, res);
lb_mem_copy_non_overlapping(p, p->return_ptr.addr, ptr, lb_const_int(p->module, t_int, sz)); lb_mem_copy_non_overlapping(p, p->return_ptr.addr, ptr, lb_const_int(p->module, t_int, sz));
} else { } else {
+2 -2
View File
@@ -68,7 +68,7 @@ gb_internal lbValue lb_typeid(lbModule *m, Type *type) {
} }
u64 data = 0; u64 data = 0;
if (build_context.word_size == 4) { if (build_context.ptr_size == 4) {
GB_ASSERT(id <= (1u<<24u)); GB_ASSERT(id <= (1u<<24u));
data |= (id &~ (1u<<24)) << 0u; // index data |= (id &~ (1u<<24)) << 0u; // index
data |= (kind &~ (1u<<5)) << 24u; // kind data |= (kind &~ (1u<<5)) << 24u; // kind
@@ -76,7 +76,7 @@ gb_internal lbValue lb_typeid(lbModule *m, Type *type) {
data |= (special &~ (1u<<1)) << 30u; // kind data |= (special &~ (1u<<1)) << 30u; // kind
data |= (reserved &~ (1u<<1)) << 31u; // kind data |= (reserved &~ (1u<<1)) << 31u; // kind
} else { } else {
GB_ASSERT(build_context.word_size == 8); GB_ASSERT(build_context.ptr_size == 8);
GB_ASSERT(id <= (1ull<<56u)); GB_ASSERT(id <= (1ull<<56u));
data |= (id &~ (1ull<<56)) << 0ul; // index data |= (id &~ (1ull<<56)) << 0ul; // index
data |= (kind &~ (1ull<<5)) << 56ull; // kind data |= (kind &~ (1ull<<5)) << 56ull; // kind
+5 -5
View File
@@ -930,17 +930,17 @@ gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
if (t->kind == Type_Struct) { if (t->kind == Type_Struct) {
auto field_remapping = lb_get_struct_remapping(m, t); auto field_remapping = lb_get_struct_remapping(m, t);
return field_remapping[index]; return field_remapping[index];
} else if (build_context.word_size != build_context.int_size) { } else if (build_context.ptr_size != build_context.int_size) {
switch (t->kind) { switch (t->kind) {
case Type_Slice: case Type_Slice:
GB_ASSERT(build_context.word_size*2 == build_context.int_size); GB_ASSERT(build_context.ptr_size*2 == build_context.int_size);
switch (index) { switch (index) {
case 0: return 0; // data case 0: return 0; // data
case 1: return 2; // len case 1: return 2; // len
} }
break; break;
case Type_DynamicArray: case Type_DynamicArray:
GB_ASSERT(build_context.word_size*2 == build_context.int_size); GB_ASSERT(build_context.ptr_size*2 == build_context.int_size);
switch (index) { switch (index) {
case 0: return 0; // data case 0: return 0; // data
case 1: return 2; // len case 1: return 2; // len
@@ -949,7 +949,7 @@ gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
} }
break; break;
case Type_SoaPointer: case Type_SoaPointer:
GB_ASSERT(build_context.word_size*2 == build_context.int_size); GB_ASSERT(build_context.ptr_size*2 == build_context.int_size);
switch (index) { switch (index) {
case 0: return 0; // data case 0: return 0; // data
case 1: return 2; // offset case 1: return 2; // offset
@@ -1589,7 +1589,7 @@ gb_internal lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) {
GB_ASSERT(is_type_map(value.type) || are_types_identical(value.type, t_raw_map)); GB_ASSERT(is_type_map(value.type) || are_types_identical(value.type, t_raw_map));
lbValue data = lb_emit_struct_ev(p, value, 0); lbValue data = lb_emit_struct_ev(p, value, 0);
u64 mask_value = 0; u64 mask_value = 0;
if (build_context.word_size == 4) { if (build_context.ptr_size == 4) {
mask_value = 0xfffffffful & ~(MAP_CACHE_LINE_SIZE-1); mask_value = 0xfffffffful & ~(MAP_CACHE_LINE_SIZE-1);
} else { } else {
mask_value = 0xffffffffffffffffull & ~(MAP_CACHE_LINE_SIZE-1); mask_value = 0xffffffffffffffffull & ~(MAP_CACHE_LINE_SIZE-1);
+22 -22
View File
@@ -3411,15 +3411,15 @@ gb_internal i64 type_size_of(Type *t) {
GB_ASSERT_MSG(is_type_typed(t), "%s", type_to_string(t)); GB_ASSERT_MSG(is_type_typed(t), "%s", type_to_string(t));
switch (t->Basic.kind) { switch (t->Basic.kind) {
case Basic_string: size = 2*build_context.int_size; break; case Basic_string: size = 2*build_context.int_size; break;
case Basic_cstring: size = build_context.word_size; break; case Basic_cstring: size = build_context.ptr_size; break;
case Basic_any: size = 2*build_context.word_size; break; case Basic_any: size = 2*build_context.ptr_size; break;
case Basic_typeid: size = build_context.word_size; break; case Basic_typeid: size = build_context.ptr_size; break;
case Basic_int: case Basic_uint: case Basic_int: case Basic_uint:
size = build_context.int_size; size = build_context.int_size;
break; break;
case Basic_uintptr: case Basic_rawptr: case Basic_uintptr: case Basic_rawptr:
size = build_context.word_size; size = build_context.ptr_size;
break; break;
default: default:
size = t->Basic.size; size = t->Basic.size;
@@ -3474,14 +3474,14 @@ gb_internal i64 type_align_of_internal(Type *t, TypePath *path) {
GB_ASSERT(is_type_typed(t)); GB_ASSERT(is_type_typed(t));
switch (t->Basic.kind) { switch (t->Basic.kind) {
case Basic_string: return build_context.int_size; case Basic_string: return build_context.int_size;
case Basic_cstring: return build_context.word_size; case Basic_cstring: return build_context.ptr_size;
case Basic_any: return build_context.word_size; case Basic_any: return build_context.ptr_size;
case Basic_typeid: return build_context.word_size; case Basic_typeid: return build_context.ptr_size;
case Basic_int: case Basic_uint: case Basic_int: case Basic_uint:
return build_context.int_size; return build_context.int_size;
case Basic_uintptr: case Basic_rawptr: case Basic_uintptr: case Basic_rawptr:
return build_context.word_size; return build_context.ptr_size;
case Basic_complex32: case Basic_complex64: case Basic_complex128: case Basic_complex32: case Basic_complex64: case Basic_complex128:
return type_size_of_internal(t, path) / 2; return type_size_of_internal(t, path) / 2;
@@ -3532,7 +3532,7 @@ gb_internal i64 type_align_of_internal(Type *t, TypePath *path) {
} break; } break;
case Type_Map: case Type_Map:
return build_context.word_size; return build_context.ptr_size;
case Type_Enum: case Type_Enum:
return type_align_of_internal(t->Enum.base_type, path); return type_align_of_internal(t->Enum.base_type, path);
@@ -3615,7 +3615,7 @@ gb_internal i64 type_align_of_internal(Type *t, TypePath *path) {
return build_context.int_size; return build_context.int_size;
} }
// NOTE(bill): Things that are bigger than build_context.word_size, are actually comprised of smaller types // NOTE(bill): Things that are bigger than build_context.ptr_size, are actually comprised of smaller types
// TODO(bill): Is this correct for 128-bit types (integers)? // TODO(bill): Is this correct for 128-bit types (integers)?
return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.max_align); return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.max_align);
} }
@@ -3698,22 +3698,22 @@ gb_internal i64 type_size_of_internal(Type *t, TypePath *path) {
} }
switch (kind) { switch (kind) {
case Basic_string: return 2*build_context.int_size; case Basic_string: return 2*build_context.int_size;
case Basic_cstring: return build_context.word_size; case Basic_cstring: return build_context.ptr_size;
case Basic_any: return 2*build_context.word_size; case Basic_any: return 2*build_context.ptr_size;
case Basic_typeid: return build_context.word_size; case Basic_typeid: return build_context.ptr_size;
case Basic_int: case Basic_uint: case Basic_int: case Basic_uint:
return build_context.int_size; return build_context.int_size;
case Basic_uintptr: case Basic_rawptr: case Basic_uintptr: case Basic_rawptr:
return build_context.word_size; return build_context.ptr_size;
} }
} break; } break;
case Type_Pointer: case Type_Pointer:
return build_context.word_size; return build_context.ptr_size;
case Type_MultiPointer: case Type_MultiPointer:
return build_context.word_size; return build_context.ptr_size;
case Type_SoaPointer: case Type_SoaPointer:
return build_context.int_size*2; return build_context.int_size*2;
@@ -3753,7 +3753,7 @@ gb_internal i64 type_size_of_internal(Type *t, TypePath *path) {
case Type_DynamicArray: case Type_DynamicArray:
// data + len + cap + allocator(procedure+data) // data + len + cap + allocator(procedure+data)
return 3*build_context.int_size + 2*build_context.word_size; return 3*build_context.int_size + 2*build_context.ptr_size;
case Type_Map: case Type_Map:
/* /*
@@ -3763,7 +3763,7 @@ gb_internal i64 type_size_of_internal(Type *t, TypePath *path) {
allocator: runtime.Allocator, // 2 words allocator: runtime.Allocator, // 2 words
} }
*/ */
return (1 + 1 + 2)*build_context.word_size; return (1 + 1 + 2)*build_context.ptr_size;
case Type_Tuple: { case Type_Tuple: {
i64 count, align, size; i64 count, align, size;
@@ -3889,7 +3889,7 @@ gb_internal i64 type_size_of_internal(Type *t, TypePath *path) {
} }
// Catch all // Catch all
return build_context.word_size; return build_context.ptr_size;
} }
gb_internal i64 type_offset_of(Type *t, i32 index) { gb_internal i64 type_offset_of(Type *t, i32 index) {
@@ -3914,8 +3914,8 @@ gb_internal i64 type_offset_of(Type *t, i32 index) {
} }
} else if (t->Basic.kind == Basic_any) { } else if (t->Basic.kind == Basic_any) {
switch (index) { switch (index) {
case 0: return 0; // type_info case 0: return 0; // type_info
case 1: return build_context.word_size; // data case 1: return build_context.ptr_size; // data
} }
} }
} else if (t->kind == Type_Slice) { } else if (t->kind == Type_Slice) {
@@ -3934,7 +3934,7 @@ gb_internal i64 type_offset_of(Type *t, i32 index) {
} else if (t->kind == Type_Union) { } else if (t->kind == Type_Union) {
/* i64 s = */ type_size_of(t); /* i64 s = */ type_size_of(t);
switch (index) { switch (index) {
case -1: return align_formula(t->Union.variant_block_size, build_context.word_size); // __type_info case -1: return align_formula(t->Union.variant_block_size, build_context.ptr_size); // __type_info
} }
} }
return 0; return 0;