shithub: mc

Download patch

ref: 96641430b332facfacc55f6060d0425886f35697
parent: 36bcb6d94f7ef17c9e40cf68fd26d78ec814c596
author: Ori Bernstein <[email protected]>
date: Sun Aug 5 09:23:37 EDT 2018

We can pick fma generically at compile time.

	It's a trait, and because the functions are generic,
	they already know the type.

--- a/lib/math/sqrt-impl.myr
+++ b/lib/math/sqrt-impl.myr
@@ -62,7 +62,6 @@
 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 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 @@
 	;;
 
 	/* 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 @@
 		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