Improve internal procedures

This commit is contained in:
gingerBill
2021-10-25 01:28:06 +01:00
parent d62c701a43
commit aaaddd03a6
2 changed files with 11 additions and 21 deletions
+2 -8
View File
@@ -128,14 +128,8 @@ compare_ptrs :: proc "contextless" (a, b: rawptr, n: int) -> int {
return compare_byte_ptrs((^byte)(a), (^byte)(b), n) return compare_byte_ptrs((^byte)(a), (^byte)(b), n)
} }
ptr_offset :: proc "contextless" (ptr: $P/^$T, n: int) -> P { ptr_offset :: intrinsics.ptr_offset
new := int(uintptr(ptr)) + size_of(T)*n ptr_sub :: intrinsics.ptr_sub
return P(uintptr(new))
}
ptr_sub :: proc "contextless" (a, b: $P/^$T) -> int {
return (int(uintptr(a)) - int(uintptr(b)))/size_of(T)
}
slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T { slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T {
return ([^]T)(ptr)[:len] return ([^]T)(ptr)[:len]
+9 -13
View File
@@ -2,15 +2,15 @@ package runtime
import "core:intrinsics" import "core:intrinsics"
bswap_16 :: proc "none" (x: u16) -> u16 { bswap_16 :: proc "contextless" (x: u16) -> u16 {
return x>>8 | x<<8 return x>>8 | x<<8
} }
bswap_32 :: proc "none" (x: u32) -> u32 { bswap_32 :: proc "contextless" (x: u32) -> u32 {
return x>>24 | (x>>8)&0xff00 | (x<<8)&0xff0000 | x<<24 return x>>24 | (x>>8)&0xff00 | (x<<8)&0xff0000 | x<<24
} }
bswap_64 :: proc "none" (x: u64) -> u64 { bswap_64 :: proc "contextless" (x: u64) -> u64 {
z := x z := x
z = (z & 0x00000000ffffffff) << 32 | (z & 0xffffffff00000000) >> 32 z = (z & 0x00000000ffffffff) << 32 | (z & 0xffffffff00000000) >> 32
z = (z & 0x0000ffff0000ffff) << 16 | (z & 0xffff0000ffff0000) >> 16 z = (z & 0x0000ffff0000ffff) << 16 | (z & 0xffff0000ffff0000) >> 16
@@ -18,7 +18,7 @@ bswap_64 :: proc "none" (x: u64) -> u64 {
return z return z
} }
bswap_128 :: proc "none" (x: u128) -> u128 { bswap_128 :: proc "contextless" (x: u128) -> u128 {
z := transmute([4]u32)x z := transmute([4]u32)x
z[0] = bswap_32(z[3]) z[0] = bswap_32(z[3])
z[1] = bswap_32(z[2]) z[1] = bswap_32(z[2])
@@ -27,33 +27,27 @@ bswap_128 :: proc "none" (x: u128) -> u128 {
return transmute(u128)z return transmute(u128)z
} }
bswap_f16 :: proc "none" (f: f16) -> f16 { bswap_f16 :: proc "contextless" (f: f16) -> f16 {
x := transmute(u16)f x := transmute(u16)f
z := bswap_16(x) z := bswap_16(x)
return transmute(f16)z return transmute(f16)z
} }
bswap_f32 :: proc "none" (f: f32) -> f32 { bswap_f32 :: proc "contextless" (f: f32) -> f32 {
x := transmute(u32)f x := transmute(u32)f
z := bswap_32(x) z := bswap_32(x)
return transmute(f32)z return transmute(f32)z
} }
bswap_f64 :: proc "none" (f: f64) -> f64 { bswap_f64 :: proc "contextless" (f: f64) -> f64 {
x := transmute(u64)f x := transmute(u64)f
z := bswap_64(x) z := bswap_64(x)
return transmute(f64)z return transmute(f64)z
} }
ptr_offset :: #force_inline proc "contextless" (ptr: $P/^$T, n: int) -> P {
new := int(uintptr(ptr)) + size_of(T)*n
return P(uintptr(new))
}
is_power_of_two_int :: #force_inline proc(x: int) -> bool { is_power_of_two_int :: #force_inline proc(x: int) -> bool {
if x <= 0 { if x <= 0 {
return false return false
@@ -828,12 +822,14 @@ floattidf_unsigned :: proc "c" (a: u128) -> f64 {
@(link_name="__fixunsdfti") @(link_name="__fixunsdfti")
fixunsdfti :: #force_no_inline proc "c" (a: f64) -> u128 { fixunsdfti :: #force_no_inline proc "c" (a: f64) -> u128 {
// TODO(bill): implement `fixunsdfti` correctly
x := u64(a) x := u64(a)
return u128(x) return u128(x)
} }
@(link_name="__fixunsdfdi") @(link_name="__fixunsdfdi")
fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 { fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 {
// TODO(bill): implement `fixunsdfdi` correctly
x := i64(a) x := i64(a)
return i128(x) return i128(x)
} }