aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-12-27 20:35:50 +0000
committergingerBill <bill@gingerbill.org>2017-12-27 20:35:50 +0000
commit90dbfe76603108f2b6fa44c6e16cc5e351be9571 (patch)
tree65579480c4b011d9220513a7db787be2c45e7416
parent125bad3154ea6549c10add4ed9304d35d56080ec (diff)
Fix issue #167 regarding abs, min, and, max for floats
-rw-r--r--core/_preload.odin44
1 files changed, 37 insertions, 7 deletions
diff --git a/core/_preload.odin b/core/_preload.odin
index 0374075d2..c73a8e630 100644
--- a/core/_preload.odin
+++ b/core/_preload.odin
@@ -792,15 +792,45 @@ foreign __llvm_core {
@(link_name="llvm.fmuladd.f32") fmuladd32 :: proc(a, b, c: f32) -> f32 ---;
@(link_name="llvm.fmuladd.f64") fmuladd64 :: proc(a, b, c: f64) -> f64 ---;
+}
+__abs_f32 :: inline proc "contextless" (x: f32) -> f32 {
+ foreign __llvm_core {
+ @(link_name="llvm.fabs.f32") _abs :: proc "c" (x: f32) -> f32 ---;
+ }
+ return _abs(x);
+}
+__abs_f64 :: inline proc "contextless" (x: f64) -> f64 {
+ foreign __llvm_core {
+ @(link_name="llvm.fabs.f64") _abs :: proc "c" (x: f64) -> f64 ---;
+ }
+ return _abs(x);
+}
- @(link_name="llvm.fabs.f32") __abs_f32 :: proc(x: f32) -> f32 ---;
- @(link_name="llvm.fabs.f64") __abs_f64 :: proc(x: f64) -> f32 ---;
-
- @(link_name="llvm.minnum.f32") __min_f32 :: proc(a, b: f32) -> f32 ---;
- @(link_name="llvm.minnum.f64") __min_f64 :: proc(a, b: f64) -> f32 ---;
- @(link_name="llvm.maxnum.f32") __max_f32 :: proc(a, b: f32) -> f32 ---;
- @(link_name="llvm.maxnum.f64") __max_f64 :: proc(a, b: f64) -> f32 ---;
+__min_f32 :: proc(a, b: f32) -> f32 {
+ foreign __llvm_core {
+ @(link_name="llvm.minnum.f32") _min :: proc "c" (a, b: f32) -> f32 ---;
+ }
+ return _min(a, b);
}
+__min_f64 :: proc(a, b: f64) -> f64 {
+ foreign __llvm_core {
+ @(link_name="llvm.minnum.f64") _min :: proc "c" (a, b: f64) -> f64 ---;
+ }
+ return _min(a, b);
+}
+__max_f32 :: proc(a, b: f32) -> f32 {
+ foreign __llvm_core {
+ @(link_name="llvm.maxnum.f32") _max :: proc "c" (a, b: f32) -> f32 ---;
+ }
+ return _max(a, b);
+}
+__max_f64 :: proc(a, b: f64) -> f64 {
+ foreign __llvm_core {
+ @(link_name="llvm.maxnum.f64") _max :: proc "c" (a, b: f64) -> f64 ---;
+ }
+ return _max(a, b);
+}
+
__abs_complex64 :: inline proc "contextless" (x: complex64) -> f32 {
r, i := real(x), imag(x);
return __sqrt_f32(r*r + i*i);