Merge remote-tracking branch 'origin/master' into file-tags-without-comments

This commit is contained in:
Karl Zylinski
2024-09-08 11:29:21 +02:00
15 changed files with 237 additions and 75 deletions
+3 -1
View File
@@ -1,4 +1,6 @@
//+build !windows !linux !darwin //+build !windows
//+build !linux
//+build !darwin
package debug_trace package debug_trace
import "base:runtime" import "base:runtime"
+2 -1
View File
@@ -1,4 +1,5 @@
//+build !netbsd !openbsd //+build !netbsd
//+build !openbsd
package flags package flags
import "base:runtime" import "base:runtime"
+2 -1
View File
@@ -1,5 +1,6 @@
//+private //+private
//+build !netbsd !openbsd //+build !netbsd
//+build !openbsd
package flags package flags
import "core:net" import "core:net"
+10 -10
View File
@@ -7,8 +7,8 @@ Parses a boolean value from the input string
**Inputs** **Inputs**
- s: The input string - s: The input string
- true: "1", "t", "T", "true", "TRUE", "True" - true: "1", "t", "T", "true", "TRUE", "True"
- false: "0", "f", "F", "false", "FALSE", "False" - false: "0", "f", "F", "false", "FALSE", "False"
- n: An optional pointer to an int to store the length of the parsed substring (default: nil) - n: An optional pointer to an int to store the length of the parsed substring (default: nil)
**Returns** **Returns**
@@ -203,7 +203,7 @@ Parses an unsigned 64-bit integer value from the input string without a prefix,
**Inputs** **Inputs**
- str: The input string to parse - str: The input string to parse
- base: The base of the number system to use for parsing - base: The base of the number system to use for parsing
- Must be between 1 and 16 (inclusive) - Must be between 1 and 16 (inclusive)
- n: An optional pointer to an int to store the length of the parsed substring (default: nil) - n: An optional pointer to an int to store the length of the parsed substring (default: nil)
Example: Example:
@@ -264,8 +264,8 @@ Parses an unsigned 64-bit integer value from the input string, using the specifi
**Inputs** **Inputs**
- str: The input string to parse - str: The input string to parse
- base: The base of the number system to use for parsing (default: 0) - base: The base of the number system to use for parsing (default: 0)
- If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal) - If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal)
- If base is not 0, it will be used for parsing regardless of any prefix in the input string - If base is not 0, it will be used for parsing regardless of any prefix in the input string
- n: An optional pointer to an int to store the length of the parsed substring (default: nil) - n: An optional pointer to an int to store the length of the parsed substring (default: nil)
Example: Example:
@@ -339,8 +339,8 @@ Parses a signed integer value from the input string, using the specified base or
**Inputs** **Inputs**
- s: The input string to parse - s: The input string to parse
- base: The base of the number system to use for parsing (default: 0) - base: The base of the number system to use for parsing (default: 0)
- If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal) - If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal)
- If base is not 0, it will be used for parsing regardless of any prefix in the input string - If base is not 0, it will be used for parsing regardless of any prefix in the input string
Example: Example:
@@ -382,8 +382,8 @@ Parses an unsigned integer value from the input string, using the specified base
**Inputs** **Inputs**
- s: The input string to parse - s: The input string to parse
- base: The base of the number system to use for parsing (default: 0, inferred) - base: The base of the number system to use for parsing (default: 0, inferred)
- If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal) - If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal)
- If base is not 0, it will be used for parsing regardless of any prefix in the input string - If base is not 0, it will be used for parsing regardless of any prefix in the input string
Example: Example:
@@ -1729,7 +1729,7 @@ quote_rune :: proc(buf: []byte, r: rune) -> string {
} }
} }
if buf == nil { if buf == nil || r < 0 {
return "" return ""
} }
+7 -1
View File
@@ -1,5 +1,11 @@
//+private //+private
//+build !windows !linux !darwin !freebsd !openbsd !netbsd !haiku //+build !windows
//+build !linux
//+build !darwin
//+build !freebsd
//+build !openbsd
//+build !netbsd
//+build !haiku
package testing package testing
/* /*
+4 -3
View File
@@ -2048,10 +2048,11 @@ gb_internal bool init_build_paths(String init_filename) {
gbFile output_file_test; gbFile output_file_test;
const char* output_file_name = (const char*)output_file.text; const char* output_file_name = (const char*)output_file.text;
gbFileError output_test_err = gb_file_open_mode(&output_file_test, gbFileMode_Append | gbFileMode_Rw, output_file_name); gbFileError output_test_err = gb_file_open_mode(&output_file_test, gbFileMode_Append | gbFileMode_Rw, output_file_name);
gb_file_close(&output_file_test);
gb_file_remove(output_file_name);
if (output_test_err != 0) { if (output_test_err == 0) {
gb_file_close(&output_file_test);
gb_file_remove(output_file_name);
} else {
String output_file = path_to_string(ha, bc->build_paths[BuildPath_Output]); String output_file = path_to_string(ha, bc->build_paths[BuildPath_Output]);
defer (gb_free(ha, output_file.text)); defer (gb_free(ha, output_file.text));
gb_printf_err("No write permissions for output path: %.*s\n", LIT(output_file)); gb_printf_err("No write permissions for output path: %.*s\n", LIT(output_file));
+10
View File
@@ -5203,6 +5203,16 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
return false; return false;
} }
if (sz >= 64) {
if (is_type_unsigned(x.type)) {
add_package_dependency(c, "runtime", "umodti3", true);
add_package_dependency(c, "runtime", "udivti3", true);
} else {
add_package_dependency(c, "runtime", "modti3", true);
add_package_dependency(c, "runtime", "divti3", true);
}
}
operand->type = x.type; operand->type = x.type;
operand->mode = Addressing_Value; operand->mode = Addressing_Value;
} }
+46 -9
View File
@@ -82,13 +82,36 @@ gb_internal LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type)
parameter_count += 1; parameter_count += 1;
} }
} }
LLVMMetadataRef *parameters = gb_alloc_array(permanent_allocator(), LLVMMetadataRef, parameter_count);
unsigned param_index = 0; auto parameters = array_make<LLVMMetadataRef>(permanent_allocator(), 0, type->Proc.param_count+type->Proc.result_count+2);
if (type->Proc.result_count == 0) {
parameters[param_index++] = nullptr; array_add(&parameters, cast(LLVMMetadataRef)nullptr);
} else {
parameters[param_index++] = lb_debug_procedure_parameters(m, type->Proc.results); bool return_is_tuple = false;
if (type->Proc.result_count != 0) {
Type *single_ret = reduce_tuple_to_single_type(type->Proc.results);
if (is_type_proc(single_ret)) {
single_ret = t_rawptr;
}
if (is_type_tuple(single_ret) && is_calling_convention_odin(type->Proc.calling_convention)) {
LLVMTypeRef actual = lb_type_internal_for_procedures_raw(m, type);
actual = LLVMGetReturnType(actual);
if (actual == nullptr) {
// results were passed as a single pointer
parameters[0] = lb_debug_procedure_parameters(m, single_ret);
} else {
LLVMTypeRef possible = lb_type(m, type->Proc.results);
if (possible == actual) {
// results were returned directly
parameters[0] = lb_debug_procedure_parameters(m, single_ret);
} else {
// resulsts were returned separately
return_is_tuple = true;
}
}
} else {
parameters[0] = lb_debug_procedure_parameters(m, single_ret);
}
} }
LLVMMetadataRef file = nullptr; LLVMMetadataRef file = nullptr;
@@ -98,8 +121,22 @@ gb_internal LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type)
if (e->kind != Entity_Variable) { if (e->kind != Entity_Variable) {
continue; continue;
} }
parameters[param_index] = lb_debug_procedure_parameters(m, e->type); array_add(&parameters, lb_debug_procedure_parameters(m, e->type));
param_index += 1; }
if (return_is_tuple) {
Type *results = type->Proc.results;
GB_ASSERT(results != nullptr && results->kind == Type_Tuple);
isize count = results->Tuple.variables.count;
parameters[0] = lb_debug_procedure_parameters(m, results->Tuple.variables[count-1]->type);
for (isize i = 0; i < count-1; i++) {
array_add(&parameters, lb_debug_procedure_parameters(m, results->Tuple.variables[i]->type));
}
}
if (type->Proc.calling_convention == ProcCC_Odin) {
array_add(&parameters, lb_debug_type(m, t_context_ptr));
} }
LLVMDIFlags flags = LLVMDIFlagZero; LLVMDIFlags flags = LLVMDIFlagZero;
@@ -107,7 +144,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type)
flags = LLVMDIFlagNoReturn; flags = LLVMDIFlagNoReturn;
} }
return LLVMDIBuilderCreateSubroutineType(m->debug_builder, file, parameters, parameter_count, flags); return LLVMDIBuilderCreateSubroutineType(m->debug_builder, file, parameters.data, cast(unsigned)parameters.count, flags);
} }
gb_internal LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *type, u64 offset_in_bits) { gb_internal LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *type, u64 offset_in_bits) {
+27 -21
View File
@@ -705,31 +705,37 @@ gb_internal lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type
lbAddr res = lb_add_local_generated(p, type, true); lbAddr res = lb_add_local_generated(p, type, true);
i64 row_count = mt->Matrix.row_count; GB_ASSERT(type_size_of(type) == type_size_of(m.type));
i64 column_count = mt->Matrix.column_count;
TEMPORARY_ALLOCATOR_GUARD();
auto srcs = array_make<lbValue>(temporary_allocator(), 0, row_count*column_count); lbValue m_ptr = lb_address_from_load_or_generate_local(p, m);
auto dsts = array_make<lbValue>(temporary_allocator(), 0, row_count*column_count); lbValue n = lb_const_int(p->module, t_int, type_size_of(type));
lb_mem_copy_non_overlapping(p, res.addr, m_ptr, n);
for (i64 j = 0; j < column_count; j++) { // i64 row_count = mt->Matrix.row_count;
for (i64 i = 0; i < row_count; i++) { // i64 column_count = mt->Matrix.column_count;
lbValue src = lb_emit_matrix_ev(p, m, i, j); // TEMPORARY_ALLOCATOR_GUARD();
array_add(&srcs, src);
}
}
for (i64 j = 0; j < column_count; j++) { // auto srcs = array_make<lbValue>(temporary_allocator(), 0, row_count*column_count);
for (i64 i = 0; i < row_count; i++) { // auto dsts = array_make<lbValue>(temporary_allocator(), 0, row_count*column_count);
lbValue dst = lb_emit_array_epi(p, res.addr, i + j*row_count);
array_add(&dsts, dst);
}
}
GB_ASSERT(srcs.count == dsts.count); // for (i64 j = 0; j < column_count; j++) {
for_array(i, srcs) { // for (i64 i = 0; i < row_count; i++) {
lb_emit_store(p, dsts[i], srcs[i]); // lbValue src = lb_emit_matrix_ev(p, m, i, j);
} // array_add(&srcs, src);
// }
// }
// for (i64 j = 0; j < column_count; j++) {
// for (i64 i = 0; i < row_count; i++) {
// lbValue dst = lb_emit_array_epi(p, res.addr, i + j*row_count);
// array_add(&dsts, dst);
// }
// }
// GB_ASSERT(srcs.count == dsts.count);
// for_array(i, srcs) {
// lb_emit_store(p, dsts[i], srcs[i]);
// }
return lb_addr_load(p, res); return lb_addr_load(p, res);
} }
+13 -5
View File
@@ -1474,6 +1474,7 @@ gb_internal i64 matrix_align_of(Type *t, struct TypePath *tp) {
Type *elem = t->Matrix.elem; Type *elem = t->Matrix.elem;
i64 row_count = gb_max(t->Matrix.row_count, 1); i64 row_count = gb_max(t->Matrix.row_count, 1);
i64 column_count = gb_max(t->Matrix.column_count, 1);
bool pop = type_path_push(tp, elem); bool pop = type_path_push(tp, elem);
if (tp->failure) { if (tp->failure) {
@@ -1491,7 +1492,7 @@ gb_internal i64 matrix_align_of(Type *t, struct TypePath *tp) {
// could be maximally aligned but as a compromise, having no padding will be // could be maximally aligned but as a compromise, having no padding will be
// beneficial to third libraries that assume no padding // beneficial to third libraries that assume no padding
i64 total_expected_size = row_count*t->Matrix.column_count*elem_size; i64 total_expected_size = row_count*column_count*elem_size;
// i64 min_alignment = prev_pow2(elem_align * row_count); // i64 min_alignment = prev_pow2(elem_align * row_count);
i64 min_alignment = prev_pow2(total_expected_size); i64 min_alignment = prev_pow2(total_expected_size);
while (total_expected_size != 0 && (total_expected_size % min_alignment) != 0) { while (total_expected_size != 0 && (total_expected_size % min_alignment) != 0) {
@@ -1523,12 +1524,15 @@ gb_internal i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) {
i64 stride_in_bytes = 0; i64 stride_in_bytes = 0;
// NOTE(bill, 2021-10-25): The alignment strategy here is to have zero padding // NOTE(bill, 2021-10-25): The alignment strategy here is to have zero padding
// It would be better for performance to pad each column so that each column // It would be better for performance to pad each column/row so that each column/row
// could be maximally aligned but as a compromise, having no padding will be // could be maximally aligned but as a compromise, having no padding will be
// beneficial to third libraries that assume no padding // beneficial to third libraries that assume no padding
i64 row_count = t->Matrix.row_count;
stride_in_bytes = elem_size*row_count;
if (t->Matrix.is_row_major) {
stride_in_bytes = elem_size*t->Matrix.column_count;
} else {
stride_in_bytes = elem_size*t->Matrix.row_count;
}
t->Matrix.stride_in_bytes = stride_in_bytes; t->Matrix.stride_in_bytes = stride_in_bytes;
return stride_in_bytes; return stride_in_bytes;
} }
@@ -4217,7 +4221,11 @@ gb_internal i64 type_size_of_internal(Type *t, TypePath *path) {
case Type_Matrix: { case Type_Matrix: {
i64 stride_in_bytes = matrix_type_stride_in_bytes(t, path); i64 stride_in_bytes = matrix_type_stride_in_bytes(t, path);
return stride_in_bytes * t->Matrix.column_count; if (t->Matrix.is_row_major) {
return stride_in_bytes * t->Matrix.row_count;
} else {
return stride_in_bytes * t->Matrix.column_count;
}
} }
case Type_BitField: case Type_BitField:
+2 -1
View File
@@ -10,7 +10,8 @@
A test suite for `core:net` A test suite for `core:net`
*/ */
//+build !netbsd !openbsd //+build !netbsd
//+build !openbsd
package test_core_net package test_core_net
import "core:testing" import "core:testing"
+1
View File
@@ -15,6 +15,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style
..\..\..\odin test ..\test_issue_2615.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_2615.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2637.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_2637.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2666.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_2666.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4210.odin %COMMON% || exit /b
@echo off @echo off
+1
View File
@@ -16,6 +16,7 @@ $ODIN test ../test_issue_2466.odin $COMMON
$ODIN test ../test_issue_2615.odin $COMMON $ODIN test ../test_issue_2615.odin $COMMON
$ODIN test ../test_issue_2637.odin $COMMON $ODIN test ../test_issue_2637.odin $COMMON
$ODIN test ../test_issue_2666.odin $COMMON $ODIN test ../test_issue_2666.odin $COMMON
$ODIN test ../test_issue_4210.odin $COMMON
if [[ $($ODIN build ../test_issue_2395.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 2 ]] ; then if [[ $($ODIN build ../test_issue_2395.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 2 ]] ; then
echo "SUCCESSFUL 1/1" echo "SUCCESSFUL 1/1"
else else
+85
View File
@@ -0,0 +1,85 @@
// Tests issue #4210 https://github.com/odin-lang/Odin/issues/4210
package test_issues
import "core:testing"
import "base:intrinsics"
@test
test_row_major_matrix :: proc(t: ^testing.T) {
row_major34: #row_major matrix[3,4]int = {
11,12,13,14,
21,22,23,24,
31,32,33,34,
}
row_major34_expected := [?]int{11,12,13,14, 21,22,23,24, 31,32,33,34}
row_major43: #row_major matrix[4,3]int = {
11,12,13,
21,22,23,
31,32,33,
41,42,43,
}
row_major43_expected := [?]int{11,12,13, 21,22,23, 31,32,33, 41,42,43}
major34_flattened := intrinsics.matrix_flatten(row_major34)
major34_from_ptr := intrinsics.unaligned_load((^[3 * 4]int)(&row_major34))
for row in 0..<3 {
for column in 0..<4 {
idx := row * 4 + column
testing.expect_value(t, major34_flattened[idx], row_major34_expected[idx])
testing.expect_value(t, major34_from_ptr [idx], row_major34_expected[idx])
}
}
major43_flattened := intrinsics.matrix_flatten(row_major43)
major43_from_ptr := intrinsics.unaligned_load((^[4 * 3]int)(&row_major43))
for row in 0..<4 {
for column in 0..<3 {
idx := row * 3 + column
testing.expect_value(t, major43_flattened[idx], row_major43_expected[idx])
testing.expect_value(t, major43_from_ptr [idx], row_major43_expected[idx])
}
}
}
@test
test_row_minor_matrix :: proc(t: ^testing.T) {
row_minor34: matrix[3,4]int = {
11,12,13,14,
21,22,23,24,
31,32,33,34,
}
row_minor34_expected := [?]int{11,21,31, 12,22,32, 13,23,33, 14,24,34}
row_minor43: matrix[4,3]int = {
11,12,13,
21,22,23,
31,32,33,
41,42,43,
}
row_minor43_expected := [?]int{11,21,31,41, 12,22,32,42, 13,23,33,43}
minor34_flattened := intrinsics.matrix_flatten(row_minor34)
minor34_from_ptr := intrinsics.unaligned_load((^[3 * 4]int)(&row_minor34))
for row in 0..<3 {
for column in 0..<4 {
idx := row * 4 + column
testing.expect_value(t, minor34_flattened[idx], row_minor34_expected[idx])
testing.expect_value(t, minor34_from_ptr [idx], row_minor34_expected[idx])
}
}
minor43_flattened := intrinsics.matrix_flatten(row_minor43)
minor43_from_ptr := intrinsics.unaligned_load((^[4 * 3]int)(&row_minor43))
for row in 0..<4 {
for column in 0..<3 {
idx := row * 3 + column
testing.expect_value(t, minor43_flattened[idx], row_minor43_expected[idx])
testing.expect_value(t, minor43_from_ptr [idx], row_minor43_expected[idx])
}
}
}
+2
View File
@@ -27,6 +27,8 @@ when ODIN_OS == .Windows {
"system:advapi32.lib", "system:advapi32.lib",
"system:user32.lib", "system:user32.lib",
"system:gdi32.lib", "system:gdi32.lib",
"system:ole32.lib",
"system:oleaut32.lib",
} }
} else when ODIN_OS == .Darwin { } else when ODIN_OS == .Darwin {
@(private) ARCH :: "x86_64" when ODIN_ARCH == .amd64 else "aarch64" when ODIN_ARCH == .arm64 else #panic("unsupported WGPU Native architecture") @(private) ARCH :: "x86_64" when ODIN_ARCH == .amd64 else "aarch64" when ODIN_ARCH == .arm64 else #panic("unsupported WGPU Native architecture")