mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Update core:runtime to use the new intrinsics
This commit is contained in:
@@ -17,7 +17,7 @@ init_global_temporary_allocator :: proc(size: int, backup_allocator := context.a
|
|||||||
copy_slice :: proc "contextless" (dst, src: $T/[]$E) -> int {
|
copy_slice :: proc "contextless" (dst, src: $T/[]$E) -> int {
|
||||||
n := max(0, min(len(dst), len(src)));
|
n := max(0, min(len(dst), len(src)));
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
mem_copy(raw_data(dst), raw_data(src), n*size_of(E));
|
intrinsics.mem_copy(raw_data(dst), raw_data(src), n*size_of(E));
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ copy_slice :: proc "contextless" (dst, src: $T/[]$E) -> int {
|
|||||||
copy_from_string :: proc "contextless" (dst: $T/[]$E/u8, src: $S/string) -> int {
|
copy_from_string :: proc "contextless" (dst: $T/[]$E/u8, src: $S/string) -> int {
|
||||||
n := max(0, min(len(dst), len(src)));
|
n := max(0, min(len(dst), len(src)));
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
mem_copy(raw_data(dst), raw_data(src), n);
|
intrinsics.mem_copy(raw_data(dst), raw_data(src), n);
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -285,22 +285,18 @@ append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_len := 1;
|
if cap(array) < len(array)+1 {
|
||||||
|
cap := 2 * cap(array) + max(8, 1);
|
||||||
if cap(array) < len(array)+arg_len {
|
|
||||||
cap := 2 * cap(array) + max(8, arg_len);
|
|
||||||
_ = reserve(array, cap, loc);
|
_ = reserve(array, cap, loc);
|
||||||
}
|
}
|
||||||
arg_len = min(cap(array)-len(array), arg_len);
|
if cap(array)-len(array) > 0 {
|
||||||
if arg_len > 0 {
|
|
||||||
a := (^Raw_Dynamic_Array)(array);
|
a := (^Raw_Dynamic_Array)(array);
|
||||||
if size_of(E) != 0 {
|
when size_of(E) != 0 {
|
||||||
data := (^E)(a.data);
|
data := (^E)(a.data);
|
||||||
assert(data != nil);
|
assert(condition=data != nil, loc=loc);
|
||||||
val := arg;
|
intrinsics.ptr_offset(data, a.len)^ = arg;
|
||||||
mem_copy(ptr_offset(data, a.len), &val, size_of(E));
|
|
||||||
}
|
}
|
||||||
a.len += arg_len;
|
a.len += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,10 +319,10 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
|
|||||||
arg_len = min(cap(array)-len(array), arg_len);
|
arg_len = min(cap(array)-len(array), arg_len);
|
||||||
if arg_len > 0 {
|
if arg_len > 0 {
|
||||||
a := (^Raw_Dynamic_Array)(array);
|
a := (^Raw_Dynamic_Array)(array);
|
||||||
if size_of(E) != 0 {
|
when size_of(E) != 0 {
|
||||||
data := (^E)(a.data);
|
data := (^E)(a.data);
|
||||||
assert(data != nil);
|
assert(condition=data != nil, loc=loc);
|
||||||
mem_copy(ptr_offset(data, a.len), &args[0], size_of(E) * arg_len);
|
intrinsics.mem_copy(intrinsics.ptr_offset(data, a.len), &args[0], size_of(E) * arg_len);
|
||||||
}
|
}
|
||||||
a.len += arg_len;
|
a.len += arg_len;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
//+build windows
|
//+build windows
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
import "intrinsics"
|
||||||
|
|
||||||
foreign import kernel32 "system:Kernel32.lib"
|
foreign import kernel32 "system:Kernel32.lib"
|
||||||
|
|
||||||
@(private="file")
|
@(private="file")
|
||||||
@@ -108,12 +110,12 @@ _windows_default_alloc_or_resize :: proc "contextless" (size, alignment: int, ol
|
|||||||
|
|
||||||
allocated_mem: rawptr;
|
allocated_mem: rawptr;
|
||||||
if old_ptr != nil {
|
if old_ptr != nil {
|
||||||
original_old_ptr := ptr_offset((^rawptr)(old_ptr), -1)^;
|
original_old_ptr := intrinsics.ptr_offset((^rawptr)(old_ptr), -1)^;
|
||||||
allocated_mem = heap_resize(original_old_ptr, space+size_of(rawptr));
|
allocated_mem = heap_resize(original_old_ptr, space+size_of(rawptr));
|
||||||
} else {
|
} else {
|
||||||
allocated_mem = heap_alloc(space+size_of(rawptr));
|
allocated_mem = heap_alloc(space+size_of(rawptr));
|
||||||
}
|
}
|
||||||
aligned_mem := rawptr(ptr_offset((^u8)(allocated_mem), size_of(rawptr)));
|
aligned_mem := rawptr(intrinsics.ptr_offset((^u8)(allocated_mem), size_of(rawptr)));
|
||||||
|
|
||||||
ptr := uintptr(aligned_mem);
|
ptr := uintptr(aligned_mem);
|
||||||
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a);
|
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a);
|
||||||
@@ -123,7 +125,7 @@ _windows_default_alloc_or_resize :: proc "contextless" (size, alignment: int, ol
|
|||||||
}
|
}
|
||||||
|
|
||||||
aligned_mem = rawptr(aligned_ptr);
|
aligned_mem = rawptr(aligned_ptr);
|
||||||
ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem;
|
intrinsics.ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem;
|
||||||
|
|
||||||
return byte_slice(aligned_mem, size), nil;
|
return byte_slice(aligned_mem, size), nil;
|
||||||
}
|
}
|
||||||
@@ -135,7 +137,7 @@ _windows_default_alloc :: proc "contextless" (size, alignment: int) -> ([]byte,
|
|||||||
|
|
||||||
_windows_default_free :: proc "contextless" (ptr: rawptr) {
|
_windows_default_free :: proc "contextless" (ptr: rawptr) {
|
||||||
if ptr != nil {
|
if ptr != nil {
|
||||||
heap_free(ptr_offset((^rawptr)(ptr), -1)^);
|
heap_free(intrinsics.ptr_offset((^rawptr)(ptr), -1)^);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user