From 74e28e6938c1fecb1a5efa15db41b83216bce5f6 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Thu, 22 Jan 2015 12:11:41 +0000 Subject: [PATCH 1/3] use muladd in horner macro --- base/math.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/math.jl b/base/math.jl index 5e984d71282ae..f7f2ed40edf34 100644 --- a/base/math.jl +++ b/base/math.jl @@ -45,7 +45,7 @@ clamp{T}(x::AbstractArray{T}, lo, hi) = macro horner(x, p...) ex = esc(p[end]) for i = length(p)-1:-1:1 - ex = :($(esc(p[i])) + t * $ex) + ex = :(muladd(t, $ex, $(esc(p[i])))) end Expr(:block, :(t = $(esc(x))), ex) end From 45a27dad02019fbf544b2f91688d99adcbf5e08d Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Thu, 22 Jan 2015 14:10:46 +0000 Subject: [PATCH 2/3] muladd fallback --- base/promotion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/promotion.jl b/base/promotion.jl index 657eb39fa9aaf..0603b578db4e8 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -196,7 +196,7 @@ no_op_err(name, T) = error(name," not defined for ",T) fma{T<:Number}(x::T, y::T, z::T) = no_op_err("fma", T) fma(x::Integer, y::Integer, z::Integer) = x*y+z -muladd{T<:Number}(x::T, y::T, z::T) = no_op_err("muladd", T) +muladd{T<:Number}(x::T, y::T, z::T) = x*y+z (&){T<:Integer}(x::T, y::T) = no_op_err("&", T) (|){T<:Integer}(x::T, y::T) = no_op_err("|", T) From 1df19b8d165dc637e43c57ba7471ea2732c63cea Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Thu, 22 Jan 2015 15:47:53 +0000 Subject: [PATCH 3/3] muladd in evalpoly macro --- base/math.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/math.jl b/base/math.jl index f7f2ed40edf34..89b1b08966a0e 100644 --- a/base/math.jl +++ b/base/math.jl @@ -61,8 +61,8 @@ macro evalpoly(z, p...) for i = length(p)-2:-1:1 ai = symbol("a", i) push!(as, :($ai = $a)) - a = :($b + r*$ai) - b = :($(esc(p[i])) - s * $ai) + a = :(muladd(r, $ai, $b)) + b = :(muladd(-s, $ai, $(esc(p[i])))) end ai = :a0 push!(as, :($ai = $a)) @@ -72,7 +72,7 @@ macro evalpoly(z, p...) :(r = x + x), :(s = x*x + y*y), as..., - :($ai * tt + $b)) + :(muladd($ai, tt, $b))) R = Expr(:macrocall, symbol("@horner"), :tt, p...) :(let tt = $(esc(z)) isa(tt, Complex) ? $C : $R