diff options
| author | gingerBill <bill@gingerbill.org> | 2021-04-25 20:22:26 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-04-25 20:22:26 +0100 |
| commit | 72aa0e6e3891c034863476751b2aefda781de5b2 (patch) | |
| tree | fc49f4821dcb900a30d472803e5340587c1cd65a /core/runtime | |
| parent | cb2e6ea31db90ca80314e5ff8ce8f43371fade7c (diff) | |
Replace many `foreign` llvm calls with intrinsics
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core.odin | 17 | ||||
| -rw-r--r-- | core/runtime/core_builtin.odin | 17 | ||||
| -rw-r--r-- | core/runtime/internal.odin | 45 | ||||
| -rw-r--r-- | core/runtime/internal_linux.odin | 10 | ||||
| -rw-r--r-- | core/runtime/internal_windows.odin | 10 | ||||
| -rw-r--r-- | core/runtime/udivmod128.odin | 32 |
6 files changed, 31 insertions, 100 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 78d43b65a..0033aad9a 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -20,6 +20,8 @@ // package runtime +import "intrinsics" + // NOTE(bill): This must match the compiler's Calling_Convention :: enum u8 { Invalid = 0, @@ -430,17 +432,9 @@ typeid_base_without_enum :: typeid_core; -@(default_calling_convention = "none") -foreign { - @(link_name="llvm.debugtrap") - debug_trap :: proc() ---; - - @(link_name="llvm.trap") - trap :: proc() -> ! ---; - - @(link_name="llvm.readcyclecounter") - read_cycle_counter :: proc() -> u64 ---; -} +debug_trap :: intrinsics.debug_trap; +trap :: intrinsics.trap; +read_cycle_counter :: intrinsics.read_cycle_counter; @@ -488,7 +482,6 @@ __init_context :: proc "contextless" (c: ^Context) { c.logger.data = nil; } - default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code_Location) { print_caller_location(loc); print_string(" "); diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index 6656c16a0..237ad0670 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -1,5 +1,7 @@ package runtime +import "intrinsics" + @builtin Maybe :: union(T: typeid) #maybe {T}; @@ -539,20 +541,15 @@ excl_bit_set :: proc(s: ^$S/bit_set[$E; $U], other: S) { @builtin card :: proc(s: $S/bit_set[$E; $U]) -> int { when size_of(S) == 1 { - foreign { @(link_name="llvm.ctpop.i8") count_ones :: proc(i: u8) -> u8 --- } - return int(count_ones(transmute(u8)s)); + return int(intrinsics.count_ones(transmute(u8)s)); } else when size_of(S) == 2 { - foreign { @(link_name="llvm.ctpop.i16") count_ones :: proc(i: u16) -> u16 --- } - return int(count_ones(transmute(u16)s)); + return int(intrinsics.count_ones(transmute(u16)s)); } else when size_of(S) == 4 { - foreign { @(link_name="llvm.ctpop.i32") count_ones :: proc(i: u32) -> u32 --- } - return int(count_ones(transmute(u32)s)); + return int(intrinsics.count_ones(transmute(u32)s)); } else when size_of(S) == 8 { - foreign { @(link_name="llvm.ctpop.i64") count_ones :: proc(i: u64) -> u64 --- } - return int(count_ones(transmute(u64)s)); + return int(intrinsics.count_ones(transmute(u64)s)); } else when size_of(S) == 16 { - foreign { @(link_name="llvm.ctpop.i128") count_ones :: proc(i: u128) -> u128 --- } - return int(count_ones(transmute(u128)s)); + return int(intrinsics.count_ones(transmute(u128)s)); } else { #panic("Unhandled card bit_set size"); } diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index e2f8c7287..0e128567a 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -415,59 +415,32 @@ foreign { @(link_name="llvm.sqrt.f64") _sqrt_f64 :: proc(x: f64) -> f64 --- } abs_f16 :: #force_inline proc "contextless" (x: f16) -> f16 { - foreign { - @(link_name="llvm.fabs.f16") _abs :: proc "none" (x: f16) -> f16 --- - } - return _abs(x); + return -x if x < 0 else x; } abs_f32 :: #force_inline proc "contextless" (x: f32) -> f32 { - foreign { - @(link_name="llvm.fabs.f32") _abs :: proc "none" (x: f32) -> f32 --- - } - return _abs(x); + return -x if x < 0 else x; } abs_f64 :: #force_inline proc "contextless" (x: f64) -> f64 { - foreign { - @(link_name="llvm.fabs.f64") _abs :: proc "none" (x: f64) -> f64 --- - } - return _abs(x); + return -x if x < 0 else x; } min_f16 :: proc(a, b: f16) -> f16 { - foreign { - @(link_name="llvm.minnum.f16") _min :: proc "none" (a, b: f16) -> f16 --- - } - return _min(a, b); + return a if a < b else b; } min_f32 :: proc(a, b: f32) -> f32 { - foreign { - @(link_name="llvm.minnum.f32") _min :: proc "none" (a, b: f32) -> f32 --- - } - return _min(a, b); + return a if a < b else b; } min_f64 :: proc(a, b: f64) -> f64 { - foreign { - @(link_name="llvm.minnum.f64") _min :: proc "none" (a, b: f64) -> f64 --- - } - return _min(a, b); + return a if a < b else b; } max_f16 :: proc(a, b: f16) -> f16 { - foreign { - @(link_name="llvm.maxnum.f16") _max :: proc "none" (a, b: f16) -> f16 --- - } - return _max(a, b); + return a if a > b else b; } max_f32 :: proc(a, b: f32) -> f32 { - foreign { - @(link_name="llvm.maxnum.f32") _max :: proc "none" (a, b: f32) -> f32 --- - } - return _max(a, b); + return a if a > b else b; } max_f64 :: proc(a, b: f64) -> f64 { - foreign { - @(link_name="llvm.maxnum.f64") _max :: proc "none" (a, b: f64) -> f64 --- - } - return _max(a, b); + return a if a > b else b; } abs_complex32 :: #force_inline proc "contextless" (x: complex32) -> f16 { diff --git a/core/runtime/internal_linux.odin b/core/runtime/internal_linux.odin index aecd7f601..1e1a25bb8 100644 --- a/core/runtime/internal_linux.odin +++ b/core/runtime/internal_linux.odin @@ -1,5 +1,7 @@ package runtime +import "intrinsics" + @(link_name="__umodti3") umodti3 :: proc "c" (a, b: u128) -> u128 { r: u128 = ---; @@ -86,12 +88,6 @@ fixdfti :: proc(a: u64) -> i128 { } -@(default_calling_convention = "none") -foreign { - @(link_name="llvm.ctlz.i128") _clz_i128 :: proc(x: i128, is_zero_undef := false) -> i128 --- -} - - @(link_name="__floattidf") floattidf :: proc(a: i128) -> f64 { DBL_MANT_DIG :: 53; @@ -102,7 +98,7 @@ floattidf :: proc(a: i128) -> f64 { N :: size_of(i128) * 8; s := a >> (N-1); a = (a ~ s) - s; - sd: = N - _clz_i128(a); // number of significant digits + sd: = N - intrinsics.leading_zeros(a); // number of significant digits e := u32(sd - 1); // exponent if sd > DBL_MANT_DIG { switch sd { diff --git a/core/runtime/internal_windows.odin b/core/runtime/internal_windows.odin index 79a4bcdcb..8f50baf7f 100644 --- a/core/runtime/internal_windows.odin +++ b/core/runtime/internal_windows.odin @@ -1,5 +1,7 @@ package runtime +import "intrinsics" + @(link_name="__umodti3") umodti3 :: proc "c" (a, b: u128) -> u128 { r: u128 = ---; @@ -86,12 +88,6 @@ fixdfti :: proc(a: u64) -> i128 { } -@(default_calling_convention = "none") -foreign { - @(link_name="llvm.ctlz.i128") _clz_i128 :: proc(x: i128, is_zero_undef := false) -> i128 --- -} - - @(link_name="__floattidf") floattidf :: proc(a: i128) -> f64 { DBL_MANT_DIG :: 53; @@ -102,7 +98,7 @@ floattidf :: proc(a: i128) -> f64 { N :: size_of(i128) * 8; s := a >> (N-1); a = (a ~ s) - s; - sd: = N - _clz_i128(a); // number of significant digits + sd: = N - intrinsics.leading_zeros((a); // number of significant digits e := u32(sd - 1); // exponent if sd > DBL_MANT_DIG { switch sd { diff --git a/core/runtime/udivmod128.odin b/core/runtime/udivmod128.odin index 3486dffc2..c0ba6b9a3 100644 --- a/core/runtime/udivmod128.odin +++ b/core/runtime/udivmod128.odin @@ -1,35 +1,11 @@ package runtime -@(default_calling_convention="none") -foreign { - @(link_name="llvm.cttz.i8") _ctz_u8 :: proc(i: u8, is_zero_undef := false) -> u8 --- - @(link_name="llvm.cttz.i16") _ctz_u16 :: proc(i: u16, is_zero_undef := false) -> u16 --- - @(link_name="llvm.cttz.i32") _ctz_u32 :: proc(i: u32, is_zero_undef := false) -> u32 --- - @(link_name="llvm.cttz.i64") _ctz_u64 :: proc(i: u64, is_zero_undef := false) -> u64 --- -} -_ctz :: proc{ - _ctz_u8, - _ctz_u16, - _ctz_u32, - _ctz_u64, -}; - -@(default_calling_convention="none") -foreign { - @(link_name="llvm.ctlz.i8") _clz_u8 :: proc(i: u8, is_zero_undef := false) -> u8 --- - @(link_name="llvm.ctlz.i16") _clz_u16 :: proc(i: u16, is_zero_undef := false) -> u16 --- - @(link_name="llvm.ctlz.i32") _clz_u32 :: proc(i: u32, is_zero_undef := false) -> u32 --- - @(link_name="llvm.ctlz.i64") _clz_u64 :: proc(i: u64, is_zero_undef := false) -> u64 --- -} -_clz :: proc{ - _clz_u8, - _clz_u16, - _clz_u32, - _clz_u64, -}; - +import "intrinsics" udivmod128 :: proc "c" (a, b: u128, rem: ^u128) -> u128 { + _ctz :: intrinsics.trailing_zeros; + _clz :: intrinsics.leading_zeros; + n := transmute([2]u64)a; d := transmute([2]u64)b; q, r: [2]u64 = ---, ---; |