mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Replace many foreign llvm calls with intrinsics
This commit is contained in:
@@ -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(" ");
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 = ---, ---;
|
||||
|
||||
Reference in New Issue
Block a user