@(linkage=<string>) for procedures and variables; @(require) for procedures; package runtime linkage improvements; Subsequence improvements to lb_run_remove_unused_function_pass

This commit is contained in:
gingerBill
2021-11-04 12:40:50 +00:00
parent 3fa7dabaa8
commit 6ded538546
15 changed files with 138 additions and 56 deletions
+19 -16
View File
@@ -2,6 +2,9 @@ package runtime
import "core:intrinsics"
@(private)
RUNTIME_LINKAGE :: "strong" when ODIN_USE_SEPARATE_MODULES else "internal"
@(private)
byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte #no_bounds_check {
return ([^]byte)(data)[:max(len, 0)]
@@ -646,7 +649,7 @@ quo_quaternion256 :: proc "contextless" (q, r: quaternion256) -> quaternion256 {
return quaternion(t0, t1, t2, t3)
}
@(link_name="__truncsfhf2")
@(link_name="__truncsfhf2", linkage=RUNTIME_LINKAGE, require)
truncsfhf2 :: proc "c" (value: f32) -> u16 {
v: struct #raw_union { i: u32, f: f32 }
i, s, e, m: i32
@@ -704,12 +707,12 @@ truncsfhf2 :: proc "c" (value: f32) -> u16 {
}
@(link_name="__truncdfhf2")
@(link_name="__truncdfhf2", linkage=RUNTIME_LINKAGE, require)
truncdfhf2 :: proc "c" (value: f64) -> u16 {
return truncsfhf2(f32(value))
}
@(link_name="__gnu_h2f_ieee")
@(link_name="__gnu_h2f_ieee", linkage=RUNTIME_LINKAGE, require)
gnu_h2f_ieee :: proc "c" (value: u16) -> f32 {
fp32 :: struct #raw_union { u: u32, f: f32 }
@@ -728,19 +731,19 @@ gnu_h2f_ieee :: proc "c" (value: u16) -> f32 {
}
@(link_name="__gnu_f2h_ieee")
@(link_name="__gnu_f2h_ieee", linkage=RUNTIME_LINKAGE, require)
gnu_f2h_ieee :: proc "c" (value: f32) -> u16 {
return truncsfhf2(value)
}
@(link_name="__extendhfsf2")
@(link_name="__extendhfsf2", linkage=RUNTIME_LINKAGE, require)
extendhfsf2 :: proc "c" (value: u16) -> f32 {
return gnu_h2f_ieee(value)
}
@(link_name="__floattidf")
@(link_name="__floattidf", linkage=RUNTIME_LINKAGE, require)
floattidf :: proc "c" (a: i128) -> f64 {
DBL_MANT_DIG :: 53
if a == 0 {
@@ -783,7 +786,7 @@ floattidf :: proc "c" (a: i128) -> f64 {
}
@(link_name="__floattidf_unsigned")
@(link_name="__floattidf_unsigned", linkage=RUNTIME_LINKAGE, require)
floattidf_unsigned :: proc "c" (a: u128) -> f64 {
DBL_MANT_DIG :: 53
if a == 0 {
@@ -825,14 +828,14 @@ floattidf_unsigned :: proc "c" (a: u128) -> f64 {
@(link_name="__fixunsdfti")
@(link_name="__fixunsdfti", linkage=RUNTIME_LINKAGE, require)
fixunsdfti :: #force_no_inline proc "c" (a: f64) -> u128 {
// TODO(bill): implement `fixunsdfti` correctly
x := u64(a)
return u128(x)
}
@(link_name="__fixunsdfdi")
@(link_name="__fixunsdfdi", linkage=RUNTIME_LINKAGE, require)
fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 {
// TODO(bill): implement `fixunsdfdi` correctly
x := i64(a)
@@ -842,7 +845,7 @@ fixunsdfdi :: #force_no_inline proc "c" (a: f64) -> i128 {
@(link_name="__umodti3")
@(link_name="__umodti3", linkage=RUNTIME_LINKAGE, require)
umodti3 :: proc "c" (a, b: u128) -> u128 {
r: u128 = ---
_ = udivmod128(a, b, &r)
@@ -850,18 +853,18 @@ umodti3 :: proc "c" (a, b: u128) -> u128 {
}
@(link_name="__udivmodti4")
@(link_name="__udivmodti4", linkage=RUNTIME_LINKAGE, require)
udivmodti4 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
return udivmod128(a, b, rem)
}
@(link_name="__udivti3")
@(link_name="__udivti3", linkage=RUNTIME_LINKAGE, require)
udivti3 :: proc "c" (a, b: u128) -> u128 {
return udivmodti4(a, b, nil)
}
@(link_name="__modti3")
@(link_name="__modti3", linkage=RUNTIME_LINKAGE, require)
modti3 :: proc "c" (a, b: i128) -> i128 {
s_a := a >> (128 - 1)
s_b := b >> (128 - 1)
@@ -874,20 +877,20 @@ modti3 :: proc "c" (a, b: i128) -> i128 {
}
@(link_name="__divmodti4")
@(link_name="__divmodti4", linkage=RUNTIME_LINKAGE, require)
divmodti4 :: proc "c" (a, b: i128, rem: ^i128) -> i128 {
u := udivmod128(transmute(u128)a, transmute(u128)b, cast(^u128)rem)
return transmute(i128)u
}
@(link_name="__divti3")
@(link_name="__divti3", linkage=RUNTIME_LINKAGE, require)
divti3 :: proc "c" (a, b: i128) -> i128 {
u := udivmodti4(transmute(u128)a, transmute(u128)b, nil)
return transmute(i128)u
}
@(link_name="__fixdfti")
@(link_name="__fixdfti", linkage=RUNTIME_LINKAGE, require)
fixdfti :: proc(a: u64) -> i128 {
significandBits :: 52
typeWidth :: (size_of(u64)*8)
-1
View File
@@ -1 +0,0 @@
package runtime
-1
View File
@@ -1 +0,0 @@
package runtime
+5 -8
View File
@@ -1,7 +1,7 @@
package runtime
when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
@(link_name="memset")
@(link_name="memset", require)
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
if ptr != nil && len != 0 {
b := byte(val)
@@ -13,7 +13,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
return ptr
}
@(link_name="memmove")
@(link_name="memmove", require)
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
if dst != src {
d, s := ([^]byte)(dst), ([^]byte)(src)
@@ -26,8 +26,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
}
} else when ODIN_NO_CRT {
@(export)
@(link_name="memset")
@(link_name="memset", linkage=RUNTIME_LINKAGE, require)
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
if ptr != nil && len != 0 {
b := byte(val)
@@ -39,8 +38,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
return ptr
}
@(export)
@(link_name="memmove")
@(link_name="memmove", linkage=RUNTIME_LINKAGE, require)
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
if dst != src {
d, s := ([^]byte)(dst), ([^]byte)(src)
@@ -52,8 +50,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
return dst
}
@(export)
@(link_name="memcpy")
@(link_name="memcpy", linkage=RUNTIME_LINKAGE, require)
memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
if dst != src {
d, s := ([^]byte)(dst), ([^]byte)(src)
+2 -1
View File
@@ -1,7 +1,8 @@
//+build wasm32
package runtime
@(link_name="__ashlti3")
@(link_name="__ashlti3", linkage="strong")
__ashlti3 :: proc "c" (a: i64, b: i32) -> i64 {
// TODO(bill): __ashlti3 on wasm32
return a
}
+3 -3
View File
@@ -22,7 +22,7 @@ windows_trap_type_assertion :: proc "contextless" () -> ! {
windows_trap_array_bounds()
}
@(private, require, link_name="_fltused") _fltused: i32 = 0x9875
@(private, export, link_name="_fltused") _fltused: i32 = 0x9875
@(private, require, link_name="_tls_index") _tls_index: u32
@(private, require, link_name="_tls_array") _tls_array: u32
@(private, export, link_name="_tls_index") _tls_index: u32
@(private, export, link_name="_tls_array") _tls_array: u32