summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-08-05 13:23:37 -0700
committerOri Bernstein <ori@eigenstate.org>2018-08-05 13:23:37 -0700
commit96641430b332facfacc55f6060d0425886f35697 (patch)
treede9e598442a999836faea54941ca1bd4627363b3
parent36bcb6d94f7ef17c9e40cf68fd26d78ec814c596 (diff)
downloadmc-96641430b332facfacc55f6060d0425886f35697.tar.gz
We can pick fma generically at compile time.
It's a trait, and because the functions are generic, they already know the type.
-rw-r--r--lib/math/sqrt-impl.myr14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/math/sqrt-impl.myr b/lib/math/sqrt-impl.myr
index a8b243f..06eb239 100644
--- a/lib/math/sqrt-impl.myr
+++ b/lib/math/sqrt-impl.myr
@@ -62,7 +62,6 @@ const ab64 : (uint64, uint64)[8] = [
const desc32 : fltdesc(flt32, uint32, int32) = [
.explode = std.flt32explode,
.assem = std.flt32assem,
- .fma = fma32,
.tobits = std.flt32bits,
.frombits = std.flt32frombits,
.nan = 0x7fc00000,
@@ -77,7 +76,6 @@ const desc32 : fltdesc(flt32, uint32, int32) = [
const desc64 : fltdesc(flt64, uint64, int64) = [
.explode = std.flt64explode,
.assem = std.flt64assem,
- .fma = fma64,
.tobits = std.flt64bits,
.frombits = std.flt64frombits,
.nan = 0x7ff8000000000000,
@@ -148,14 +146,14 @@ generic sqrtgen = {x : @f, d : fltdesc(@f, @u, @i) :: numeric,floating,std.equat
;;
/* split up "x_{n+1} = x_n (3 - ax_n^2)/2" */
- var epsn = d.fma(-1.0 * a, xn * xn, 1.0)
+ var epsn = fma(-1.0 * a, xn * xn, 1.0)
var rn = 0.5 * epsn
var gn = a * xn
var hn = 0.5 * xn
for var j = 0; j < d.iterlim; ++j
- rn = d.fma(-1.0 * gn, hn, 0.5)
- gn = d.fma(gn, rn, gn)
- hn = d.fma(hn, rn, hn)
+ rn = fma(-1.0 * gn, hn, 0.5)
+ gn = fma(gn, rn, gn)
+ hn = fma(hn, rn, hn)
;;
/*
@@ -174,11 +172,11 @@ generic sqrtgen = {x : @f, d : fltdesc(@f, @u, @i) :: numeric,floating,std.equat
var r_plus_ulp : @f = d.frombits(d.tobits(r) + 1)
var r_minus_ulp : @f = d.frombits(d.tobits(r) - 1)
- var delta_1 = d.fma(r, r_minus_ulp, -1.0 * x)
+ var delta_1 = fma(r, r_minus_ulp, -1.0 * x)
if d.tobits(delta_1) & d.sgnmask == 0
r = r_minus_ulp
else
- var delta_2 = d.fma(r, r_plus_ulp, -1.0 * x)
+ var delta_2 = fma(r, r_plus_ulp, -1.0 * x)
if d.tobits(delta_2) & d.sgnmask != 0
r = r_plus_ulp
else